A wrapper for facebook/emitter that requires event types to be registered before use.
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
dist
test
.eslintrc
.gitignore
LICENSE
README.md
index.js
package.json

README.md

checked-emitter

An EventEmitter implementation that wraps fbemitter with checks to ensure that event types are always registered before use.

Usage

var CheckedEmitter = require('checked-emitter');
var e = new CheckedEmitter();

e.registerEvent('propchange', 'propName', 'oldValue', 'newValue');
e.addListener('propchange', function(name, oldValue, newValue) {
  ...
});
e.emit('propchange', 'count', 3, 4);

API

The API is the same as fbemitter.EventEmitter, with the following additions:

registerEvent(eventType, ...params)

Register a new event to be emitted. eventType is a String, params are parameter names for the event.

registerEvents(obj)

Shorthand for registering multiple events. obj is a mapping {String : Array} of event types to parameter names.

events()

Return an Array of objects representing the events that have been registered on this emitter.