Simple event dispatcher.
$ npm install --save @vaalentin/event-dispatcher
import EventDispatcher from '@vaalentin/event-dispatcher';
class App extends EventDispatcher {
start() {
this.dispatchEvent('start', performance.now());
}
}
const app = new App();
app.addEventListener('start', time => {
console.log(`app started at: ${time}`);
});
app.start();
Can be used directly, or extended.
Add listener cb
to type
. dispatcher.on(type, cb)
is an alias.
Remove listener cb
from 'type'. dispatcher.off(type, cb)
is an alias.
Call all listeners of type
and pass data
. dispatcher.trigger(type, ...data)
is an alias.
Delete instance.
MIT, see LICENSE.md for more details.