Re:A proposal to add signals to JavaScript
by pcthrowaway on Monday April 01, 2024 @01:07AM
(#39891090)
Removing event listeners upon some component being removed actually sounds like a great use case for the new FinalizationRegistry API[1]
[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Example with web components in all frameworks https://webcomponents.dev/blog/all-the-ways-to-make-a-web-co... and an other version to experiment with https://jsbin.com/yiviragiba/8/edit?html,css,js,console,outp...
For other event listeners, they get removed when the DOM element is removed.
The frameworks do not solve this to any greater degree. They also just make everything invisible and behind-the-scenes and hard to debug due to their declarative nature, but that is another topic.