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
今日こそ理解するHot / Cold @社内RxSwift勉強会
Search
ukitaka
July 18, 2016
Programming
14
2.7k
今日こそ理解するHot / Cold @社内RxSwift勉強会
ukitaka
July 18, 2016
Tweet
Share
More Decks by ukitaka
See All by ukitaka
CSの生産性改善を支える分析環境 Mercari CS/CRE Tech Talk #1
ukitaka
1
2.7k
switchのexhaustiveness/redundancy チェック 理論と実装 わいわいswiftc #8 @ukitaka
ukitaka
0
190
SwiftのDemanglerを書く @ わいわいswiftc番外編
ukitaka
0
430
Swiftの型システムに入門する - iOSDC Japan 2018
ukitaka
10
6.7k
Responder Chainを使って コードをスッキリさせたい - 第1回 HAKATA.swift
ukitaka
6
1.4k
理論から入門するswift/lib/Sema - わいわいswiftc #1
ukitaka
5
1.6k
Realmの処理を再利用可能かつ合成可能にする
ukitaka
0
890
マルチスレッドRxSwift @ 社内RxSwift勉強会
ukitaka
5
1.2k
RxSwift コードリーディングの勘所@社内RxSwift勉強会
ukitaka
3
1k
Other Decks in Programming
See All in Programming
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
1.4k
ドメインイベント増えすぎ問題
h0r15h0
2
570
技術的負債と向き合うカイゼン活動を1年続けて分かった "持続可能" なプロダクト開発
yuichiro_serita
0
300
watsonx.ai Dojo #6 継続的なAIアプリ開発と展開
oniak3ibm
PRO
0
170
React 19でお手軽にCSS-in-JSを自作する
yukukotani
5
570
rails newと同時に型を書く
aki19035vc
5
710
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
420
20241217 競争力強化とビジネス価値創出への挑戦:モノタロウのシステムモダナイズ、開発組織の進化と今後の展望
monotaro
PRO
0
290
良いユニットテストを書こう
mototakatsu
11
3.6k
AHC041解説
terryu16
0
400
快速入門可觀測性
blueswen
0
500
Swiftコンパイラ超入門+async関数の仕組み
shiz
0
180
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
It's Worth the Effort
3n
183
28k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
Measuring & Analyzing Core Web Vitals
bluesmoon
5
210
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Building Your Own Lightsaber
phodgson
104
6.2k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
3
360
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Building an army of robots
kneath
302
45k
Transcript
ࠓͦ͜ཧղ͢Δ Hot / Cold @ࣾRxSwiftษڧձ
RxͰΈͳ࠷ॳʹͭ·ͮ͘ ϙΠϯτ
None
Hot / Cold
Hot / Cold • Hot / Cold Ή͔͍ͣ͠ • Hot
/ Cold Α͘Θ͔Βͳ͍ • Hot / Cold ཧղͰ͖ͳ͍ • Rxͦ͠͏… Rxා͍…
ࡾᵆ( ^o^)ᵒ
ࡾᵆ( ^o^)ᵒ ※ Bondྑ͍ϥΠϒϥϦͰ͢
͜ͷεϥΠυͰ • جຊతͳ֓೦Λཧղ্ͨ͠ͰɺHot / Cold Ͱ ৺͕ંΕͦ͏ʹͳͬͨํΛλʔήοτʹͯ͠ ΔͷͰɺ͋ΔఔͷRxSwiftͷཧղΛඞཁͱ͠ ·͢ɻ
͜ͷεϥΠυͰ • ·ͨHotมʹ͍ͭͯ͘ͳΔͷͰผͷػձ ʹઆ໌͠·͢ɻ • ͱΓ͋͑ͣ Hot / Cold ͷੑ࣭ʹͯ͠આ໌
͠·͢ɻ
͜ͷεϥΠυͰ • ྫ (ΫΠζ) Λग़͠ͳ͕ΒHot / Cold ͦΕͧΕ ͕ͲΜͳੑ࣭Λ͍࣋ͬͯΔͷ͔֬ೝ͍͖ͯ͠ ·͢ɻ
• ·ͩͦΕͧΕͷੑ࣭ҧ͍Λઆ໌͍ͯ͠ͳ͍ ͷͰ͕͢ɺ͋ͱͰઆ໌͘͢͢͠ΔͨΊʹ࠷ ॳʹʮલఏࣝʯͱʮݟ͚ํʯͷϧʔϧΛ આ໌͠·͢ɻ
લఏࣝ
લఏࣝ ͦͷ1 Hot / Cold ʮObservableʯͷੑ࣭
ͳʹΛͨΓલͷࣄΛ ݴ͍ͬͯΔΜͩίΠπ
͡Ό͋ͳʹ͕Observable͔
͡Ό͋ͳʹ͕Observable͔ • Subject • PublishSubject, BehaviorSubject, ReplaySubject …
͡Ό͋ͳʹ͕Observable͔ • Subject • PublishSubject, BehaviorSubject, ReplaySubject … • Operator
• map, filter, flatMap … • create, of, just, error …
͡Ό͋ͳʹ͕Observable͔ • Subject • PublishSubject, BehaviorSubject, ReplaySubject … • Operator
← !? • map, filter, flatMap … • create, of, just, error …
લఏࣝ ͦͷ2 ֤छOperator (Λද͢Ϋϥε) ʮObservableʯͰ͋Δ
filter
filter ฦΓͷܕObservable
filter ࣮ଶfilter operatorΛද͢ Filterͱ͍͏Ϋϥε
just
just ฦΓͷܕObservable
just ࣮ଶJustͱ͍͏Ϋϥε
લఏࣝ·ͱΊ • Hot / Cold ʮObservableʯͷੑ࣭ • SubjectʮObservableʯ •
Operator (Λද͢Ϋϥε) ʮObservableʯ
Hot / Cold ͷ ݟ͚ํ
ݟ͚ํ ͦͷ1 SubjectHotͰ͋Δ
Subject • PublishSubject • BehaviorSubject • ReplaySubject ͜ΕΒHotͰ͋Δ
ݟ͚ํ ͦͷ2 ΄ͱΜͲͷOperator ColdͰ͋Δ
Hotʹؔ࿈͢ΔΦϖϨʔλ Hotʹؔ࿈͢ΔΦϖϨʔλҎԼͷΈɻ ͜ΕΒ͕ಛʹݺΕͯͳ͚ΕHotʹม͞ΕΔ͜ͱͳ͍ɻ • multicast / publish • replay /
replayAll • connect / refCount • share / shareReplay • shareReplayLatestWhileConnected
SubjectͳͷͰHot
Map OperatorCold
Filter OperatorCold
Subject Map Filter ↑ Α͘Έ͔͚Δਤ
ݟ͚ํ·ͱΊ • Subject Hot • Operator ΄ͱΜͲ͕ Cold • publishͳͲҰ෦ͷOperator
Hot (ʹؔ࿈)
ͰɺHot / Cold ͬͯͳʹʁ
͓·ͨͤ͠·ͨ͠ Hot / Coldͷੑ࣭
Question1 ͳΜͱදࣔ͞ΕΔͰ͠ΐ͏ʁ
None
Answer ਖ਼ղ…
A. ͳʹදࣔ͞Εͳ͍
Coldͷੑ࣭ ͦͷ1 ColdͳObservable subscribe͞ΕΔ·Ͱ ಈ࡞͠ͳ͍
Coldsubscribe͞ΕΔ·Ͱಈ࡞͠ͳ͍ Sequence
Coldsubscribe͞ΕΔ·Ͱಈ࡞͠ͳ͍ Sequence Map
Coldsubscribe͞ΕΔ·Ͱಈ࡞͠ͳ͍ ୭subscribe͍ͯ͠ͳ͍ → ಈ࡞͠ͳ͍
͡Ό͋subscribeͨ͠Βʁ
͡Ό͋subscribeͨ͠Βʁ
Hotͷੑ࣭ ͦͷ1 HotͳObservable subscribe͞Εͳͯ͘ ಈ࡞͢Δ ٯʹ
Question2 ͳΜͱදࣔ͞ΕΔͰ͠ΐ͏ʁ
None
Answer ਖ਼ղ…
A. ͳʹදࣔ͞Εͳ͍
ղઆ Subject Map
ղઆ Subject Map
• ಈ࡞͠ͳ͍ = ड͚औΔ͜ͱ͢Β͠ͳ͍ Coldsubscribe͞ΕΔ·Ͱಈ࡞͠ͳ͍ Subject Map SubjectΛྲྀ͢ ड͚औΒͳ͍
Question3 ͳΜͱදࣔ͞ΕΔͰ͠ΐ͏ʁ
None
Answer ਖ਼ղ…
A. 1, 2, 3
ղઆ Subject Map Hot
HotલͷColdΛՔಇͤ͞Δ ͱॻ͘ͱͦ͠͏͕ͩɺཁ HotͳObservableதͰsubscribeΛݺΜͰΔ͚ͩɻ Subject Map Hot subscribe Քಇ
͜͜·Ͱͷ·ͱΊ • Cold ͳObservablesubscribe͞ΕΔ·Ͱಈ࡞͠ͳ͍ • Hot ͳObservablesubscribe͞Εͳͯ͘ಈ࡞͢Δ • Hot ͳObservableલͷCold
ΛՔಇͤ͞Δ
Hot ͷ͏Ұͭେ͖ͳੑ࣭
Hotͷੑ࣭ ͦͷ2 HotͳObservable ذͰ͖Δ
Coldͷੑ࣭ ͦͷ2 ColdͳObservable ذͰ͖ͳ͍ ٯʹ
ذͰ͖Δͱʁ • ذͰ͖Δ = ObserverΛෳ࣋ͯΔ • Cold ͳObservableObserverΛ1͔ͭ࣋ͯ͠ͳ͍ • Hot
ͳObservableObserverΛෳ࣋ͯΔ ※ આ໌؆ུԽͷͨΊʹʮObserverʯͱ͍ͯ͠·͕͢ɺͪΖΜ͜͜· ͰͷྫͷΑ͏ʹذޙʹObservableΛͭͳ͛ͯߦ͘͜ͱͰ͖·͢ɻ
͑ʁෳ࣋ͯͳ͍ͷʁ
͑ʁෳ࣋ͯͳ͍ͷʁ
͑ʁෳ࣋ͯͳ͍ͷʁ ͳΜ͔Ͱ͖ͦ͏ͳงғؾ͋Δ͚Ͳʁʁʁ
Sequence Map
Sequence Map Observer 1ͭΊ͕subscribe
Sequence Map Observer Map Observer 2ͭΊsubscribe͍͚ͨ͠Ͳ ͢Ͱʹ1ͭ͞ΕͯΔ…
Sequence Map Observer Map Observer
Sequence Map Observer Sequence Map Observer
Sequence Map Observer Sequence Map Observer ετϦʔϜ͕2ຊʹ !!
ͦͷ݁ՌͲ͏ͳΔ͔
ͦͷ݁ՌͲ͏ͳΔ͔
ͦͷ݁ՌͲ͏ͳΔ͔ Sequence Map Observer Sequence Map Observer 2ετϦʔϜग़ྗ͞ΕΔ
Hotͷ߹ Hotʹ͢Δ(·ͩಈ࡞͠ͳ͍) (ৄࡉHotมͷͱ͖ʹઆ໌)
Hotͷ߹
Hotͷ߹ ͜͜ͰετϦʔϜ։࢝ (ৄࡉHotมͷͱ͖ʹઆ໌)
Hotͷ߹ Sequence Map Hot
Hotͷ߹ Sequence Map Hot Observer 1ͭΊ͕subscribe
Hotͷ߹ Sequence Map Hot Observer Observer 2ͭΊsubscribe
Hotͷ߹ Sequence Map Observer Hot Observer
Hotͷ߹ Sequence Map Observer Hot Observer ذ !!!
ͦͷ݁ՌͲ͏ͳΔ͔
ͦͷ݁ՌͲ͏ͳΔ͔
ͦͷ݁ՌͲ͏ͳΔ͔ Sequence Map Observer Hot Observer Ұճ͔͠print͞Εͳ͍
͜͜·Ͱͷ·ͱΊ • Cold ͳObservableذͰ͖ͳ͍ • Hot ͳObservableذͰ͖Δ
Hot ͷ࠷ޙͷੑ࣭
Question4 ͳΜͱදࣔ͞ΕΔͰ͠ΐ͏ʁ
͜͜ͰετϦʔϜ։࢝ (ৄࡉHotมͷͱ͖ʹઆ໌) Hotʹ͢Δ(·ͩಈ࡞͠ͳ͍)
Answer ਖ਼ղ…
A. 2, 4, 6
͋Εʁ 2ճsubscribeͯ͠Δͷʹʁ
Hotͷੑ࣭ ͦͷ3 HotͳObservableͷΠϕϯτ ֤ObserverͰڞ༗͞ΕΔ
͢ΔͱͲ͏ͳΔ͔ • ֤Observerʹରͯ͠ಉ͡Πϕϯτ͕ૹग़͞ΕΔɻͭ· Γͦ͜·ͰͷColdԿݺΕͳ͍ɻ(ذͷੑ࣭ ͱ͜ΖͰ֬ೝࡁΈ) • ͢ͰʹྲྀΕͨΠϕϯτ(Next)ૹग़͞Εͳ͍ɻͭ·Γ ్த͔Βsubscribe͢Δͱ్த͔Β͔͠ड͚औΕͳ͍ɻ
ղઆ ετϦʔϜՔಇ։࢝࣌Ͱ observer1ͭ
ղઆ 2,4,6 ͕දࣔ͞ΕΔ
ղઆ ͜͜ʹࢸͬͨ࣌ͰશͯͷNext͢Ͱʹૹग़ࡁΈɻ ࠶ྲྀΕΔ͜ͱͳ͍ɻ
ղઆ Αͬͯɺͳʹදࣔ͞Εͳ͍
ղઆ
͡Ό͋Coldͷ߹ʁ
͡Ό͋Coldͷ߹ʁ Sequence Map Observer Sequence Map Observer
͡Ό͋Coldͷ߹ʁ ͢Ͱʹղઆͨ͠௨ΓɺετϦʔϜࣗମ͕2ͭʹͳΔɻ ͳͷͰɺ྆ํͷObserverͰ࠷ॳͷΠϕϯτ͔Βͯ͢ ड͚औΔ͜ͱ͕Ͱ͖Δɻ Sequence Map Observer Sequence Map Observer
͡Ό͋Coldͷ߹ʁ
ੑ࣭·ͱΊ
Coldͷੑ࣭ ͦͷ1 ColdͳObservable subscribe͞ΕΔ·Ͱ ಈ࡞͠ͳ͍
Hotͷੑ࣭ ͦͷ1 HotͳObservable subscribe͞Εͳͯ͘ ಈ࡞͢Δ ٯʹ
Hotͷੑ࣭ ͦͷ2 HotͳObservable ذͰ͖Δ
Coldͷੑ࣭ ͦͷ2 ColdͳObservable ذͰ͖ͳ͍ ٯʹ
Hotͷੑ࣭ ͦͷ3 HotͳObservableͷΠϕϯτ ֤ObserverͰڞ༗͞ΕΔ
Ҏ্ʂ
࠷ޙʹ • ͜͜·Ͱઆ໌ͨ͠ͷ͋͘·Ͱ֓೦తͳ Ͱ͢ɻͲ͜Ͱͳʹ͕ى͍ͬͯ͜Δ͔ΛͪΌΜ ͱཧղ͢ΔʹɺΓ࣮Λ͕Μͬͯಡ ΜͰ͍ͩ͘͞ɻ(ίʔυϦʔσΟϯάͷצॴ ผ్ൃද͠·͢ɻ) • Hotมʹ͍ͭͯผ్ղઆ͠·͢ɻ