mbostock/d3 — pull request #1393 by MrCox (2013-07-13 04:59:09+00:00)
Title: Suggested modification to selection.data

The change adds the function 'update' to the object returned by d3_selectionPrototype.data. It expects to be passed a valid html tag. I suggest it as a convenient way to bind new data to a selection, append something to the entering selection, and then chain off of the update selection. For example, the proposed modification would make this:

var data = [1, 2, 3, 4, 5];

var ps = d3.select('#div').selectAll('p').data(data);
ps.enter().append('p');
ps.exit().remove();
// chain stuff:
ps.text(function(d) { return d});

Look like this:
d3.select('#div').selectAll('p').data(data).update('p').text(function(d) { return d});

I realize that this is only useful if you don't plan on doing anything special to the entering selection (or the exiting selection), but for simple tasks, this turns out to be a common use case.
My coworkers and I work with d3 a lot, and I've discovered that 'thinking with joins' is a conceptual hurdle to people new to the library -- even those with extensive experience with javascript. I think adding a method like this would make data-driven updating simpler for beginners.
Perhaps there is a smarter way to do this-- for example, would it be more appropriate to throw an error if no arguments are passed?
Anyway, just a suggestion.