Skip to content

Strict event emitter. Forces event names to be accessed by key, not value.

Notifications You must be signed in to change notification settings

caiogondim/pedant-emitter.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pedant-emitter

 Travis CI Coverage Status

Strict event emitter. Forces event names to be accessed by key, not value.

Installation

npm install pedant-emitter -S

Usage

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, () => {}) // 👍

API

pedant-emitter extends from EventEmitter (Node.js native event emitter) so the same API is available, plus the methods below:

events

Object with all events registered.

addEvent(eventName)

Registers new event.

removeEvent(eventName)

Removes previously registered event.

Credits

  • Icon by Gregor Cresnar from the Noun Project

caiogondim.com  ·  GitHub @caiogondim  ·  Twitter @caio_gondim

About

Strict event emitter. Forces event names to be accessed by key, not value.

Resources

Stars

Watchers

Forks

Packages

No packages published