A high performance event bus, designed as a centralized data flow switchboard in Scrollback. It's in production use both on client and server.
On the client, it serves a similar role as the Flux Dispatcher.
It can be used that way, but it does a few more things.
- Subscribers can be triggered in a predetermined sequence or in parallel
- Subscribers can modify the payload before passing it to downstream subscribers
- Subscribers can throw errors to stop propagation to other subscribers
Unlike Flux's Dispatcher, ebus allows multiple events with different subscriber lists, and supports asynchronous subscribers.
var bus = require("ebus")();
bus.on("event", callback, priority);
bus.emit("event", data, callback);
bus.off("event", callback);
// debugging
bus.setDebug(bool); //
bus.dump("event"); // logs the listeners in sequence
bus.on("event", callback).after("target1", "traget2").before("target3");
bus.on("event1 target1> target2> <target3, event2 target3>", callback);