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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
sporto
March 28, 2015
Technology
0
200
Practically Immutable
Immutable data in practice in JavaScript
sporto
March 28, 2015
Tweet
Share
More Decks by sporto
See All by sporto
React inside Elm
sporto
2
180
Elm
sporto
1
260
Redux: Flux Reduced
sporto
1
360
Webpack and React
sporto
4
390
Rails with Webpack
sporto
1
220
Lesson learnt building Single Page Application
sporto
0
130
Grunt
sporto
1
190
Safe Testing in Ruby
sporto
1
130
Go - A great language for building web applications
sporto
1
340
Other Decks in Technology
See All in Technology
入社1ヶ月でデータパイプライン講座を作った話
waiwai2111
1
240
Bill One急成長の舞台裏 開発組織が直面した失敗と教訓
sansantech
PRO
1
290
2026年、サーバーレスの現在地 -「制約と戦う技術」から「当たり前の実行基盤」へ- /serverless2026
slsops
2
210
SREのプラクティスを用いた3領域同時 マネジメントへの挑戦 〜SRE・情シス・セキュリティを統合した チーム運営術〜
coconala_engineer
2
590
プロダクト成長を支える開発基盤とスケールに伴う課題
yuu26
4
1.3k
セキュリティ はじめの一歩
nikinusu
0
1.5k
Introduction to Bill One Development Engineer
sansan33
PRO
0
360
GCASアップデート(202510-202601)
techniczna
0
250
Agile Leadership Summit Keynote 2026
m_seki
1
410
モダンUIでフルサーバーレスなAIエージェントをAmplifyとCDKでサクッとデプロイしよう
minorun365
3
140
We Built for Predictability; The Workloads Didn’t Care
stahnma
0
130
10Xにおける品質保証活動の全体像と改善 #no_more_wait_for_test
nihonbuson
PRO
1
190
Featured
See All Featured
Docker and Python
trallard
47
3.7k
Claude Code のすすめ
schroneko
67
210k
Everyday Curiosity
cassininazir
0
130
Evolving SEO for Evolving Search Engines
ryanjones
0
120
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
96
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.7k
Building Applications with DynamoDB
mza
96
6.9k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
730
Measuring & Analyzing Core Web Vitals
bluesmoon
9
750
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
3.9k
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