notiflix / Notiflix

Notiflix is a pure JavaScript library for client-side non-blocking notifications, popup boxes, loading indicators, and more that makes your web projects much better.
https://notiflix.github.io
MIT License
647 stars 55 forks source link

Callbacks fail when calling typescript functions #30

Closed DDriggs00 closed 4 years ago

DDriggs00 commented 4 years ago

Describe the bug When adding a typescript variable to a callback function, the button which calls the does nothing when clicked.

To Reproduce Steps to reproduce the behavior:

  1. Install in Angular via method 1 under installation (npm install, import)
  2. Import Notiflix import { Confirm } from 'notiflix';
  3. Create a Confirm as follows and call from a class function:
     Confirm.Show(
         'Notiflix Confirm',
         'Do you agree with me?', 
        'Yes',
         'No', 
        function(){
            // Yes button callback
            this.classvariable = true;
            alert('alert is a typescript function');
        },
        function(){
            // No button callback
            alert('alert is a non-typescript function'); 
        }
    ); 
  4. The "No" Button should work, and the "Yes" Button should not do anything

Expected behavior The yes button sets this.classvariable to true then raises the alert.

Desktop

Not tested on Mobile

furcan commented 4 years ago

Hi @DDriggs00

Firstly thanks for using Notiflix.

I did not get your expectation at all but maybe you can try the code below and feedback.

Thanks.

Furkan.

 // ....
 var aMysteriousThis = this;

 Confirm.Show(
     'Notiflix Confirm',
     'Do you agree with me?', 
    'Yes',
     'No', 
    function(){
        // Yes button callback
        aMysteriousThis.classvariable = true;
        alert('alert is a typescript function');
    },
    function(){
        // No button callback
        alert('alert is a non-typescript function'); 
    }
); 
DDriggs00 commented 4 years ago

Thank you, This is a good workaround. I can confirm that it works with typescript 3.8/Angular 9

It would still be nice to not have to do a workaround like this, but I understand this is a pure JS library.