emitters
Fancy node-compatible event emitters, including bubbling and singleton ready events.
var emitters = require('emitters');
var ee = new emitters.EventEmitter();
var count = 0
, counter = function (evt){
console.log("Count: "+(count++)+" because "+this+" fired "+evt);
};
var re = new emitters.ReadyEmitter();
re.on('ready', counter);
re.ready(true);
re.on('ready', counter);
re.ready(counter);
var c1 = new emitters.ChainedEmitter(ee)
, c2 = new emitters.ChainedEmitter(c1)
, c3 = new emitters.ChainedEmitter()
;
c3.parentEmitter(c1);
ee.on('bonk', counter);
c1.on('bonk', counter);
c2.on('bonk', counter);
c3.on('bonk', counter);
c2.emit('bonk');
c1.on('bonk', function (){
console.log('STOP!');
return false;
});
c3.emit('bonk');
Usage
For usage in node.js, install it via npm: npm install emitters
.
A browser distribution is coming soon!
API
Coming soon — use the source, Luke!
Feedback
Find a bug or want to contribute? Open a ticket (or fork the source!) on github.
You're also welcome to send me email at dsc@less.ly.
License
emitters
was written by David Schoonover (in Coco, a dialect of CoffeeScript that compiles down to JavaScript). It is open-source software and freely available under the MIT License.