dispatch
d3-dispatch
Dispatching is a convenient mechanism for separating concerns with loosely-coupled code: register named callbacks and then call them with arbitrary arguments. A variety of D3 components, such as d3-request, use this mechanism to emit events to listeners. Think of this like Node’s EventEmitter, except every listener has a well-defined name so it’s easy to remove or replace them.
For example, to create a dispatch for start and end events:
var dispatch = d3.dispatch("start", "end");
You can then register callbacks for these events using dispatch.on:
dispatch.on("start", callback1); dispatch.on("start.foo", callback2); dispatch.on("end", callback3);
Then, you can invoke