ensemble
v1.2.1
Published
Event listener orchestration
Downloads
5
Maintainers
Readme
ensemble
Event listener orchestration. Makes it easy to bulk unbind listeners that were
set withing a context. This is especially useful for unmounting listeners in
React's componentWillUnmount
lifecycle event.
Installation
$ npm i --save ensemble
Overview
var Emitter = require('events').EventEmitter;
var ensemble = require('ensemble');
/**
* Wrap an event emitter.
*/
var emitter = ensemble(new Emitter);
/**
* Attach listeners to the emitter.
*/
emitter.on('foo', function() {});
/**
* Remove all listeners registered
* in the wrapper from the emitter.
*/
emitter.removeListeners()
API
var emitter = ensemble(Emitter)
Wrap an event emitter in an ensemble object.
var Emitter = require('events').EventEmitter;
var ensemble = require('ensemble');
var myEmitter = ensemble(new Emitter);
.on(event, cb)
Attach an event listener to the wrapped emitter. Behaves identical to Node's built in listener function.
myEmitter.on('some_event', function(val) {
console.log(val);
});
.removeListeners()
Remove all listeners that were attached within this context to the emitter.
myEmitter.removeListeners();