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
役立つログに取り組もう
irof
28
9.6k
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
970
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
230
watsonx.ai Dojo #4 生成AIを使ったアプリ開発、応用編
oniak3ibm
PRO
1
140
C++でシェーダを書く
fadis
6
4.1k
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
Macとオーディオ再生 2024/11/02
yusukeito
0
370
Figma Dev Modeで変わる!Flutterの開発体験
watanave
0
140
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Why Our Code Smells
bkeepers
PRO
334
57k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
Statistics for Hackers
jakevdp
796
220k
The Language of Interfaces
destraynor
154
24k
A Tale of Four Properties
chriscoyier
156
23k
What's in a price? How to price your products and services
michaelherold
243
12k
Documentation Writing (for coders)
carmenintech
65
4.4k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
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Λߦ͏
Ҏ্ʂʂ