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変換@社内RxSwift勉強会
Search
ukitaka
July 18, 2016
Programming
4
830
今日こそ理解するHot変換@社内RxSwift勉強会
今日こそ理解するHot変換
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
180
SwiftのDemanglerを書く @ わいわいswiftc番外編
ukitaka
0
420
Swiftの型システムに入門する - iOSDC Japan 2018
ukitaka
10
6.6k
Responder Chainを使って コードをスッキリさせたい - 第1回 HAKATA.swift
ukitaka
6
1.3k
理論から入門するswift/lib/Sema - わいわいswiftc #1
ukitaka
5
1.6k
Realmの処理を再利用可能かつ合成可能にする
ukitaka
0
890
マルチスレッドRxSwift @ 社内RxSwift勉強会
ukitaka
5
1.2k
今日こそ理解するHot / Cold @社内RxSwift勉強会
ukitaka
14
2.6k
Other Decks in Programming
See All in Programming
Webエンジニア主体のモバイルチームの 生産性を高く保つためにやったこと
igreenwood
0
330
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
180
testcontainers のススメ
sgash708
1
120
バグを見つけた?それAppleに直してもらおう!
uetyo
0
170
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
270
Haze - Real time background blurring
chrisbanes
1
510
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
210
【re:Growth 2024】 Aurora DSQL をちゃんと話します!
maroon1st
0
770
競技プログラミングへのお誘い@阪大BOOSTセミナー
kotamanegi
0
350
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
450
Recoilを剥がしている話
kirik
5
6.6k
Featured
See All Featured
Designing Experiences People Love
moore
138
23k
YesSQL, Process and Tooling at Scale
rocio
169
14k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Docker and Python
trallard
42
3.1k
Typedesign – Prime Four
hannesfritz
40
2.4k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
KATA
mclloyd
29
14k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
Become a Pro
speakerdeck
PRO
26
5k
Practical Orchestrator
shlominoach
186
10k
Transcript
ࠓͦ͜ཧղ͢Δ Hotม @ࣾRxSwiftษڧձ
https://speakerdeck.com/ukitaka/cold-at-she-nei-rxswiftmian-qiang-hui લճͷଓ͖
Hotม
Cold → Hot
(෮श)Hotʹؔ࿈͢ΔΦϖϨʔλ Hotʹؔ࿈͢ΔΦϖϨʔλҎԼͷΈɻ ͜ΕΒ͕ಛʹݺΕͯͳ͚ΕHotʹม͞ΕΔ͜ͱͳ͍ɻ • multicast / publish • replay /
replayAll • connect / refCount • share / shareReplay • shareReplayLatestWhileConnected
·͊ͱΓ͋͑ͣͬͯΈΔ͔
publish()
Question1 ͳΜͱදࣔ͞ΕΔͰ͠ΐ͏ʁ
None
͜Μͳͷ؆୯͡ΌΜʂ 1,2,3Ͱ͠ΐʂ
͜Μͳͷ؆୯͡ΌΜ Sequence Map Hot subscribe Քಇ
͜Μͳͷ؆୯͡ΌΜ Sequence Map Hot subscribe Քಇ
Answer ਖ਼ղ…
A. ͳʹදࣔ͞Εͳ͍
!?
(෮श)Hotʹؔ࿈͢ΔΦϖϨʔλ Hotʹؔ࿈͢ΔΦϖϨʔλҎԼͷΈɻ ͜ΕΒ͕ಛʹݺΕͯͳ͚ΕHotʹม͞ΕΔ͜ͱͳ͍ɻ • multicast / publish • replay /
replayAll • connect / refCount • share / shareReplay • shareReplayLatestWhileConnected ؚΈͷ͋Δݴ͍ํ
Hotม ϙΠϯτͦͷ1 ConnectableObservable
ͭ͡publish()ͷฦΓ…
ConnectableObservable • connect() ϝιουΛ࣋ͭ • connect() ΛݺͿ͜ͱͰHotʹมྃ͢Δ • connect() ΛݺͿ·ͰObserver͕͍Α͏͕͍
·͍͕ಈ࡞͠ͳ͍
ConnectableObservable
ͳΜͰඞཁͳͷʁ • ྫ͑ɺෳͷobserver͕Hotม͞Εͨετ ϦʔϜͷΛ࠷ॳ͔ΒͪΌΜͱड͚औΓ͍ͨ ࣌ɻconnect()ΛݺͿ·Ͱಈ࡞͠ͳ͍ͷͰɺͦ ͷؒʹશͯͷobserverΛsubscribe͓ͤͯ͘͞ ͜ͱ͕Ͱ͖Δɻ
ͳΜͰඞཁͳͷʁ (ConnectableObservable͕ແ͍ͱͲ͏ͳΔ͔ߟ͑ͯΈ͍ͯͩ͘͞)
ConnectableObservableΛฦ͢Operator • multicast() • publish() • replay(bufferSize:) • replayAll()
multicast() • ͦͦHotมͱɺ෦తʹSubjectΛར ༻͍ͯ͠Δ͚ͩͰ͋Δɻ • multicast()SubjectΛࢦఆͯͦ͜͠ͰҰ୴Π ϕϯτΛड͚ΔΑ͏ʹ͢ΔOperator
multicast()
publish() • PublishSubjectʹmulticast͢Δ
• ReplaySubjectʹmulticast͢Δ replay(bufferSize:) / replayAll()
ConnectableObservable·ͱΊ • ColdͳObservableʹରͯ͠ɺmulticast() / publish() / replay(bufferSize:) / replayAll() Λݺͼ
ग़͢͜ͱͰ ConnectableObservableʹมͰ͖ Δɻ • ConnectableObservableʹରͯ͠connect()Λݺͼ ग़͢͜ͱͰHotͳObservableʹม͕ྃ͢Δɻ
࣍…
ConnectableObservable ཧղͨ͠
ଞͷHotؔ࿈ͷOperatorʁ
(෮श)Hotʹؔ࿈͢ΔΦϖϨʔλ Hotʹؔ࿈͢ΔΦϖϨʔλҎԼͷΈɻ ͜ΕΒ͕ಛʹݺΕͯͳ͚ΕHotʹม͞ΕΔ͜ͱͳ͍ɻ • multicast / publish • replay /
replayAll • connect / refCount • share / shareReplay • shareReplayLatestWhileConnected
ͱΓ͋͑ͣshare()Ͱ ͬͯΈΔ͔
share() ConnectableObservable͡Όͳͯ͘ ObservableͰฦ͖ͬͯͯΔ͠ ͖ͬͱHotΖʂʂʂ
Question2 ͳΜͱදࣔ͞ΕΔͰ͠ΐ͏ʁ
None
Answer ਖ਼ղ…
A. ͳʹදࣔ͞Εͳ͍
ƅЧƅ)Űō?
Hotม ϙΠϯτͦͷ2 ۂऀ: RefCount
share()
refCount() • refCount() ConnectableObservableʹର͠ ͯݺΔ͏ҰͭͷOperatorͰ͋Δɻ
refCount() • Hotͷ֓೦Λ෴͢ΊΜͲ͍͘͞ศརͳͭ • Hotͷੑ࣭ͱͯ͠ʮsubscribe͠ͳͯ͘ಈ࡞ ͢Δʯͱ͍͏ͷ͕͋Δ͕ɺrefCount͕ڬ·Δ ͱʮHot͕ͩɺ࠷ॳʹsubscribe͞ΕΔ·Ͱಈ ࡞͠ͳ͍ʯΈ͍ͨͳڍಈʹͳΔɻ
refCount() • ࡞Γ୯७Ͱɺ࠷ॳʹsubscribe͞Εͨ࣌Ͱ ෦తʹconnect()ΛݺͿɻ
Question3 ͳΜͱදࣔ͞ΕΔͰ͠ΐ͏ʁ
None
Answer ਖ਼ղ…
A. 1,2,3
ͪΌΜͱHotม͞Εͯͨ (ͳΜͰʁʂͱࢥͬͨํલճͷεϥΠυΈͯΈ·͠ΐ͏)
ΓͷOperator
shareReplay(bufferSize:) • ໊લͷ௨Γɺshare + replay • share = publish +
refCount • shareReplay = publish + refCount + replay • ʮHot͕ͩɺ࠷ॳʹsubscribe͞ΕΔ·Ͱಈ࡞͠ͳ ͍ʯΛकΓͭͭࢦఆ͞Εͨݸ͚ͩΛreplay͢ Δ
shareReplay(bufferSize:) • ࣮ΊͬͪΌॏཁͰɺRxSwiftͷExampleͰΑ͘ʢʁʣ ΘΕ͍ͯΔɻ • มతʹѻ͍ͭͭɺ࠶ܭࢉͤ͞ͳ͍Α͏ʹ͢Δͱ͖ʹ shareReplay(1)Λ͚ͭΔͱΑ͍ (͜Εʹ͍ͭͯผ్ൃද͠ ·͢ɻ) •
RxSwift v2.5.0࣌ͰshareReplayʹ1Ҏ֎Λ͢ͱ࠶ܭࢉ ͕Δόάʁ༷ʁ͕͋Δɻshareಉ༷ͷݱ༗Γɻ
shareReplayLatestWhileConnected() • ໊લ͕ΊͬͪΌ͍ • ͜Μͳͷ͏ػձ͋Δͷʁͱࢥ͏͔͠Εͳ͍͕ɺ RxSwift(RxCocoa)Ͱఏڙ͞Ε͍ͯΔ DriverσϑΥϧτͰ͜Εͱಉ ͡ڍಈΛ͢ΔɻͳͷͰڍಈཧղ͓͖ͯ͘͠ɻ • ShareReplay1
ͱͷҧ͍ɺconnect தͰͳ͍ͱ࠷ޙͷ͕औΕͳ͍ ͜ͱɻͭ·Γ1 .Completed ͕ྲྀΕͨΒͦͷ͋ͱʹreplay͞Ε ͣɺ.Completed ͔͠ྲྀΕͯ͜ͳ͍ɻ • ڍಈͷৄࡉͳྫDriverͷͱ͖ʹઆ໌͢ΔͷͰ͜͜ͰׂѪɻ
Hotม·ͱΊ Hotʹม͢Δʹ • ConnectableObservableʹมޙɺconnect() ΛݺͿ • RefCountʹରͯ͠1ͭҎ্subscribeΛߦ͏
Ҏ্ʂʂ