SlideShare a Scribd company logo
Immutable.js
@TinaHeiligers1, tina.heiligers@gmail.com, 

https://github.com/TinaHeiligers
https://facebook.github.io/immutable-js/
What is Immutable.js?
• Provides immutable data structures with getters and
setters

• Persistent data: always yields new updated data.

• Highly efficient, e.g:

• List get & set O(log32 N), push & pop O(1)

• Map get & set: O(log32 N)
What is Immutable.js?
• Provides immutable data structures with getters and
setters

• Persistent data: always yields new updated data.

• Highly efficient, e.g:

• List get & set O(log32 N), push & pop O(1)

• Map get & set: O(log32 N)
What is Immutable.js?
• Provides immutable data structures with getters and
setters

• Persistent data: always yields new updated data.

• Highly efficient, e.g:

• List get & set O(log32 N), push & pop O(1)

• Map get & set: O(log32 N)
~ Array O(N)
What is Immutable.js?
• Provides immutable data structures with getters and
setters

• Persistent data: always yields new updated data.

• Highly efficient, e.g:

• List get & set O(log32 N), push & pop O(1)

• Map get & set: O(log32 N)
~ Array O(N)
~ Object O(N)
List: Construction
List: Getters
• has(): Boolean
• includes(): Boolean
• first(): List.size > 0 ? value : undefined
List: Setters
•set(): changes item at index given (-1 changes the last value)
•delete() (alias remove()): deletes item at index given
•insert(): inserts item at the index given
•clear(): empties the List
•push(): appends items at the end
•pop(): removes the last item
•unshift(): inserts items at the start
•shift(): removes first item
•update(): updates items after some modifications have been made, useful for chaining
•setSize(): adds or removes items from a list until the new list has the required
size. If size < current size, items at higher indices are removed. If size > current
size, undefined is appended at the higher indices until the required size is
attained.
List: Setters
•set(): changes item at index given (-1 changes the last value)
•delete() (alias remove()): deletes item at index given
•insert(): inserts item at the index given
•clear(): empties the List
•push(): appends items at the end
•pop(): removes the last item
•unshift(): inserts items at the start
•shift(): removes first item
•update(): updates items after some modifications have been made, useful for chaining
•setSize(): adds or removes items from a list until the new list has the required
size. If size < current size, items at higher indices are removed. If size > current
size, undefined is appended at the higher indices until the required size is
attained.
New Lists are returned!
Map: Construction
Map: Construction
From (editable) immutable docs!
Map: Getters
Shallow values:
• get(): returns value with provided key if
it exists, otherwise undefined
• has(): Boolean
• includes(): Boolean
• first(): if non-empty, first element in
collection, otherwise undefined
• last(): if non-empty, last element in
Map: Setters
Shallow setters:
• set():Returns a new Map also containing the new key, value pair. If an
equivalent key already exists in this Map, it will be replaced
• delete(): returns a new Map that excludes the key
• deleteAll(): returns a new Map that excludes the keys provided
• clear(): returns a new Map with no keys or values
• update():returns a new Map having updated the value at the key given
after returning from some updating function, useful for chaining
• merge(): merges the provided collection into the current Map, returning
a new Map
• mergeWith(): does the same thing as merge, but uses some merger function
first (like division, multiplication etc).
Map: Setters cont.
Shallow setters:
• mergeDeep(): like merge but if two collections conflict, it uses
recursive deep merging through the nested data
• mergeDeepWith(): does the same thing as mergeDeep but uses a merging
function
Deep persistent changes:
• setIn(): sets a value at the given keyPath
• deleteIn(): removes value at the given keyPath
• updateIn(): updates value at the given keyPath
• mergeIn(): combination of updateIn() and merge()
• mergeDeepIn(): combination of updateIn() and mergeDeep()
…and more
• OrderedMap
• Set
• OrderedSet
• Stack
• Record
• Seq
• Collection
Why do we care anyway?
Why do we care anyway?
Redux!
Why do we care anyway?
• Immutable State

• Pure reducers

• Immutable data management => safer data handling

• Time-travel debugging needs pure functions with no
side effects to jump between different states
Redux!
Why do we care anyway?
• Immutable State

• Pure reducers

• Immutable data management => safer data handling

• Time-travel debugging needs pure functions with no
side effects to jump between different states
Consistently return same output for given input
Don’t alter input data
Don’t depend on external state
Redux!
From: React With Redux (Desert Code Camp 2018)
Why do we use Redux
again?
Why is immutability such a
big deal in React with Redux?
Use shallow equality checking for performance
• CombineReducers (redux) -> shallowly checks for
reference changes caused by the reducers that it calls.

• Connect (react-redux) -> generates components that
shallowly check reference changes to the root state, and
the return values from the `mapStateToProps` function to
see if the wrapped components actually need to re-render
Why is immutability such a
big deal in React with Redux?
Use shallow equality checking for performance
• CombineReducers (redux) -> shallowly checks for
reference changes caused by the reducers that it calls.

• Connect (react-redux) -> generates components that
shallowly check reference changes to the root state, and
the return values from the `mapStateToProps` function to
see if the wrapped components actually need to re-render
?
What is shallow equality checking?
Equality by reference:
Shallow equality checking
What is shallow equality checking?
Equality by reference: Equality by value:
Recursive, deep equality checking
Shallow equality checking
The how…by example
comparison
• Main App (entry point)

• Container

• Reducer

• Store

• Root reducer
The how…by example
comparison
• Main App (entry point)

• Container

• Reducer

• Store

• Root reducer
Without & with
Immutable
App (no Immutable)
App (no Immutable)
Container (no Immutable)
Container (no Immutable)
Justtogetourbearings
Container (no Immutable)
Container (no Immutable)
Container (no Immutable)
Container (no Immutable)
Reducer (no Immutable)
Reducer (no Immutable)
Reducer (no Immutable)
Reducer (no Immutable)
Reducer (no Immutable)
Reducer (no Immutable)
Root Reducer (no Immutable)
Store (no Immutable)
App (with Immutable)
App (with Immutable)
Container (with Immutable)
Container (with Immutable)
Almostthesame
Container (with Immutable)
Container (with Immutable)
Container (with Immutable)
Container (with Immutable)
Container (with Immutable)
Reducer (with Immutable)
Reducer (with Immutable)
Reducer (with Immutable)
Reducer (with Immutable)
Reducer (with Immutable)
Reducer (with Immutable)
Store (with Immutable)
Store (with Immutable)
Root Reducer (with Immutable)
Further Reading & Code
• https://facebook.github.io/immutable-js/

• https://thomastuts.com/blog/immutable-js-101-maps-
lists.html

• https://github/TinaHeiligers/findmemore

More Related Content

PPT
Collections
PPT
Collections
PPT
Ch15 Heap
PPT
PPT
Java Presentation
PPTX
Sorting
PDF
Lecture 01 variables scripts and operations
Collections
Collections
Ch15 Heap
Java Presentation
Sorting
Lecture 01 variables scripts and operations

What's hot (9)

PDF
Concept of Stream API Java 1.8
PDF
ODP
Java for newcomers
PDF
Introduction data structure
PDF
Java ArrayList Tutorial | Edureka
ODP
Collection advance
PPTX
Quick and Heap Sort with examples
PDF
Heapsort quick sort
PPTX
Intro to Akka Streams
Concept of Stream API Java 1.8
Java for newcomers
Introduction data structure
Java ArrayList Tutorial | Edureka
Collection advance
Quick and Heap Sort with examples
Heapsort quick sort
Intro to Akka Streams
Ad

Similar to Immutable js reactmeetup_local_ppt (20)

PDF
Immutability, and how to do it in JavaScripts
PDF
Building Functional Islands
PDF
Functional Web Development
PPTX
A Skeptics guide to functional style javascript
PDF
Modern Application Foundations: Underscore and Twitter Bootstrap
PDF
2018 02-22 React, Redux & Building Applications that Scale | Redux
PDF
Tech Talk - Immutable Data Structure
PPTX
Functional programming in javascript
PPTX
Functional programming with Immutable .JS
PDF
ES6: The future is now
PPTX
8558537werr.pptx
PDF
MCS First Year JavaScript ES6 Features.pdf
PPTX
Immutable Libraries for React
PDF
JSDC 2014 - functional java script, why or why not
PDF
Christian Gill ''Functional programming for the people''
PDF
Immutable, performance and components communication
PDF
Functional Programming for OO Programmers (part 2)
PDF
RxJS 5 in Depth
PDF
Web futures
PPTX
Thinking Functionally with JavaScript
Immutability, and how to do it in JavaScripts
Building Functional Islands
Functional Web Development
A Skeptics guide to functional style javascript
Modern Application Foundations: Underscore and Twitter Bootstrap
2018 02-22 React, Redux & Building Applications that Scale | Redux
Tech Talk - Immutable Data Structure
Functional programming in javascript
Functional programming with Immutable .JS
ES6: The future is now
8558537werr.pptx
MCS First Year JavaScript ES6 Features.pdf
Immutable Libraries for React
JSDC 2014 - functional java script, why or why not
Christian Gill ''Functional programming for the people''
Immutable, performance and components communication
Functional Programming for OO Programmers (part 2)
RxJS 5 in Depth
Web futures
Thinking Functionally with JavaScript
Ad

Recently uploaded (20)

PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Construction Project Organization Group 2.pptx
PPTX
Sustainable Sites - Green Building Construction
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPT
introduction to datamining and warehousing
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
DOCX
573137875-Attendance-Management-System-original
PPT
Project quality management in manufacturing
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
Current and future trends in Computer Vision.pptx
PPT
Mechanical Engineering MATERIALS Selection
PDF
Digital Logic Computer Design lecture notes
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
Artificial Intelligence
PPTX
OOP with Java - Java Introduction (Basics)
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Construction Project Organization Group 2.pptx
Sustainable Sites - Green Building Construction
CYBER-CRIMES AND SECURITY A guide to understanding
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
introduction to datamining and warehousing
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
573137875-Attendance-Management-System-original
Project quality management in manufacturing
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Current and future trends in Computer Vision.pptx
Mechanical Engineering MATERIALS Selection
Digital Logic Computer Design lecture notes
R24 SURVEYING LAB MANUAL for civil enggi
Artificial Intelligence
OOP with Java - Java Introduction (Basics)

Immutable js reactmeetup_local_ppt