EventEmitter in JavaScript
Synopsis
EventEmitter is an implementation of the Event-based architecture in JavaScript.
The code is written using the ES2015 approaches, including creation of private property through WeakMap that allows you to not to check for clearing memory, and let it do to the garbage collector.
The module contains the most basic and necessary things: subscription to an event, unsubscribing from the events, running event only once, setting the maximum number of listeners.
The focus is on code readability, speed of execution, getting rid of all the excess.
You can use this library in browser either at the server as within the node.js.
Dependencies
There are no dependencies. You need only npm installed and just run npm install
to grab the development dependencies.
Examples
let EM = ; EM; EM;
let EM = ; EM; EM;
let EM = ; EM; EM;
let EM = ; EM; // Note: you can use chaining. EM ;
// You can set maxNumberOfListeners as a parameter when creating new object. let EM = 1; EM; // Note: it will show notification in console. EM;
Testing
Tests are performed using mocha and expect library.
Building the documentation
You can use JSDoc comments found within the source code.
Minifying
You can grab minified versions of EventEmitter from /dist path after running gulp build
.
Todo
- Add event's namespace:
EM;
- Add events through comma:
EM;
- Add method "onAny" for listening each event:
EM;