Fancy node-compatible event emitters, including bubbling and singleton ready events.
var emitters = require'emitters';// Polyfill for a node-compatible EventEmitter.var ee = ;var count = 0console.log"Count: "+count+++" because "+this+" fired "+evt;;// An emitter that auto-invokes listeners if the "ready" event has already occurred.var re = ;reon'ready' counter;// Fires the ready event unless already ready.rereadytrue; // -> count == 1// Invokes our callback because we're already ready.reon'ready' counter; // -> count == 2// Or...rereadycounter; // -> count == 3// A ChainedEmitter bubbles events to its parent.var c1 = eec2 = c1c3 =;// You can also get/set the parent emitter later.c3parentEmitterc1;// So we're bubbling from c2 -> c1, c3 -> c1, and c1 -> ee; let's listen in.eeon'bonk' counter;c1on'bonk' counter;c2on'bonk' counter;c3on'bonk' counter;c2emit'bonk'; // -> We see c2, c1, and ee all recieve events, putting our counter to 6.// Event handlers can stop propagaion by returning false.c1on'bonk'console.log'STOP!';return false;;c3emit'bonk'; // -> 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*.)
A browser distribution is coming soon!
Coming soon — use the source, Luke!