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
4.5k
Responder Chainを使って コードをスッキリさせたい - 第1回 HAKATA.swift
ukitaka
6
1.3k
理論から入門するswift/lib/Sema - わいわいswiftc #1
ukitaka
5
1.5k
Realmの処理を再利用可能かつ合成可能にする
ukitaka
0
870
マルチスレッドRxSwift @ 社内RxSwift勉強会
ukitaka
5
1.1k
RxSwift コードリーディングの勘所@社内RxSwift勉強会
ukitaka
3
970
Other Decks in Programming
See All in Programming
What we keep in mind when migrating from Serverless Framework to AWS CDK and AWS SAM
kasacchiful
1
130
Ruby Parser progress report 2024
yui_knk
2
190
LangChainの現在とv0.3にむけて
os1ma
4
770
1人で挑むSwiftコンパイラ 〜型システム入門編〜
s_shimotori
0
320
Playwrightから始めるVisual Regression Testingのススメ by とっと
totto2727
2
1.8k
Prompt Cachingは本当に効果的なのか検証してみた.pdf
ttnyt8701
0
500
Mergeable Libraryで 高速なアプリ起動を実現しよう!
giginet
PRO
1
2.2k
Desafios e Lições Aprendidas na Migração de Monólitos para Microsserviços em Java
jessilyneh
2
140
Method Swizzlingを行うライブラリにおけるマルチモジュール設計
yoshikma
0
110
LangChainでWebサイトの内容取得やGitHubソースコード取得
shukob
0
140
Rubyのobject_id
qnighy
6
1.3k
Rustではじめる負荷試験
skanehira
5
1.2k
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
663
120k
It's Worth the Effort
3n
182
27k
Git: the NoSQL Database
bkeepers
PRO
425
64k
Embracing the Ebb and Flow
colly
83
4.4k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
42
2k
Raft: Consensus for Rubyists
vanstee
135
6.5k
Docker and Python
trallard
39
3k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3.4k
Happy Clients
brianwarren
96
6.6k
Making Projects Easy
brettharned
113
5.8k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
26
1.9k
Producing Creativity
orderedlist
PRO
340
39k
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มʹ͍ͭͯผ్ղઆ͠·͢ɻ