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
22
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,863
  • 3
  • 16
  • 27
22
votes
1 answer

Sorting by alphabetical order immutable.js

I would like to sort immutable.js orderedList by property name, data.map(x => x.get("name")) returns the string, I want to sort my map by name in alphabetical order. How to do that? I tried: return data.sortBy((val) => { if (dir === "up") { …
lipenco
  • 1,358
  • 5
  • 16
  • 30
21
votes
1 answer

Why does Immutable.js throw Invalid key path on Map.setIn()

I must be missing something here because the Docs make it out as if the below code should work just fine but I get an invalid keypath error... Check this codepen. var map1 = Immutable.Map({ 'selector': { 'type': 'bar' }}); var map2 =…
hally9k
  • 2,423
  • 2
  • 25
  • 47
21
votes
2 answers

Immutable.js - is it possible to insert element into list at arbitrary position?

How do I insert an element at arbitrary position of Immutable.js List?
AndreyM
  • 1,403
  • 2
  • 12
  • 23
19
votes
6 answers

Immutable - change elements in array with slice (no splice)

How is possible to change 3/4 elements? Expected output is [1,2,4,3,5] let list = [1,2,3,4,5]; const removeElement = list.indexOf(3); // remove number 3 list.slice(0, removeElement).concat(list.slice(removeElement+1)) // [1,2,4,5] ...next push…
Ingrid Oberbüchler
  • 766
  • 2
  • 6
  • 16
19
votes
3 answers

Delete object from ImmutableJS List based upon property value

What would be the simplest way to delete an object from a List based on a value of a property? I'm looking for an equivalent of the $pull in MongoDB. My List looks simple like this: [{a: '1' , b: '1'},{a: '2' , b: '2'}] And I'd like to remove from…
user3696212
  • 3,381
  • 5
  • 18
  • 31
19
votes
3 answers

ImmutableJS - delete element from Map

I have a map with this structure: { 1: {}, 2: {} } And I'd like to delete 2: {} from it (of course - return new collection without this). How can I do it? I tried this, but something is wrong: theFormerMap.deleteIn([],2) //[] should mean that it's…
user3696212
  • 3,381
  • 5
  • 18
  • 31
18
votes
1 answer

How to loop through Immutable List like forEach?

I would like to loop through Immutable List, I used List.map to do it, it can be worked, but not good. is there are a better way? Because I just check each element in array, if the element match my rule, I do something, just like Array.forEach, I…
Seven Lee
  • 597
  • 4
  • 9
  • 21
18
votes
3 answers

What is the "ownerID" in Immutable.js?

I'm going through Immutable.js's source code and there's an ownerID field that I don't understand. Here's the source for Map.asMutable() and Map.asImmutable(): https://github.com/facebook/immutable-js/blob/master/src/Map.js#L171 It seems like the…
Leo Jiang
  • 24,497
  • 49
  • 154
  • 284
18
votes
1 answer

Redux React create initial state from API

How to define initialState from API? Actions import * as types from '../constants/ActionTypes' import jquery from 'jquery' import { apiRoot } from '../config.js' import Immutable from 'immutable' import Random from 'random-js' export function…
Kris MP
  • 2,305
  • 6
  • 26
  • 38
18
votes
2 answers

Immutablejs: One liner code to convert keys of a map into array?

From the docs: Map#keys I get the keys of a Map and loop through it to transform them into an array. Is there a one line code to cleanly convert these keys into an array?
Melvin
  • 5,798
  • 8
  • 46
  • 55
17
votes
5 answers

Can TypeScript's `readonly` fully replace Immutable.js?

I have worked on a couple of projects using React.js. Some of them have used Flux, some Redux and some were just plain React apps utilizing Context. I really like the way how Redux is using functional patterns. However, there is a strong chance…
Storm
  • 3,062
  • 4
  • 23
  • 54
16
votes
7 answers

How to get index based value from Set

I am looking to store a list of unique string (hence Set) and wanted to retrieve the value based on the index. I used get(index) But it turned out it returns undefined. So it seems I did not understand Set well. In case value needed to be retrieved…
Anil Namde
  • 6,452
  • 11
  • 63
  • 100
16
votes
2 answers

How to loop through an Immutable Map of Immutable Maps?

I've got an immutable map of maps. let mapOfMaps = Immutable.fromJS({ 'abc': { id: 1 type: 'request' }, 'def': { id: 2 type: 'response' }, 'ghi': { type: cancel' }, 'jkl': { …
user1261710
  • 2,539
  • 5
  • 41
  • 72
16
votes
2 answers

In ImmutableJS, how to push a new array into a Map?

How can I achieve the following using ImmutableJS: myMap.get(key).push(newData);
Chopper Lee
  • 1,557
  • 2
  • 11
  • 30
1 2
3
80 81