Created
June 19, 2017 06:49
-
-
Save battmanz/7cec8c2f22ee55f60dd0c478236892de to your computer and use it in GitHub Desktop.
Immutable.js persistent data structures.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Use in place of `[]`. | |
| const list1 = Immutable.List(['A', 'B', 'C']); | |
| const list2 = list1.push('D', 'E'); | |
| console.log([...list1]); // ['A', 'B', 'C'] | |
| console.log([...list2]); // ['A', 'B', 'C', 'D', 'E'] | |
| // Use in place of `new Map()` | |
| const map1 = Immutable.Map([ | |
| ['one', 1], | |
| ['two', 2], | |
| ['three', 3] | |
| ]); | |
| const map2 = map1.set('four', 4); | |
| console.log([...map1]); // [['one', 1], ['two', 2], ['three', 3]] | |
| console.log([...map2]); // [['one', 1], ['two', 2], ['three', 3], ['four', 4]] | |
| // Use in place of `new Set()` | |
| const set1 = Immutable.Set([1, 2, 3, 3, 3, 3, 3, 4]); | |
| const set2 = set1.add(5); | |
| console.log([...set1]); // [1, 2, 3, 4] | |
| console.log([...set2]); // [1, 2, 3, 4, 5] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment