Last active
November 24, 2016 01:57
-
-
Save r05al/23d8807375734821f7485ff4ecf66b80 to your computer and use it in GitHub Desktop.
immutable concepts
This file contains 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
Immutable data and Immutable.js | |
Inspired by Clojure, Scala, Haskell | |
Persistent data means API yields new updated data. | |
Data structures include: List, Stack, Map, OrderedMap, Set, OrderedSet, Record | |
Efficiency through use of structural sharing via hash map tries and vector tries. | |
npm install immutable | |
or | |
<script src="immutable.min.js"></script> | |
Data is passed from above rather than subscribed to. | |
Immutable collections treated as values rather than objects. | |
Values represent state at particular instance of time. | |
Objects are "copied" by making reference to original, | |
enable memory savings and speed boost. | |
API that returns new immutable collections | |
Array is to Immutable.List | |
Map is to Immutable.Map | |
Set is to Immutable.Set | |
Accepts raw JS objects, expects an Iterable | |
Seq evaluates lazily and does not cache immediate results | |
Immutable.Map accepts keys of any type | |
JavaScript Object properties are always strings | |
Converts back to raw JS objects shallowly with: | |
toArray(), toObject(), toJS(), toJSON() | |
Nested Structures | |
deep trees of data | |
mergeDeep(), updateIn(), getIn(), setIn() | |
Lazy Seq: lazy op for efficient chaining of iterable methods | |
assigning to variable does not execute | |
only performs work enough for requested result | |
take(), get() | |
Equality | |
=== and !=== checks instances | |
is() and equals() checks equivalent values | |
Batching Mutations | |
apply series of mutations before returning | |
creates temporary mutable copy of collection | |
withMutations(), asMutable(), asImmutable() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment