ensemble

1.2.1 • Public • Published

ensemble

NPM version build status Test coverage Dependency Status Downloads

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();

License

MIT © Yoshua Wuyts

Package Sidebar

Install

npm i ensemble

Weekly Downloads

1

Version

1.2.1

License

MIT

Last publish

Collaborators

  • yoshuawuyts