immutable-js: add

This commit is contained in:
Rico Sta. Cruz 2015-11-23 18:26:30 +11:00
parent 48309c179c
commit b21bc0eac7
1 changed files with 43 additions and 0 deletions

43
immutable-js.md Normal file
View File

@ -0,0 +1,43 @@
---
title: Immutable.js
---
```js
var Immutable = require('immutable')
```
## Maps
```js
var map = Immutable.Map({ a: 1, b: 2, c: 3 })
map
.set('b', 50)
.get('b') // 50
```
## Lists
```js
var list = Immutable.List.of(1, 2)
list
.push(3, 4, 5)
.unshift(0)
.concat(list2, list3)
.get(0)
.size
```
## Nested maps
```js
var nested = Immutable.fromJS({ user: { profile: { name: 'John' } } })
nested
.mergeDeep({ user: { profile: { age: 90 } } })
.setIn([ 'user', 'profile', 'name' ], 'Jack')
.updateIn([ 'user', 'profile', 'name' ], (s) => s.toUpperCase())
.getIn(['user', 'profile', 'name']) // 'Jack'
```