Strict event emitter. Forces event names to be accessed by key, not value.
npm install pedant-emitter -S
import Emitter from 'pedant-emitter'
const emitter = new Emitter({ events: ['a', 'b'] })
emitter.on('c', () => {}) // => throws TypeError since the event `c` was never registered
emitter.addEvent('c')
emitter.on('c', () => {}) // still throws a TypeError. Event names should be accessed by key, not value
emitter.on(emitter.events.c, () => {}) // 👍
pedant-emitter
extends from EventEmitter
(Node.js native event emitter) so the same API is available, plus the methods below:
Object with all events registered.
Registers new event.
Removes previously registered event.
- Icon by Gregor Cresnar from the Noun Project
caiogondim.com · GitHub @caiogondim · Twitter @caio_gondim