Immutable.js provides persistent List, Map, Set, Record, and lazy Seq collections that return new data on change instead of mutating in place, with structural sharing for efficiency and bundled Flow and TypeScript types.
Overview
Immutable.js offers persistent immutable data structures for JavaScript programs where updates always yield new collections rather than changing existing objects in place. The goal is simpler state flow, less defensive copying, and straightforward change detection when data is treated as values compared by equality instead of reference.
Collections include List, Stack, Map, OrderedMap, Set, OrderedSet, and Record, implemented with structural sharing via hash-array mapped tries and vector tries. A lazy Seq allows chaining map, filter, and similar operations without building intermediate arrays. Utilities such as fromJS, toJS, getIn, setIn, and updateIn help convert plain objects and navigate nested trees.
The API mirrors familiar ES2015 Array, Map, and Set patterns while mutative-sounding methods return new immutables. Collections interoperate with plain JavaScript objects and arrays, support JSON serialization, and work with module bundlers or script tags in browsers. Type definitions ship with the npm package for Flow and TypeScript.
Batch local edits can use withMutations for performance when several changes precede returning an immutable snapshot. The library positions itself as a fit for React-style unidirectional data and memoization patterns where referential stability matters.
Key features
- Persistent List Map Set Record types
- Lazy Seq with Range and Repeat
- Structural sharing for updates
- Deep getIn setIn updateIn helpers
- fromJS and toJS plain object bridge
- Value equality via is and equals
- Bundled TypeScript and Flow types
- withMutations batch editing
Use cases
- React and Redux application state
- Undo-redo friendly data models
- Memoized derived view computations
- Nested configuration trees