About
Store DOM event listeners and clear them with a single command.
Useful for native JavaScript web component development whereby multiple event listeners may be added by the component that need removing when the component is disposed of to avoid memory leaks e.g. in single page applications.
Event listeners are also automatically bound to the context passed to the constructor, so no need for handler.bind(this)
.
Install
$ npm install --save dom-event-store
Methods
/** * Adds an event listener to the target DOM element */; /** * Removes an aliased event listener */; /** * Removes all event listeners */;
Example usage with a simple web component
; { thistarget = target; thisstate = state; thiseventStore = this; this; } { // this example just adds a single event listener, in practice you may have many let button = document; buttontextContent = 'click me'; thiseventStore; thistarget; } { // remove all registered event listeners thiseventStoreclear; } ;
License
MIT © Tony Leeper