mbostock/d3 — pull request #477 by jasondavies (2012-01-29 18:14:21+00:00)
Title: Allow event firing to be chained.

This is really a very minor nice-to-have, and I no longer even need it, so feel free to ignore.

I was looking at using a dispatch object to encapsulate the state of some background computation, something like:

```javascript
function backgroundComputation() {
return d3.dispatch("start", "stop")
.on("start", /* Start some complex computation here… */)
.on("stop", …);
}

// Without this change, worker would be undefined.
var worker = thing().on(…).start();

// Later, e.g. if a button is pressed…
worker.stop();
```

It turns out I needed to support other, non-event operations, so I ended up using d3.rebind instead, so got chaining for free anyway.

If you think it's worth it, I can add some tests too.

I suppose one argument against this is you might want to return something like the number of listeners that were notified instead.