eventer

Experimental events interface

npm install eventer
4 downloads in the last week
8 downloads in the last month

eventer

Experimental event creator helper.

NPM

Usage

The easiest way to use eventer is to patch events into either an object or prototype:

var eventer = require('..');

// define a messenger helper "class"
function Messenger() {}
Messenger.prototype.send = eventer(Messenger.prototype, 'message');

function handleSend(message) {
  console.log('sent message: ' + message);
}

// create a new messenger instance
var ted = new Messenger();

ted.onmessage = [ handleSend ];
// does not work :(
// ted.onmessage = fo()(ted.onmessage + handleSend);

// add another handler
ted.onmessage = ted.onmessage.concat(function(message) {
  console.log('yes, i really did send: ' + message);
});

ted.send('hello');
// --> sent message: hello
// --> yes, i really did send: hello

// remove the first handler
ted.onmessage = ted.onmessage.filter(function(handler) {
  return handler !== handleSend;
});

ted.send('hi');
// --> yes, i really did send: hi
npm loves you