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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
250
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
500名弱規模の組織のPythonプロジェクト(dbt) をどう管理するか?
hiracky16
0
300
GopherCon @シアトル に行ってきました
logica0419
0
320
紙 to デジタル
ichien178
0
250
サービス内で複数のOP・ASを連鎖させる(OAuth/OIDC Numa (Immersion) Workshop 2026)
oidfj
PRO
0
320
アクセスキーが漏れた日にやるべきこと- 無効化の先にある本当の対応
kazzpapa3
0
340
Bill One 開発エンジニア 紹介資料
sansan33
PRO
7
20k
AWS Blocks が楽しい #ゆるWeb札幌
tacck
PRO
0
160
Digital Credentials API × OpenID4VP ブラウザ完結型本人確認の実装知見(OAuth/OIDC Numa (Immersion) Workshop 2026)
oidfj
PRO
0
300
【書籍出版記念】 10周回って、エージェント開発は RAGがすべてだった。〜RAGの歴史と開発現場で見えた実践知〜
akiratameto
21
8k
AWSとAzureのマルチクラウド活用における強い味方___AWS_Kiroを使った二刀流スキル作成.pdf
duelist2020jp
0
120
IHV like なユースケースへのOpenID Connect 関連仕様の適用事例
optim
0
320
Dylib Hijacking on macOS: Dead or Alive?
patrickwardle
0
120
Featured
See All Featured
Believing is Seeing
oripsolob
1
200
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
220
Technical Leadership for Architectural Decision Making
baasie
3
540
Context Engineering - Making Every Token Count
addyosmani
9
1.1k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
Marketing to machines
jonoalderson
1
5.7k
The Spectacular Lies of Maps
axbom
PRO
1
950
My Coaching Mixtape
mlcsv
0
290
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
290
Thoughts on Productivity
jonyablonski
76
5.3k
So, you think you're a good person
axbom
PRO
2
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