Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Practically Immutable
Search
sporto
March 28, 2015
Technology
210
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Practically Immutable
Immutable data in practice in JavaScript
sporto
March 28, 2015
More Decks by sporto
See All by sporto
React inside Elm
sporto
2
200
Elm
sporto
1
290
Redux: Flux Reduced
sporto
1
380
Webpack and React
sporto
4
410
Rails with Webpack
sporto
1
240
Lesson learnt building Single Page Application
sporto
0
150
Grunt
sporto
1
210
Safe Testing in Ruby
sporto
1
150
Go - A great language for building web applications
sporto
1
360
Other Decks in Technology
See All in Technology
【CEDEC2026】専門性の高いデフォルメチームが挑んだ人材育成戦略 〜Cygames Academiaの企画から実施まで〜
cygames
PRO
0
500
JavaScript 研修 (2026)
recruitengineers
PRO
1
370
SnowflakeCoCoでデータエンジニアリング!
foursue
0
180
FORENSIA: ローカルLLMフォレンジックハーネス
sumeshi
2
230
もう一度考える SRE チームの作り方・育て方 / Rethinking SRE #1: Building and Growing SRE Teams
rrreeeyyy
6
1k
Data Hubグループ 紹介資料
sansan33
PRO
0
3.1k
名古屋の市バスGTFS-JPデータ×スガキヤ 最寄りバス停検索をAmazon ElastiCache Serverless for Valkeyで最適化する
usanchuu
1
370
AIエージェントを前提としたプラットフォーム エンジニアリング:GKEで作るAgent-Ready Golden Path
legalontechnologies
PRO
1
210
サイバー捜査員研修(前半)
nomizone
1
1.8k
20260801_スクフェス大阪
kgnkhkr
2
1.2k
Service Connect 上のサービスに ECS Service の外側から到達できなかった話
ota1022
1
130
研究開発部の紹介 / Sansan R&D Profile
sansan33
PRO
4
24k
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Leo the Paperboy
mayatellez
8
2.1k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
440
Design in an AI World
tapps
1
270
sira's awesome portfolio website redesign presentation
elsirapls
0
320
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
How to make the Groovebox
asonas
2
2.3k
Being A Developer After 40
akosma
91
590k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
Transcript
practically immutable ! Immutable data in JS @sebasporto
I build CRUD apps, mostly
What? • Something that cannot change • Once created stays
the same
var array1 = [1, 2].immutable var array2 = array1.push(3) !
array1 //=> [1, 2] array2 //=> [1, 2, 3]
WHY?
# 1 no side effects
var orders = [1, 2]; processOrders(orders); what is orders after
this?
Predictability Store Comp Comp Data Data wants to sort data
wants to transform data doesn't want its data to be modified externally
Enforces uni directional data flow React + Flux Store Comp
Action
# 2 Easier workflows
Undo add(item) { history.push(items) items = items.push(item) } undo() {
items = history.pop() }
Dirty objects Get record from store Clone record Edit record
Save Replace original Yes Discard No
Dirty objects Get record from store Edit record Save Replace
original Yes Discard No
HOW?
clojurescript immutable data for free but this talk is about
plain JS
• In JS strings and numbers are immutable (not the
case in every language) • Arrays, objects are not - so we need help here • JS and immutable data => opposing forces
immutable.js • Great for simple collections • [1, 2, ...]
['a', 'b' ...] • Caveats for collections with objects https://github.com/facebook/immutable-js
Immutable.js var record = {label: 'Sam'}; var list = Immutable.List([record]);
! console.log(list.get(0).label) // => 'Sam' http://jsbin.com/dilupu/1/embed?js,console record.label = 'Biff' ! console.log(list.get(0).label) // => 'Biff' Opps!
immutable.js To be fair: Immutable.js can do the right thing
if you learn it really well Immutable.js != Just works™
Seamless immutable • Fixes Immutable.js issues with deep objects https://github.com/rtfeldman/seamless-immutable
var record = {label: 'Sam'}; var list = Immutable([record]); !
console.log(list[0].label) // => 'Sam' ! record.label = 'Biff' ! console.log(list[0].label) // => 'Sam' http://jsbin.com/fayupu/1/edit?js,console Seamless immutable
imm https://github.com/sporto/imm • Build on top of seamless-immutable • Nice
CRUD API
imm list = list.add(record) list = list.replace(record) list = list.remove(id)
! record = list.get(id)
in Conclusion
Immutable data can make your application more robust
but play a lot with your chosen lib, understand
the caveats
Thanks