Commit c967623a authored by Mike Bostock's avatar Mike Bostock
Browse files

Update CHANGES.

parent d4ad20ba
......@@ -670,9 +670,9 @@ Mention d3-scale-chromatic?
## [Selections (d3-selection)](https://github.com/d3/d3-selection/blob/master/README.md)
Selections no longer subclass Array using [prototype chain injection](http://perfectionkills.com/how-ecmascript-5-still-does-not-allow-to-subclass-an-array/#wrappers_prototype_chain_injection); they are now plain objects. This avoids a [scary performance warning](https://github.com/d3/d3/issues/1805) on Firefox.
Selections no longer subclass Array using [prototype chain injection](http://perfectionkills.com/how-ecmascript-5-still-does-not-allow-to-subclass-an-array/#wrappers_prototype_chain_injection); they are now plain objects. This avoids a [scary warning](https://github.com/d3/d3/issues/1805) on Firefox and improves performance.
Selections are now immutable: the set of elements in a given selection will never change. (The elements’ attributes and content will of course be modified!) The [*selection*.sort](https://github.com/d3/d3-selection#selection_sort) and [*selection*.data](https://github.com/d3/d3-selection#selection_data) methods now return new selections rather than modifying the selection in-place. In addition, [*selection*.append](https://github.com/d3/d3-selection#selection_append) no longer merges entering nodes into the update selection. Use [*selection*.merge](https://github.com/d3/d3-selection#selection_merge) to combine enter and update after a data join. For example, the following code in 3.x:
Selections are now immutable: the elements and parents in a selection will never change. (The elements’ attributes and content will of course still be modified!) The [*selection*.sort](https://github.com/d3/d3-selection#selection_sort) and [*selection*.data](https://github.com/d3/d3-selection#selection_data) methods now return new selections rather than modifying the selection in-place. In addition, [*selection*.append](https://github.com/d3/d3-selection#selection_append) no longer merges entering nodes into the update selection; use [*selection*.merge](https://github.com/d3/d3-selection#selection_merge) to combine enter and update after a data join. For example, the following code in 3.x:
```js
var circle = svg.selectAll("circle").data(data) // UPDATE
......@@ -680,7 +680,7 @@ var circle = svg.selectAll("circle").data(data) // UPDATE
circle.exit().remove(); // EXIT
circle.enter().append("circle") // ENTER, and merges into UPDATE!
circle.enter().append("circle") // ENTER, and merges into UPDATE! 🌶
.style("fill", "green");
circle // ENTER + UPDATE
......@@ -701,6 +701,8 @@ circle.enter().append("circle") // ENTER
.style("stroke", "black");
```
This change is discussed further in [What Makes Software Good?](https://medium.com/@mbostock/what-makes-software-good-943557f8a488#.4ukdnxqiz)
In 3.x, the [*selection*.enter](https://github.com/d3/d3-selection#selection_enter) and [*selection*.exit](https://github.com/d3/d3-selection#selection_exit) methods were undefined until you called *selection*.data. In 4.0, now they simply return the empty selection if the selection has not been joined to data.
In 3.x, [*selection*.append](https://github.com/d3/d3-selection#selection_append) would always append the new element as the last child of its parent. A little-known trick was to use [*selection*.insert](https://github.com/d3/d3-selection#selection_insert) without specifying a *before* selector when entering nodes, rather than *selection*.append, so that the entering nodes would be inserted into the DOM before the corresponding following element in the update selection. In 4.0, this is now the default behavior of *selection*.append, and if you do not specify a *before* selector to *selection*.insert, the inserted element is appended as the last child. This change makes the default general update pattern preserve the relative order of elements and data. For example, given the following DOM:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment