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.6k
今日こそ理解する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.6k
switchのexhaustiveness/redundancy チェック 理論と実装 わいわいswiftc #8 @ukitaka
ukitaka
0
180
SwiftのDemanglerを書く @ わいわいswiftc番外編
ukitaka
0
410
Swiftの型システムに入門する - iOSDC Japan 2018
ukitaka
10
6.1k
Responder Chainを使って コードをスッキリさせたい - 第1回 HAKATA.swift
ukitaka
6
1.3k
理論から入門するswift/lib/Sema - わいわいswiftc #1
ukitaka
5
1.6k
Realmの処理を再利用可能かつ合成可能にする
ukitaka
0
880
マルチスレッドRxSwift @ 社内RxSwift勉強会
ukitaka
5
1.2k
RxSwift コードリーディングの勘所@社内RxSwift勉強会
ukitaka
3
1k
Other Decks in Programming
See All in Programming
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
140
初めてDefinitelyTypedにPRを出した話
syumai
0
400
Ethereum_.pdf
nekomatu
0
460
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
290
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
190
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
250
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
470
Click-free releases & the making of a CLI app
oheyadam
2
110
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1k
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
870
Featured
See All Featured
BBQ
matthewcrist
85
9.3k
For a Future-Friendly Web
brad_frost
175
9.4k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Documentation Writing (for coders)
carmenintech
65
4.4k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Side Projects
sachag
452
42k
Designing for Performance
lara
604
68k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Building Adaptive Systems
keathley
38
2.3k
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มʹ͍ͭͯผ్ղઆ͠·͢ɻ