icepath
v0.0.15
Published
Utilities for treating frozen JavaScript objects as persistent immutable collections.
Downloads
85
Maintainers
Readme
icepath
Utilities for treating frozen JavaScript objects as persistent immutable collections.
Motivation
icepath
provides functions that allow you to "modify" a structure by returning a partial clone using structural sharing. Only collections in the structure that had a child change will be changed.
icepath
uses structural sharing at the object or array level. icepath
does not use tries to store objects or arrays, so updates will be less efficient. This is to maintain JavaScript interoperability at all times. Also, for smaller collections, the overhead of creating and managing a trie structure is slower than simply cloning the entire collection. However, using very large collections (e.g.collections with more than 1000 elements) with icepath
could lead to performance problems.
Structural sharing is useful wherever you can avoid expensive computation if you can quickly detect if the source data has changed. For example, shouldComponentUpdate
in a React component. If you are using a frozen hierarchical object to build a system of React components, you can be confident that a component doesn't need to update if its current props
strictly equal the nextProps
.
API
set
unset
assoc
get
update
chain
single
For Arrays:
push
pushIn
unshift
unshiftIn
pop
popIn
shift
shiftIn
reverse
reverseIn
sort
sortIn
splice
spliceIn
slice
sliceIn
map
mapIn
filter
filterIn
For Objects:
assign
assignIn
map
mapIn
filter
filterIn
License
MIT