Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Practically Immutable
Search
sporto
March 28, 2015
Technology
220
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
210
Elm
sporto
1
300
Redux: Flux Reduced
sporto
1
390
Webpack and React
sporto
4
420
Rails with Webpack
sporto
1
260
Lesson learnt building Single Page Application
sporto
0
160
Grunt
sporto
1
230
Safe Testing in Ruby
sporto
1
160
Go - A great language for building web applications
sporto
1
370
Other Decks in Technology
See All in Technology
今から始めるAWS環境の暗号移行 - ポスト量子時代に備える
sato4mi
0
150
新米を「売り越さない」、Aurora DSQLで作る在庫ゼロ死守の限定ドロップEC
yama3133
0
180
[General] 개발자로 해외 기업에서 일하기
skydoves
1
300
セキュリティ専任チームなしで攻撃を先回りするSREが実践したSIEM on Amazon OpenSearch Service
cscengineer
PRO
0
250
慶應義塾大学 AI実践05 論文執筆の仕組み化
keio_smilab
PRO
6
3.7k
`go get`したらELFが降ってきた件
taiyow
0
170
You Have Agency(サンキュー、Ruby)
snoozer05
PRO
5
680
Content Mapper APIの応用例~CSS Modules、言語ファイル~
uhyo
2
600
サボる子はいねぇがー!AgentCoreハーネスの脆弱性に学ぶ、エージェントの入力バリデーション
iwamot
PRO
4
240
Copilot Coworkで「みのるん式」やってみた
minorun365
PRO
2
1.5k
令和の今、あらためて IAM を考える。アクセスキーを「無くせない現実」との向き合い方
kazzpapa3
0
190
re:Invent2026 事前勉強会 歴史と愉しみ方10分LT編
toshi_atsumi
0
130
Featured
See All Featured
My Coaching Mixtape
mlcsv
0
380
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
610
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
3.7k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1.1k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
830
The Mindset for Success: Future Career Progression
greggifford
PRO
0
560
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
630
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
480
Product Roadmaps are Hard
iamctodd
55
13k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.6k
Designing for Timeless Needs
cassininazir
1
550
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