I have run into many situations where what I need is a Map. When I do I always have the same question that needs to be answered: Should I polyfill Map or attempt to use a POJO as a Map? Ember has a private implementation of Map which would be nice but it is private.
For production code I’m looking for
- maintainability (will this be supported as the app upgrades)
- readability (how easy is it to grok its usage)
- developer ergonomics (how easy is it to work with)
I’ve narrowed down the API to the following two options: JavaScript Map via a polyfill, build my own via two denominational arrays, or manage it via a POJO. The later two are supported by all browsers and do not need a polyfill but does introduce some complexity. It is more obtuse to use Object.keys
then it is to simply iterate over the Map (for (let [ key, value ] of myMap)
) and less performent to force iteration to get a single value with two-dimentional arrays.
My questions are:
- Is it worth forcing a babel polyfill for the use of the built in Map?
- Is the private ember Map worth looking into if the keys are not strings?
- If the keys are always strings is it worth using Map at all just for the iteration and nice API or just manipulate a POJO with
pojo[name]
,pojo[name] =
,delete pojo[name]
, andObject.keys(pojo)
?