Comments (3)
Consistency with the standard is good, but there are complicating factors here, namely that d3.map is not a shim for ES6 Map because it’s not really possible to shim ES6 Map. You can get a lot closer than d3.map, but I taking it as far as you can would be counterproductive. Some differences:
- D3’s map coerces keys to strings, whereas ES6 Maps can use any object.
- D3 calls it map.remove, whereas ES6 says map.delete.
- D3 lacks a map.clear method.
- D3’s map is not iterable. (There’s not really a way to shim this feature.)
- Likewise, D3’s map.keys returns an array, not an iterator.
- Likewise, D3’s map.values returns an array, not an iterator.
- D3’s map.entries method returns an array of {key, value} objects, not an iterator of [key, value].
- D3’s map.set returns the new value, not the map instance
- D3’s map.size is a method, not a read-only accessor property.
- D3’s map.forEach doesn’t accept a thisArg.
- D3 provides a map.empty method.
Until recently, my plan for 4.0 was to remove d3.map and d3.set, adopt ES6 Map and Set, and provide a barebones shim for runtimes that lack this native feature. But I decided the polyfill approach was flawed because the shim behaves very differently from the native feature, and this would leak out in D3’s public API (such as d3.namespaces and nest.map, which previously used ES6 Map).
I’d love to drop the shim and use ES6 Map and Set directly, but I don’t think it’s appropriate yet to require that of all users. And I don’t believe it’s possible to create a true shim of ES6 collections because that depends on language features like iterators and symbols.
Now, my intention is for d3.map and d3.set to exist on their own independent of ES6: similar, yes, but different. It’s confusing that the forEach method uses the opposite order of arguments from ES6, but d3.map has been around since February 2012, and changing the behavior now would be confusing, too.
So… how about renaming it to map.each and set.each? That’s similar to selection.each, and would make the difference from ES6 more apparent. And, it’s shorter and all lowercase, which I like. 😁
from d3-array.
See #14.
from d3-array.
Fixed in 0.2.0.
from d3-array.
Related Issues (20)
- BUG: d3-array/dist/d3-array.js: Unexpected token (139:15) HOT 4
- fix(babel): cumsum HOT 1
- binary ticks increments on linear scale HOT 2
- D3-array produces ERR_REQUIRE_ESM with node >= 15 HOT 3
- bisectCenter naming HOT 1
- quantile returns undefined on an empty array, differs from extent HOT 1
- Docs: define the bin thresholds with array HOT 2
- First and last thresholds are set to data extent (not explicitly stated limits) HOT 2
- bisector no longer supports two-argument (object, value) comparator HOT 12
- Testing a lib using `d3-array` HOT 1
- d3.blur HOT 1
- Incorrect results for binary search on large arrays due to miscomputation of midpoint HOT 11
- d3.bin can mutate the user-specified thresholds
- About the sorting problem of d3.rank HOT 2
- Insecure Randomness for the useof Math.random() in shuffle API (security vulnerability) HOT 1
- d3.thresholdScott returns NaN for single-element arrays
- Feature request: `find` / `findValue` methods
- groupSort should use ascendingDefined instead of ascending
- medianIndex/quantileIndex doesn’t handle missing data HOT 3
- can d3-array also support BigInt numbers? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3-array.