Events with recipient address.
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
tests
.gitignore
README.md
index.js
package.json

README.md

switch-emitter

Events with recipient address.

Install

$ npm install switch-emitter

Listen and emit to addressed events

var switchEmitter = require('switch-emitter');
var emitter = switchEmitter();

var recipientA = emitter.to('recipient-a');
var recipientB = emitter.to('recipient-b');

// recipientA and recipientB are event emitters

recipientA.on('event', function(a, b) {  
  console.log('recipient A got event', arguments);
  assert.equal(a, 'a');
  assert.equal(b, 'b');
});

// Send event to recipient-a
emitter.send('recipient-a', 'event', 'a', 'b')

Arrays for recipients

The recipient list, the first argument of emit, can also be an array:

emitter.send(['recipient-a', 'recipient-b'], 'event', 'a', 'b')

or an array inside an array:

emitter.send(['recipient-a', ['recipient-b', 'recipient-c']], 'event', 'a', 'b')

Close recipient so it doesn't emit more events

var recipientA = emitter.to('recipient-a');

// ...

recipientA.end();

Licence

MIT