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
15
votes
2 answers

How to use Immutable JS with typed ES6 classes?

Say I have classes Task and TaskGroup class Task{ constructor(public text:string){} } class TaskGroup { constructor(public title:string = "new task group", public tasks:Task[] = []){} } Then in my Angular 2 service I will create an…
Frozen Crayon
  • 5,172
  • 8
  • 36
  • 71
15
votes
2 answers

Parsing nested Records in Immutable.js

Suppose I have the following Records defined using Immutable.js: var Address = Immutable.Record({street: '', city: '', zip: ''}); var User = Immutable.Record({name: '', address: new Address()}); How do I convert plain javascript object into the…
dkl
  • 3,850
  • 2
  • 27
  • 26
14
votes
1 answer

Is it possible to wrap a flow type in an immutable container?

For example, given the following record: type UserRecord = { id: string; name: ?string; age: number; } Is there some way to do the equivalent of the following: /* @flow */ import { List, Map } from 'immutable' const users:…
gf3
  • 481
  • 2
  • 11
14
votes
1 answer

How to get the first key (not value) of immutable.js map?

How to get the first key (not value) of immutable.js map? basically myMap.first() will return the value, but I am interested in the key... I can do a forEach and store first, but must be a better way! didn't see it in the docs, prob missing it...…
born2net
  • 24,129
  • 22
  • 65
  • 104
14
votes
2 answers

Performance issues with a tree structure and shouldComponentUpdate in React / Redux

I'm fairly new to React, Redux and ImmutableJS, and have run into some performance issues. I have a large tree structure of data, which I'm currently storing as a flat list in this structure: new Map({ 1: new Node({ id: 1, text: 'Root', …
Paddy Mann
  • 1,169
  • 12
  • 18
14
votes
2 answers

Using PropTypes when immutable-js in react-js

I am using immutable-js and react-immutable-proptypes in React. // CommentBox.jsx getInitialState() { return { comments: Immutable.List.of( {author: 'Pete Hunt', text: 'Hey there!'}, {author: 'Justin Gordon',…
rubyu2
  • 270
  • 1
  • 3
  • 14
13
votes
1 answer

Flow: Typechecking a complex Immutable shape using fromJS()?

How do you typecheck the shape of an Immutable.JS data structure generated from fromJS using Flow? Plain old JS blobs can be typed very accurately using an object literal notation: type ObjectShape = { a: number, b: string, c: { d:…
Jon Cursi
  • 3,301
  • 4
  • 27
  • 53
13
votes
2 answers

Append value to List

I have a immutable list object, within a Map object, as follows: let initialState = Immutable.fromJS({}); state = initialState; state = state.set("myList", Immutable.List()); How do I append a value to "myList", thereby updating state?
Baz
  • 12,713
  • 38
  • 145
  • 268
13
votes
2 answers

converting immutable fromJS object back to json

I want to be able to look at my immutable objects for debugging. I find it very difficult to look through an object by clicking on entries and such. Ideally what I would like is the opposite of the formJS function so, const immutableObj =…
DrivingInsanee
  • 1,631
  • 2
  • 13
  • 22
13
votes
3 answers

Immutable JS compare nested structures

I have 2 nested structures newState and newState1. But when I compare their, equals() or Immutable.is() returned false. The values in these structures identical. How to correctly compare newState and newState1? var grid = { editable: false, …
Slava Minchonok
  • 141
  • 1
  • 1
  • 7
12
votes
2 answers

What are the advantages and disadvantages of mobx and Redux, particularly in a React-Native environment?

Lately I've been hearing everyone talking about mobx, I've used (am using) Redux in a production React Native application. I'm just looking to see if anyone has experience with both and can advise where each one holds advantages over the other.
R. Langford
  • 163
  • 1
  • 8
12
votes
4 answers

Redux + ImmutableJS - how to garbage collect too large store?

I'm using Redux with ImmutableJS. In my SPA (quite complicated administration system), users often load a lot of data into stores (thousands rows for many tables). After opening several pages and having too many data in the store, the app becomes…
user3696212
  • 3,381
  • 5
  • 18
  • 31
12
votes
2 answers

Immutable.js: How to find an object in an array by specify property value

I have an array made by Immutable.js: var arr = Immutable.List.of( { id: 'id01', enable: true }, { id: 'id02', enable: true }, { id: 'id03', …
hh54188
  • 14,887
  • 32
  • 113
  • 184
12
votes
2 answers

Two immutable lists - how to make triple equality work?

Let's say we have an immutable object that is created using Facebook's great Immutable.js. I want to compare two lists that were produced using .map or .filter out of single source and make sure they are equal. It seems to me, that when using…
mseimys
  • 588
  • 1
  • 7
  • 16
12
votes
6 answers

Any way to use immutable.js with lodash?

I'm using immutable.js with my flux application. It is very useful and gives performance boost. But what actually makes me sad is the fact that I can't use lodash together with it. Lodash provides great API with ton of useful functions, so I wonder…
Boris Zagoruiko
  • 12,705
  • 15
  • 47
  • 79