@superherocheesecake/event-dispatcher
v1.1.4
Published
Global EventDispatcher
Downloads
7
Maintainers
Keywords
Readme
EventDispatcher
Global EventDispatcher
NPM installation
npm i --save @superherocheesecake/event-dispatcher
Common practice
Most likely you will extend your own class.
import EventDispatcher from '@superherocheesecake/event-dispatcher';
class Module extends EventDispatcher {
// ...
}
Methods
dispatchEvent(type, payload)
Payload can be any type of value.
this.dispatchEvent('eventName', {key: value});
addEventListener(type, listener)
this.addEventListener('eventName', listener);
addEventListenerOnce(type, listener)
this.addEventListenerOnce('eventName', listener);
removeEventListener(type, listener)
this.removeEventListener('eventName', listener);
hasEventListener(type, listener)
this.hasEventListener('eventName', listener);