Introducing immutable collections of ImmutableJS

introducing immutablejs

ImmutableJS is a library that allows us to manage different collections and add immutable qualities. It was created by Facebook in 2013 and is complemented perfectly with ReactJS flux architecture and the way they work with states and properties.

What is an immutable object?

An immutable object is basically one that after being created never changes. In Javascript objects are mutable by default. Example:

As you can see, to make a change to an object ( person2) reference (changed person). Working with immutable objects brings benefits such as:

  • When you are working with multiple threads or asynchronous processes, you don’t have to worry about the state as this will never change
  • More natural management of Maps and Set Collections
  • It avoids conflict between objects
  • It changes in your data are more explicit
  • It allows you to write queries or other simple data management algorithms.

Besides, when you are working with ImmutableJS you will get following advantages:

  • Implemented collections optimized for Javascript
  • Interaction with objects defined in the Javascript API
  • It works with nested collections

Using Immutable?

To use Immutable first we have to install it with NPM:

As you can see, when you create the new object ( person2 ) the referencing object does not change (person).

Immutable Collections

Immutable has several collections. Here are some most useful ones:


A map is basically an object which consists of key/value pairs:

It also has methods such as mergeDeep and mergeWith which suitable for working with both nested collections and iterations.

MergeDeep basically allows us to gain access to our collections modify data.

MergeWith allows us not only to merge to maps but returns us iterable object.

You can check the methods mentioned above and more Immutable API methods in its documentation.


It is the representation of an array in JavaScript. However, when it is altered, the sources never changes. Similarly to Maps, this collection also has methods for nested collections.


The Set collection is an array that does not allow duplicate values.

Immutable has many more collections that you may find useful when it comes to managing your data efficiently. So learn more about it in ImmutableJS and share your thoughts with us in the comment below.

WBD Team

Our excellent WBD team working day and night to put together best content for you.

You may also like...