emitters
Fancy node-compatible event emitters, including bubbling and singleton ready events.
var emitters = ; // Polyfill for a node-compatible EventEmitter.var ee = ; var count = 0 { console; }; // An emitter that auto-invokes listeners if the "ready" event has already occurred.var re = ;re; // Fires the ready event unless already ready.re; // -> count == 1 // Invokes our callback because we're already ready.re; // -> count == 2 // Or...re; // -> count == 3 // A ChainedEmitter bubbles events to its parent.var c1 = ee c2 = c1 c3 = ; // You can also get/set the parent emitter later.c3; // So we're bubbling from c2 -> c1, c3 -> c1, and c1 -> ee; let's listen in.ee;c1;c2;c3; c2; // -> We see c2, c1, and ee all recieve events, putting our counter to 6. // Event handlers can stop propagaion by returning false.c1; c3; // -> c3 and c1 both have listeners who will get the event...// But the second listener we just registered will end the bubbling. (Even if the // listener were first, the rest of c1's listeners would be notified. Stopping // propagation prevents the event from moving *up*.)
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.