SortedMap implemented in Immutable.js
npm install immutable-sorted-mapEver wish Immutable.js Maps would insert new items sorted by key?
Issue #88 inspired me to extend Immutable's Map to do just this.
$ npm install immutable-sorted-map $ yarn install immutable-sorted-mapjavaScript
import SortedMap from 'immutable-sorted-map'const myData = {
'0.01': 'hundredth',
'0.001': 'thousandth',
'0.1': 'tenth'
}
const compareKeys = (currKey, nextKey) => {
const currNum = Number(currKey)
const nextNum = Number(nextKey)
if (currNum < nextNum) return -1
if (currNum > nextNum) return 1
return 0
}
const myImmutableData = new SortedMap(myData, compareKeys)
myImmutableData.toJS()
/* {
'0.001': 'thousandth',
'0.01': 'hundredth',
'0.1': 'tenth'
} */
``