immutable-sorted-map
v0.3.0
Published
SortedMap implemented in Immutable.js
Downloads
4
Maintainers
Readme
Immutable Sorted Map
Ever wish Immutable.js Maps would insert new items sorted by key?
Issue #88 inspired me to extend Immutable's Map to do just this.
Installation
Using npm:$ npm install immutable-sorted-map
Using yarn:$ yarn install immutable-sorted-map
Usage
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'
} */
Api
See the documentation for Immutable's Map