1.1.4 • Published 6 years ago

pedant-emitter v1.1.4

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

pedant-emitter

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

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago