cssinjs
cssinjs copied to clipboard
Event listener never removed
You are adding a bound function but then removing the original function, it won't work.
function hello() { console.log('Hello'); }
el.addEventListener('mousein', hello.bind(this));
el.removeEventListener('mousein', hello); // Nothing will be removed
https://github.com/Sitebase/cssinjs/blob/feature-interaction-mixin/interaction-aware-mixin.js
Thanks for the heads up @LinusU How can this be solved? Do I needs to store the bound version of the function or something?
Yes, the same value that's being passed to addEventListener
must be passed to removeEventListener
.
If there is a function that will be called when the instance is created (haven't used mixins so I don't know) I would store the bound functions on the new instance. Then just use this.onOver
and this.onOut
directly.
constructor: function () {
this.onOver = this.onOver.bind(this);
this.onOut = this.onOut.bind(this);
}