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
820
今日こそ理解する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.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
今日こそ理解するHot / Cold @社内RxSwift勉強会
ukitaka
14
2.6k
Other Decks in Programming
See All in Programming
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
RubyLSPのマルチバイト文字対応
notfounds
0
120
距離関数を極める! / SESSIONS 2024
gam0022
0
280
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
Better Code Design in PHP
afilina
PRO
0
120
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
600
初めてDefinitelyTypedにPRを出した話
syumai
0
400
みんなでプロポーザルを書いてみた
yuriko1211
0
260
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
The Invisible Side of Design
smashingmag
298
50k
Being A Developer After 40
akosma
86
590k
4 Signs Your Business is Dying
shpigford
180
21k
Optimizing for Happiness
mojombo
376
70k
Code Review Best Practice
trishagee
64
17k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
Fireside Chat
paigeccino
34
3k
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Λߦ͏
Ҏ্ʂʂ