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.

1206 questions
36
votes
3 answers

Performance: Immutable.js Map vs List vs plain JS

Question Is there something wrong with my benchmark? How can Immutable.js find() be 8 times slower than array.find()? Ok, not entirely fair, since I'm using Immutable.Map inside of the Immutable.List. But to me this is a real world example. If I…
Michael
  • 1,764
  • 2
  • 20
  • 36
35
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
  • 402
  • 1
  • 4
  • 9
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
  • 72,912
  • 30
  • 168
  • 299
32
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
  • 716
  • 1
  • 7
  • 8
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,773
  • 3
  • 25
  • 31
28
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
  • 3,054
  • 1
  • 24
  • 25
27
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,651
  • 5
  • 28
  • 39
26
votes
1 answer

what does getIn() do in Immutable.js?

Unfortunately the documentation is very sparse : https://facebook.github.io/immutable-js/docs/#/Map/getIn Does anyone have an example? I am guessing that if I have a myObject like so : a: { b:{ c:"banana" } …
Oliver Watkins
  • 12,575
  • 33
  • 119
  • 225
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
  • 26,428
  • 32
  • 94
  • 144
26
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,816
  • 5
  • 49
  • 65
26
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
  • 14,388
  • 4
  • 30
  • 35
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
  • 89,644
  • 67
  • 288
  • 419
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
  • 12,554
  • 4
  • 38
  • 47
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
  • 21,680
  • 22
  • 74
  • 108
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,421
  • 1
  • 12
  • 18
1
2
3
80 81