Emmett
A custom event emitter for Node.js and the browser.
Its aim is to provide its user with a lot of event emitting sugar while remaining lightweight and fast.
Installation
You can install Emmett through npm:
npm install --save emmett
Usage
Creating an emitter
var Emitter = ; var emitter = ;
Extending the emitter
Node.js
var util = Emitter = ; { Emitter;} util;
ES6 class
; /* ... */
Listening to events
// Basicemitter; // Onceemitter; // Using ES6 symbol as event nameconst sym = Symbol;emitter; // Matching event names with a regexemitter; // Optionsemitter; // Polymorphismsemitter; emitter; // Listening to every eventsemitter;
Event data
Events are objects having the following keys:
- data: the data attached to the event.
- type: the event type.
- target: the event emitter.
emitter; emitter; // Will print "Hello World!" in the console
Removing listeners
// Basicemitter; // Removing every listeners attached to the given eventemitter; // Removing the callback from any eventemitter; // Polymorphismsemitter; emitter; // Removing every listenersemitter;
Emitting
// Basicemitter; // With dataemitter; // Polymorphismsemitter;emitter; emitter;
Retrieving listeners
// Return every matching handlers for a given event nameemitter;
Disabling an emitter
While disabled, emitting events won't produce nothing.
emitter;emitter;
Killing an emitter
Killing an emitter will remove all its listeners and make it inoperant in the future.
emitter;
Contribution
Do not hesitate to contribute to the library. Be sure to add and pass any relevant unit test before submitting any code.
# Installing the dev version git clone http://github.com/jacomyal/emmettcd emmett # Installing dependencies npm install # Running unit tests npm test # Lint the code npm run lint