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

spread operator vs immutable.js

It seems like when using redux with react, immutable.js has become almost a industry standard. My question is, aren't we making changes to our redux states immutably when we are using the spread operator? For example, const reducer =…
Young Moon
  • 123
  • 1
  • 5
11
votes
1 answer

How Immutability is Implemented

I am trying to grasp how the trie and such in immutability is implemented, as relates to immutability in JS. I understand how there is supposed to be significant structural sharing. My question is say you have a graph sort of structure like this: a…
Lance
  • 75,200
  • 93
  • 289
  • 503
11
votes
4 answers

How to chunk ImmutableJS list into multiple lists

Is there a way to separate an ImmutableJS list into a list of multiple lists ? I'm basically looking for something like lodash's chunk but for ImmutableJS lists. I could transform my list into an Array before passing it to chunk and convert back the…
Gerard Clos
  • 1,080
  • 2
  • 12
  • 21
11
votes
3 answers

ImmutableJS - update value in a List

I have a Map like this (in ImmutableJS): {arrayOfValues: [ {one: {inside: 'first in array'}}, {one: {inside: 'second in array'}} ]} And I want to update the value "inside" in the second entry in the "arrayOfValues" array. How can I do it? This…
user3696212
  • 3,381
  • 5
  • 18
  • 31
10
votes
2 answers

Vue.js and Immutable.js

I'm working on a Vue.js application where I have to deal with deeply nested data structures (trees and forests). After reading about using simple data structures, pure functions and reducing (non-local) mutation, I belief that embracing those ideas…
Willem-Aart
  • 2,200
  • 2
  • 19
  • 27
10
votes
2 answers

How to iterate over Map in immutablejs

What is the equivalent to Object.entries() in Immutablejs Map. Basically, I enumerate the object's key/value pairs to render a presentational component { Object.entries(filteredNetworks) .map(([key, value]) =>
10
votes
1 answer

Custom equality semantics for Immutable.js data structures

I would like Sanctuary to provide Fantasy Land -compatible Map and Set types with value-based equality semantics. Ideally these values would be immutable, though this is not critical since Sanctuary would provide pure functions for merging and…
davidchambers
  • 23,918
  • 16
  • 76
  • 105
10
votes
2 answers

How to declare a Map containing certain properties with flowtype & immutable.js

Given a website object created like this import {Map} from 'immutable' const website = new Map({name: 'My Website', url: 'http://www.myw.fr'}) How could I declare a websiteType which would be a map containing exactly the given properties. I know…
Nihau
  • 474
  • 3
  • 20
10
votes
2 answers

Immutable.js Map set vs update

I would like to change a value at a key in a Map I have. Other than the fact that using update will give me an error if the key I ask to update doesn't exist, what benefit is there (if any) to using update over set? I find set to be significantly…
Matthew Herbst
  • 29,477
  • 23
  • 85
  • 128
10
votes
2 answers

Best way to remove an element from a List inside of a Map in Immutable.js

I am using Facebook's Immutable.js to speed up my React application to take advantage of the PureRender mixin. One of my data structures is a Map() and one of the keys in that map has a List() as its value. What I'm wondering is, not knowing…
Matthew Herbst
  • 29,477
  • 23
  • 85
  • 128
9
votes
2 answers

immutable.js filter and mutate (remove) found entries

I have two loops, one for each day of the month, other with all events for this month. Let's say I have 100 000 events. I'm looking for a way to remove events from the main events List once they were "consumed". The code is something like: const…
enapupe
  • 15,691
  • 3
  • 29
  • 45
9
votes
2 answers

What is the best implememtation of react shouldComponentUpdate with immutable.js

I'm new to ImmutableJS. My app implements large Redux Store & multiple react components. Correct me if I'm wrong: I understand that the benefits of Immutable is to protect Flux Store and to avoid unnecessary vDom rendering on component getting…
Damien Leroux
  • 11,177
  • 7
  • 43
  • 57
9
votes
1 answer

How does ImmutableJS work with Angular 2?

I've been using ImmutableJS with Angular 2 for some time, because of it's performance benefits in change detection. See here. However, I'm not quite sure, why Immutable works with Angular 2 by default. How does it know how to iterate over the values…
Luka Jacobowitz
  • 22,795
  • 5
  • 39
  • 57
9
votes
1 answer

mapStateToProps must return an object. Instead received Map {}?

Hello i use Immuteble Map for state and when i try maspStateToProps i have this error. Uncaught Invariant Violation: mapStateToProps must return an object. Instead received Map {}. Here is my code: Component: const mapStateToProps = (state)…
Grund
  • 309
  • 1
  • 2
  • 12
9
votes
4 answers

How to setup Ember like computed properties in Immutablejs and Redux and Flux and React

I am used to computed properties in Ember Object Model. It's a convenient way to specify computed properties that depend on other properties. Say fullName depends on firstName and lastName, I can setup computed properties as a function…
eguneys
  • 6,028
  • 7
  • 31
  • 63