simonwep / pickr

🎨 Flat, simple, multi-themed, responsive and hackable Color-Picker library. No dependencies, no jQuery. Compatible with all CSS Frameworks e.g. Bootstrap, Materialize. Supports alpha channel, rgba, hsla, hsva and more!
https://simonwep.github.io/pickr
MIT License
4.31k stars 285 forks source link

.off is not unbinding event listener #280

Closed macbubi closed 3 years ago

macbubi commented 3 years ago

What is the current behavior?

We use this amazing color picker with custom events for 'clear', 'cancel', and 'change'. The problem is that the events are not unsubscribed using the off method (the callback doesnt being called at all)

Please provide the steps to reproduce and create a JSFiddle.

https://jsfiddle.net/2m7tzybc/7/

What is the expected behavior?

.off(event, cb) will remove the event listener and call the cb function

Your environment:

Version (see Pickr.version): 1.8.0
Used bundle (es5 or normal one): es5
Used theme (default is classic):  nano
Browser-version:  chrome 90
Operating-system:  macOS
macbubi commented 3 years ago

was able to workaround using pickr.destroy() but the off method still not working

simonwep commented 3 years ago

This is not how functions / callbacks work... You pass in a function and try to unbind an different function in your fiddle. You'll need to declare a function which you can bind and unbind.

Example:

pickr.on('change', console.log);
pickr.off('change', console.log);

or

const listener = () => console.logt('change!');
pickr.on('change', listener);
pickr.off('change', listener);