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
5.7k
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
RxSwift コードリーディングの勘所@社内RxSwift勉強会
ukitaka
3
990
Other Decks in Programming
See All in Programming
Dev ContainersとGitHub Codespacesの素敵な関係
ymd65536
1
130
offers_20241022_imakiire.pdf
imakurusu
2
360
Realtime API 入門
riofujimon
0
110
GCCのプラグインを作る / I Made a GCC Plugin
shouth
1
150
開発効率向上のためのリファクタリングの一歩目の選択肢 ~コード分割~ / JJUG CCC 2024 Fall
ryounasso
0
360
Golang と Erlang
taiyow
8
1.9k
CPython 인터프리터 구조 파헤치기 - PyCon Korea 24
kennethanceyer
0
240
カスタムしながら理解するGraphQL Connection
yanagii
1
1.2k
Amazon Neptuneで始めてみるグラフDB-OpenSearchによるグラフの全文検索-
satoshi256kbyte
4
320
プロジェクト新規参入者のリードタイム短縮の観点から見る、品質の高いコードとアーキテクチャを保つメリット
d_endo
1
1k
生成 AI を活用した toitta 切片分類機能の裏側 / Inside toitta's AI-Based Factoid Clustering
pokutuna
0
570
RailsのPull requestsのレビューの時に私が考えていること
yahonda
5
1.7k
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
231
17k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Happy Clients
brianwarren
97
6.7k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
StorybookのUI Testing Handbookを読んだ
zakiyama
26
5.2k
Agile that works and the tools we love
rasmusluckow
327
21k
How GitHub (no longer) Works
holman
311
140k
Six Lessons from altMBA
skipperchong
26
3.5k
Designing for Performance
lara
604
68k
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มʹ͍ͭͯผ్ղઆ͠·͢ɻ