10/7/2019 - 10:08 PM

Immutable JS

Immutable JS

Data structures should be thought of as EITHER plain JavaScript OR Immutable.

Operations on an Immutable object return the result of the operation.

Operations on an Immutable object do not change the object itself, but instead create a new object.

Advantages- Get a nested value without checking it exists

Chaining operations like push

Modifying an object doesn’t change the original data, it returns a new object


fromJS - convert JS object to Immutable
toJS - convert Immutable to JS object
Map - object to Map
List - array to List
toObject - Map to object
toArray - List to array
get - get a value one level deep
getIn - get a nested value
first - get value of first key in map
last - get value of last key in map
has - check if map contains a key
hasIn - check if map has nested key
includes - check for nested value
keys - get all keys, best used with Es6 iterator
values - get all values
entries- get keys and values
set - add a key value pair to a Map
setIn - add a nested value to a Map