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
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
190
テストコード書いてみませんか?
onopon
2
110
nekko cloudにおけるProxmox VE利用事例
irumaru
3
430
暇に任せてProxmoxコンソール 作ってみました
karugamo
2
720
テストコード文化を0から作り、変化し続けた組織
kazatohiei
2
1.5k
Effective Signals in Angular 19+: Rules and Helpers @ngbe2024
manfredsteyer
PRO
0
140
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
760
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
400
CSC305 Lecture 26
javiergs
PRO
0
140
RWC 2024 DICOM & ISO/IEC 2022
m_seki
0
210
採用事例の少ないSvelteを選んだ理由と それを正解にするためにやっていること
oekazuma
2
1k
선언형 UI에서의 상태관리
l2hyunwoo
0
160
Featured
See All Featured
Designing for humans not robots
tammielis
250
25k
Statistics for Hackers
jakevdp
796
220k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
How to Think Like a Performance Engineer
csswizardry
22
1.2k
Imperfection Machines: The Place of Print at Facebook
scottboms
266
13k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
The Cost Of JavaScript in 2023
addyosmani
45
7k
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Λߦ͏
Ҏ্ʂʂ