Questions tagged [immutable.js]

Immutable.js provides Persistent Immutable List, Stack, Map, OrderedMap, Set, OrderedSet and Record. They are highly efficient on modern JavaScript VMs (browser and nodejs) by using structural sharing via hash maps tries and vector tries as popularized by Clojure and Scala, minimizing the need to copy or cache data.

Immutable provides immutable data structures like List, Stack, Map, OrderedMap, Set and Record by using persistent hash maps tries and vector tries as popularized by Clojure and Scala. They achieve efficiency on modern JavaScript VMs by using structural sharing and minimizing the need to copy or cache data.

Immutable also provides a lazy Seq, allowing efficient chaining of collection methods like map and filter without creating intermediate representations. Create some Seq with Range and Repeat.

Getting started:

Install immutable using npm.

npm install immutable

Then require it into any module.

var Immutable = require('immutable');
var map = Immutable.Map({a:1, b:2, c:3});

Useful links:

License:

Immutable is BSD-licensed. We also provide an additional patent grant.

1177 questions
34
votes
6 answers

How to specify null prop type in ReactJS?

I've got a prop on a ReactJS Component that's either null or an Immutable Map. At the bottom of my widget if I write: MyComponent.propTypes = { myMap: React.PropTypes.instanceOf(Immutable.Map) }; I am leaving this open to the possibility of…
user1261710
  • 2,125
  • 5
  • 31
  • 55
34
votes
1 answer

Do Immutable.js or Lazy.js perform short-cut fusion?

First, let me define what is short-cut fusion for those of you who don't know. Consider the following array transformation in JavaScript: var a = [1,2,3,4,5].map(square).map(increment); console.log(a); function square(x) { return x *…
Aadit M Shah
  • 67,342
  • 26
  • 146
  • 271
32
votes
2 answers

Redux state is undefined in mapStateToProps

I am currently following this tutorial. I've hit a bit of a snag involving mapStateToProps in the following code: import React from 'react'; import Voting from './voting'; import {connect} from 'react-redux'; const mapStateToProps = (state) => { …
esaminu
  • 362
  • 1
  • 3
  • 9
31
votes
2 answers

Getting nested values in Immutable.js

According to the docs here: https://facebook.github.io/immutable-js/docs/#/Map/getIn I should be able to get the deeply nested value by providing an array for the keyPath argument. This is what I've done, however I'm getting undefined as the return…
xiankai
  • 2,675
  • 3
  • 21
  • 30
30
votes
3 answers

When should I use `withMutations` on a map in Immutable.js?

I have a series of mutations to make on my Immutable.js map. At what point should I prefer using withMutations rather than creating intermediate immutable maps? From the Immutable.js docs: If you need to apply a series of mutations to produce a…
dstreit
  • 596
  • 1
  • 5
  • 8
27
votes
3 answers

Immutable.js Map values to array

I am using the immutable Map from http://facebook.github.io/immutable-js/docs/#/Map I need to get an array of the values out to pass to a backend service and I think I am missing something basic, how do I do it ? I have tried :…
LenW
  • 2,854
  • 1
  • 22
  • 25
26
votes
6 answers

How to remove an object from an array in Immutable?

Given a state like this: state = { things: [ { id: 'a1', name: 'thing 1' }, { id: 'a2', name: 'thing 2' }, ], }; How can I create a new state where ID "a1" is removed? It's easy enough to push new items: return…
ffxsam
  • 20,847
  • 29
  • 72
  • 128
26
votes
3 answers

React performance: rendering big list with PureRenderMixin

I took a TodoList example to reflect my problem but obviously my real-world code is more complex. I have some pseudo-code like this. var Todo = React.createClass({ mixins: [PureRenderMixin], ............ } var TodosContainer =…
Sebastien Lorber
  • 79,294
  • 59
  • 260
  • 386
26
votes
5 answers

Immutable.js relationships

Imagine a situation that John have two childrens Alice and Bob, and Bob have a cat Orion. var Immutable = require('immutable'); var parent = Immutable.Map({name: 'John'}); var childrens = Immutable.List([ Immutable.Map({name: 'Alice', parent:…
user1518183
  • 4,255
  • 4
  • 24
  • 39
24
votes
2 answers

Immutable.js Push into array in nested object

Assume there is an object: const object = { 'foo': { 'bar': [1, 2, 3] } } I need to push 4 to object.foo.bar array. Right now I'm doing it like this: const initialState = Immutable.fromJS(object) const newState = initialState.setIn( …
Alexandr Lazarev
  • 11,333
  • 2
  • 30
  • 45
24
votes
4 answers

immutable.js get keys from map/hash

I want to retrieve keys() from the following Immutable Map: var map = Immutable.fromJS({"firstKey": null, "secondKey": null }); console.log(JSON.stringify(map.keys())); I would expect the output: ["firstKey", "secondKey"] However this…
knagode
  • 5,090
  • 5
  • 42
  • 58
24
votes
1 answer

Can I use destructuring assignment with immutable.js?

With standard JS objects, one can use destructuring assignment such as: let obj = {name: 'james', code: '007'} let {name, code} = obj // creates new variables 'name' and 'code' (with the proper values) As suggested by some Flux / Redux evangelist,…
Tomas Kulich
  • 10,850
  • 3
  • 24
  • 30
23
votes
3 answers

What are disadvantages to using immutable state in React?

I have built my first React application with stateful stores the "normal" way, and now I am looking into using an immutable global state like used in the Este starterkit. The state of all stores is kept together in a single immutable data…
Thijs Koerselman
  • 16,219
  • 15
  • 62
  • 89
23
votes
4 answers

How do I transform a List of Maps into a Map of Maps in immutable.js?

Suppose I have an immutable.js List like this: var xs = Immutable.fromJS([{key: "k", text: "foo"}]) I want to transform that into a Map that looks like this: var ys = Immutable.fromJS({k: {key: "k", text: "foo"}}) How do I turn xs into ys…
CJ Gaconnet
  • 1,391
  • 1
  • 11
  • 17
21
votes
2 answers

How to remove duplicates from an unordered Immutable.List()?

How would one remove duplicates from an unordered Immutable.List()? (without using toJS() or toArray()) e.g. Immutable.List.of("green", "blue","green","black", "blue")
ThorbenA
  • 1,613
  • 2
  • 13
  • 25
1
2
3
78 79