@jslibrary/event-dispatcher
v1.0.2
Published
Class to add, remove event listeners and dispatch custom events.
Downloads
2
Maintainers
Readme
event-dispatcher
EventDispatcher is a class that enables addEventListener, removeEventListener and dispatchEvent methods in your class by extendeding it.
Example
import { EventDispatcher } from '@jslibrary/event-dispatcher'
export class Controller extends EventDispatcher {
async remoteMethod() {
this.dispatchEvent(new CustomEvent("beforeRemoteCall")
await const response = remoteCall()
this.dispatchEvent(new CustomEvent("afterRemoteCall", response))
}
}
import { Controller } from './Controller';
let controller = new Controller()
controller.addEventListener('afterRemoteCall', (response) => {
alert(response);
})
controller.remoteMethod()
Instalation
npm install @jslibrary/event-dispatcher