curran / d3-component

A lightweight component abstraction for D3.js.
BSD 3-Clause "New" or "Revised" License
109 stars 10 forks source link

Use enter, update, exit names #42

Closed curran closed 7 years ago

curran commented 7 years ago

As a follow-on to #40, inspired by @mbostock, perhaps it would be sensible to rename the methods:

The reason why the names were create, render, destroy in the first place is that they do different things from the original enter, update, exit, and I didn't want to introduce confusion around overloading these names. However, they are indeed invoked within those very phases of the general update pattern, and it's clear enough that they are invoked on instance of d3.component, not selections. Maybe it would make sense to use these names after all.

This is how the API would look after the name change:

var myComponent = d3.component("div")
  .enter(function (d, i){
    d3.select(this).style("font-size", "30px");
  })
  .update(function (d, i){
    d3.select(this).text(d.text);
  })
  .exit(function (d, i){
    return d3.select(this).transition().style("font-size", "0px");
  });

Any thoughts?