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
200
0
Share
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
190
Elm
sporto
1
270
Redux: Flux Reduced
sporto
1
370
Webpack and React
sporto
4
400
Rails with Webpack
sporto
1
230
Lesson learnt building Single Page Application
sporto
0
140
Grunt
sporto
1
200
Safe Testing in Ruby
sporto
1
140
Go - A great language for building web applications
sporto
1
350
Other Decks in Technology
See All in Technology
NOSTR, réseau social et espace de liberté décentralisé
rlifchitz
0
200
Introduction to Sansan Meishi Maker Development Engineer
sansan33
PRO
0
390
"SQLは書けません"から始まる データドリブン
kubell_hr
2
460
え!?初参加で 300冊以上 も頒布!? これは大成功!そのはずなのに わいの財布は 赤字 の件
hellohazime
0
150
ハーネスエンジニアリングをやりすぎた話 ~そのハーネスは解体された~
gotalab555
0
300
All About Sansan – for New Global Engineers
sansan33
PRO
1
1.4k
AIエージェントの権限管理 1: MCPサーバー・ツールの Fine grained access control 編
ren8k
3
480
自分のハンドルは自分で握れ! ― 自分のケイパビリティを増やし、メンバーのケイパビリティ獲得を支援する ― / Take the wheel yourself
takaking22
1
830
DevOpsDays Tokyo 2026 軽量な仕様書と新たなDORA AI ケイパビリティで実現する、動くソフトウェアを中心とした開発ライフサイクル / DevOpsDays Tokyo 2026
n11sh1
0
150
AIエージェントを構築して感じた、AI時代のCDKとの向き合い方
smt7174
1
260
AWS DevOps Agentはチームメイトになれるのか?/ Can AWS DevOps Agent become a teammate
kinunori
6
660
Azure Lifecycle with Copilot CLI
torumakabe
3
990
Featured
See All Featured
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.1k
The SEO identity crisis: Don't let AI make you average
varn
0
440
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
200
AI: The stuff that nobody shows you
jnunemaker
PRO
6
560
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
770
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
WENDY [Excerpt]
tessaabrams
10
37k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
160
So, you think you're a good person
axbom
PRO
2
2k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
330
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
250
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