What about ES6 Maps and Sets?

Maps and Sets are two new primitives that were introduced in ES2015. Both are iterable, meaning that you can loop through them as if they were an array.
Why would you use these? They ultimately provide a more structured way for assigning and accessing data, and can seem familiar if you've ever used these primitives in other languages. That all said, I don't make use of them in this book because d3-selection can't really do much with them, and it's just easier to use arrays. While d3-collection has its own variants of Map and Set, they are mainly used to deal with array data while working with d3.nest and are ultimately just a polyfill for browsers that don't support them natively (for example, Internet Explorer). What does this mean, given that Babel will polyfill Map and Set for us? Not much. With D3, all pieces of data tend to end up in arrays anyhow.

Although some interest has been expressed in making ES6 Map and Set work with d3-selection, there's an open issue from 2015 showing that there isn't much movement on that front. Keep an eye on https://github.com/d3/d3/issues/2584 though, as this may change, particularly as browser support for Map and Set becomes more common.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset