Learn how to use Immutable.js

91 minutes

im·mu·ta·ble i(m)ˈmyo͞odəb(ə)l/ adjective - unchanging over time or unable to be changed.

Mutating data is the source of never ending headaches in software systems, and JavaScript code is no exception. Immutable data structures, pure functions, uni-directional data flow... you've probably been hearing these terms.

Immutable.js provides us the data structures and utilities that we need to start introducing this powerful concept of immutability into our applications.

pro-course-rss-logo

PRO RSS Feed

Manage Application State with Immutable.js

Creating an Immutable Object Graph with Immutable.js Map()

P

Modifying an Immutable.js Map()

P

Querying an Immutable.js Map()

P

Iterating Over an Immutable.js Map()

P

Working with Subsets of an Immutable.js Map()

P

Equality Checking with .is() and More

P

Using fromJS() to Convert Plain JavaScript Objects into Immutable Data

P

Differences between the Immutable.js Map() and List()

P

Exploring Sequences and Range() in Immutable.js

P

Converting Immutable.js Structures to Javascript and other Immutable Types

P

Simple Undo/Redo with Immutable.js Data Structures

P

Maintaining Order in Immutable.js Objects

P

Transforming Immutable Data with Reduce

P

Lightning Fast Immutable.js Equality Checks with Hash Codes

P

Immutable.Record() as data models

P
js tutorial about Manage Application State with Immutable.js

Manage Application State with Immutable.js

2:36 js

Learn how Immutable.js data structures are different from native iterable Javascript data types and why they provide an excellent foundation on which to build your application's state.

js tutorial about Creating an Immutable Object Graph with Immutable.js Map()

Creating an Immutable Object Graph with Immutable.js Map()

3:15 js PRO

Learn how to create an Immutable.Map() through plain Javascript object construction and also via array tuples.

js tutorial about Modifying an Immutable.js Map()

Modifying an Immutable.js Map()

5:22 js PRO

We will now look at five methods that modify an Immutable.Map(). I highly encourage you to visit the Immutable.js documentation where I am now. They are set, delete, clear, update and merge. These are used often, so let's get to know them well.

js tutorial about Querying an Immutable.js Map()

Querying an Immutable.js Map()

4:47 js PRO

Learn how to query an Immutable.Map() using get, getIn, has, includes, find, first and last. These are powerful operators that make finding data in an object graph pain free.

js tutorial about Iterating Over an Immutable.js Map()

Iterating Over an Immutable.js Map()

6:31 js PRO

Immutable.js provides several methods to iterate over an Immutable.Map(). These also apply to the other immutable structures found within the Immutable.js family, such as Set and List. The primary methods are map and forEach, but we will also cover filter and groupBy.

js tutorial about Working with Subsets of an Immutable.js Map()

Working with Subsets of an Immutable.js Map()

7:43 js PRO

Immutable.js offers methods to break immutable structures into subsets much like Array--for instance it has the all powerful slice()--and unlike Array it offers functional methods like take() and skip(). You get the best of both the imperative and functional worlds.

js tutorial about Equality Checking with .is() and More

Equality Checking with .is() and More

4:02 js PRO

Equality checking deeply nested objects is painful. Fortunately Immutable.js makes this task easy with its .is() and .isSubset() methods. Let's see how we can take two different Immutable Maps() and check for equality.

js tutorial about Using fromJS() to Convert Plain JavaScript Objects into Immutable Data

Using fromJS() to Convert Plain JavaScript Objects into Immutable Data

6:39 js PRO

Immutable.js offers the fromJS() method to build immutable structures from objects and array. Objects are converted into maps. Arrays are converted into lists. The fromJS() method can also take a reviver function for custom conversions.

js tutorial about Differences between the Immutable.js Map() and List()

Differences between the Immutable.js Map() and List()

4:02 js PRO

The Immutable.js Map() is analogous to a Javascript Object or Hash since it is comprised of key-value pairs. The Immutable.js List() is analogous to a Javascript Array and contains many of the same native methods. Let's compare the two and dive into the basics of List().

js tutorial about Exploring Sequences and Range() in Immutable.js

Exploring Sequences and Range() in Immutable.js

6:59 js PRO

Understanding Immutable.js's Map() and List() structures will likely take you as far as you want to go with immutable programming. They have only small semantic differences between each other and the remaining structures in the Immutable.js family. Sequence, however, has one major difference: it's lazy--which opens a new realm of functional possibilities. Let's write a simple sequence to start.

js tutorial about Converting Immutable.js Structures to Javascript and other Immutable Types

Converting Immutable.js Structures to Javascript and other Immutable Types

5:57 js PRO

Immutable.js provides several conversion methods to migrate one structure to another. Each Immutable.js class contains a prefixed "to" method like Map.toList(), Map.toSet(), etc. Converting these types sometimes results in a loss of data, as we will see when converting from Map to List.

js tutorial about Simple Undo/Redo with Immutable.js Data Structures

Simple Undo/Redo with Immutable.js Data Structures

8:35 js PRO

Implementing Undo/Redo can be tricky business. Consider two strategies to simplify implenting undo/redo: 1) use immutable data 2) react to that data with a top-down approach. Let's build a simple drawing app that will draw circles on a canvas and allow us to undo/redo our drawing.

js tutorial about Maintaining Order in Immutable.js Objects

Maintaining Order in Immutable.js Objects

8:08 js PRO

Immutable.js's Map doesn't promise iteration order after a set() operation. When we need a guarantee for iteration order, we can use OrderedMap. This comes at a slight performance cost, or for you computer science people, it is amortized at an unstable O(log32 N). Let's explore ordering.

js tutorial about Transforming Immutable Data with Reduce

Transforming Immutable Data with Reduce

8:25 js PRO

Immutable.js iterables offer the reduce() method, a powerful and often misunderstood functional operator on which map(), filter(), groupBy(), etc. are built. The concept is simple: reduce transforms your iterable into something else, that's all. The name is misleading as you may or may not actually "reduce" anything. Let's replicate the groupBy() and filter() methods with reduce to illustrate how it works.

js tutorial about Lightning Fast Immutable.js Equality Checks with Hash Codes

Lightning Fast Immutable.js Equality Checks with Hash Codes

2:27 js PRO

While Immutable.js offers .is() to confirm value equality between iterables it comes at the cost of referencing each key and value in both objects. For lightning fast equality checks, Immutable.js can produce a hash code based on an iterable's content. If two iterables have the same content, their hash codes will be the same. It's worth noting that this technique is unsuitable for mission critical application development since there is a chance, however slight, that checksums like these might collide. This is outlined here: https://en.wikipedia.org/wiki/Collision_(computer_science)

js tutorial about Immutable.Record() as data models

Immutable.Record() as data models

5:33 js PRO

The Immutable.js Record() allows you to model your immutable data much like you would model data with native Javascript classes or objects. It differs from native classes because it cannot be mutated after it's creation and it always has a default value. It's an excellent construct in which to piece together your stores, be them Flux or some other storage implementation. Let's quickly create an Immutable Record().

Presented by:

J.S. Leonard

J.S. Leonard resides in his birthplace, Las Vegas, Nevada, where he weaves words, code and colors into remarkable experiences. He is married to a pretty rad chick and has two crazy young boys. No, he doesn't gamble. Yes, people actually live in Las Vegas.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?