excid3 / tailwindcss-stimulus-components

A set of StimulusJS components for TailwindCSS apps similar to Bootstrap JS components.
https://excid3.github.io/tailwindcss-stimulus-components/
MIT License
1.36k stars 137 forks source link

fix: applies change to event listener registration and cleanup #242

Closed ka1ea6 closed 3 months ago

ka1ea6 commented 3 months ago

This PR changes the way event listeners are registered on connect() for a better removal as per the recommendation in this manual.

When you call .bind() on a function, it creates a new function. Therefore, calling bind twice means the add and remove eventListeners are calling different references of the function and the event wont be removed. Make sure that when adding and removing event listeners you use the same bound function reference.

excid3 commented 3 months ago

Great improvement 👍

ka1ea6 commented 3 months ago

Thanks. You got a really interesting project going glad I could be of help.