1
1
import { Selection } from "./index.js" ;
2
2
import { EnterNode } from "./enter.js" ;
3
- import array from "../array.js" ;
4
3
import constant from "../constant.js" ;
5
4
6
5
function bindIndex ( parent , group , enter , update , exit , data ) {
@@ -90,7 +89,7 @@ export default function(value, key) {
90
89
var parent = parents [ j ] ,
91
90
group = groups [ j ] ,
92
91
groupLength = group . length ,
93
- data = array ( value . call ( parent , parent && parent . __data__ , j , parents ) ) ,
92
+ data = arraylike ( value . call ( parent , parent && parent . __data__ , j , parents ) ) ,
94
93
dataLength = data . length ,
95
94
enterGroup = enter [ j ] = new Array ( dataLength ) ,
96
95
updateGroup = update [ j ] = new Array ( dataLength ) ,
@@ -115,3 +114,15 @@ export default function(value, key) {
115
114
update . _exit = exit ;
116
115
return update ;
117
116
}
117
+
118
+ // Given some data, this returns an array-like view of it: an object that
119
+ // exposes a length property and allows numeric indexing. Note that unlike
120
+ // selectAll, this isn’t worried about “live” collections because the resulting
121
+ // array will only be used briefly while data is being bound. (It is possible to
122
+ // cause the data to change while iterating by using a key function, but please
123
+ // don’t; we’d rather avoid a gratuitous copy.)
124
+ function arraylike ( data ) {
125
+ return typeof data === "object" && "length" in data
126
+ ? data // Array, TypedArray, NodeList, array-like
127
+ : Array . from ( data ) ; // Map, Set, iterable, string, or anything else
128
+ }
0 commit comments