-
Notifications
You must be signed in to change notification settings - Fork 10
Closed
Description
Summary of API changes between v2 and v3:
- No longer using
thisin create(), render(), destroy() - Passing a selection as the first argument to create(), render(), destroy()
- No longer passing
nodesinto create(), render(), destroy() - No longer passing
iinto create(), render(), destroy()
Before: .render(function (d, i, nodes){ var selection = d3.select(this);
After: .render(function (selection, d){
One driving force is ES6 considerations. Using d3-component is awkward with ES6, because the API relies heavily on use of non-lexically-bound this. For the next major version of d3-component, I'd like to make the API more ES6-friendly.
The decision for the original API was intentional, to mirror the API of D3's selection.each. However, it's unfortunate because we can't use ES6 arrow functions.
ES5:
var paragraph = d3.component("p")
.render(function (d){
d3.select(this).text(d);
}),ES6 (ideal):
const paragraph = d3.component("p")
.render((d) => d3.select(this).text(d)); // Breaks due to lexically bound "this"Maybe we could pass in a selection:
ES6 (idea):
const paragraph = d3.component("p")
.render((selection, d) => selection.text(d)); // Would work fine./cc @micahstubbs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels