A minimal and performant event emitter library for Node.JS.
npm install chiisai-event-emitter
Use EventEmitter.subscribe(eventName, callback)
to subscribe to an event.
import { EventEmitter } from 'chiisai-event-emitter';
const eventEmitter = new EventEmitter();
eventEmitter.subscribe('event', () => console.log('event-handler called!'));
eventEmitter.emit('event')
// event-handler called!
EventEmitter.subscribe(eventName, callback)
method returns a function which can be called to unsubscribe the callback from the event.
const unsubscibe = eventEmitter.subscribe('event', () => console.log('event-handler called!'));
unsubscribe();
eventEmitter.emit('event')
// (nothing happened)
EventEmitter.clear(eventName)
method removes an event and all callbacks subscibed to this event.
eventEmitter.subscribe('event', () => console.log('event-handler called!'));
eventEmitter.subscribe('event', () => console.log('another event-handler called!'));
eventEmitter.clear('event')
eventEmitter.emit('event')
// (nothing happened)