dimanche 12 mai 2019

Remove event listeners when element gets deleted

I have a project where im using a plugin that produces something like the picture below:

enter image description here

In a div element, it spins so it has event listeners which are declared in the plugin like this...

window.addEventListener('resize', resizeHandler);

The plugin is abit long so i will link the full file here: https://pastebin.com/6e7HLDV3

I then call the library like this:

new skillsCloud(this.$()[0], this.get('entries'));

Where entries is just an array of objects for each text item.

What i want to be able to do is delete this element and it will leave no trails and properly dispose of all the event listeners.

How would I even get a chance to run the code that will remove the listeners if its about to be destroyed?

Is it worth making a function called dispose where I do it and then call before i delete the element?

Any help is appriciated




Aucun commentaire:

Enregistrer un commentaire