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.8k
今日こそ理解する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.8k
switchのexhaustiveness/redundancy チェック 理論と実装 わいわいswiftc #8 @ukitaka
ukitaka
0
200
SwiftのDemanglerを書く @ わいわいswiftc番外編
ukitaka
0
460
Swiftの型システムに入門する - iOSDC Japan 2018
ukitaka
10
7k
Responder Chainを使って コードをスッキリさせたい - 第1回 HAKATA.swift
ukitaka
6
1.4k
理論から入門するswift/lib/Sema - わいわいswiftc #1
ukitaka
5
1.7k
Realmの処理を再利用可能かつ合成可能にする
ukitaka
0
940
マルチスレッドRxSwift @ 社内RxSwift勉強会
ukitaka
5
1.2k
RxSwift コードリーディングの勘所@社内RxSwift勉強会
ukitaka
3
1.1k
Other Decks in Programming
See All in Programming
ワープロって実は計算機で
pepepper
2
1.4k
あなたとJIT, 今すぐアセンブ ル
sisshiki1969
1
720
学習を成果に繋げるための個人開発の考え方 〜 「学習のための個人開発」のすすめ / personal project for leaning
panda_program
1
110
TanStack DB ~状態管理の新しい考え方~
bmthd
2
320
自作OSでDOOMを動かしてみた
zakki0925224
1
1.4k
MLH State of the League: 2026 Season
theycallmeswift
0
160
コンテキストエンジニアリング Cursor編
kinopeee
1
700
Flutter로 Gemini와 MCP를 활용한 Agentic App 만들기 - 박제창 2025 I/O Extended Seoul
itsmedreamwalker
0
150
Jakarta EE Core Profile and Helidon - Speed, Simplicity, and AI Integration
ivargrimstad
0
180
【第4回】関東Kaggler会「Kaggleは執筆に役立つ」
mipypf
0
750
STUNMESH-go: Wireguard NAT穿隧工具的源起與介紹
tjjh89017
0
380
管你要 trace 什麼、bpftrace 用下去就對了 — COSCUP 2025
shunghsiyu
0
460
Featured
See All Featured
Unsuck your backbone
ammeep
671
58k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
890
How to train your dragon (web standard)
notwaldorf
96
6.2k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.6k
Reflections from 52 weeks, 52 projects
jeffersonlam
351
21k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
31
2.2k
Six Lessons from altMBA
skipperchong
28
4k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
The Cult of Friendly URLs
andyhume
79
6.5k
Mobile First: as difficult as doing things right
swwweet
223
9.9k
Rails Girls Zürich Keynote
gr2m
95
14k
Java REST API Framework Comparison - PWX 2021
mraible
33
8.8k
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มʹ͍ͭͯผ్ղઆ͠·͢ɻ