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
Reactive way on Android
Search
WeRockStar
August 30, 2019
Programming
0
22
Reactive way on Android
Presentation at ReactiveX meetup first in Bangkok, Thailand
WeRockStar
August 30, 2019
Tweet
Share
More Decks by WeRockStar
See All by WeRockStar
Software Design & Architecture on my mind
werockstar
0
150
Kotlin in 2 Days
werockstar
0
27
Kotlin Testing for Android
werockstar
1
61
Modern Android Development
werockstar
0
100
Disrupt Innovation
werockstar
0
36
Kotlin 101#1
werockstar
0
95
Android Reactive Programming
werockstar
0
140
Mobile Automate Testing
werockstar
0
58
Other Decks in Programming
See All in Programming
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
380
技術的負債の正体を知って向き合う / Facing Technical Debt
irof
0
180
その面倒な作業、「Dart」にやらせませんか? Flutter開発者のための業務効率化
yordgenome03
1
130
iOSエンジニア向けの英語学習アプリを作る!
yukawashouhei
0
190
大規模アプリのDIフレームワーク刷新戦略 ~過去最大規模の並行開発を止めずにアプリ全体に導入するまで~
mot_techtalk
1
450
SwiftDataを使って10万件のデータを読み書きする
akidon0000
0
140
『毎日の移動』を支えるGoバックエンド内製開発
yutautsugi
2
250
コードとあなたと私の距離 / The Distance Between Code, You, and I
hiro_y
0
170
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
400
overlayPreferenceValue で実現する ピュア SwiftUI な AdMob ネイティブ広告
uhucream
0
180
PHPに関数型の魂を宿す〜PHP 8.5 で実現する堅牢なコードとは〜 #phpcon_hiroshima / phpcon-hiroshima-2025
shogogg
1
240
はじめてのDSPy - 言語モデルを『プロンプト』ではなく『プログラミング』するための仕組み
masahiro_nishimi
2
520
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
30
2.9k
The Power of CSS Pseudo Elements
geoffreycrofte
79
6k
[RailsConf 2023] Rails as a piece of cake
palkan
57
5.9k
We Have a Design System, Now What?
morganepeng
53
7.8k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.4k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4k
Become a Pro
speakerdeck
PRO
29
5.6k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
Embracing the Ebb and Flow
colly
88
4.9k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
115
20k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
Site-Speed That Sticks
csswizardry
12
900
Transcript
@werockstar @werockstar Kotchaphan Muangsan Software Developer @ODDS
@werockstar Interested - Fundamental - OOP, FP, RP - Design
Pattern, Refactoring - Software Design
medium.com/@werockstar
None
None
Reactively way on Android @werockstar
@werockstar The Land of Reactive
@werockstar
@werockstar Before we start I gonna sharing some story about
Rx on Mobile Development
@werockstar We know the first implementation of Rx is Rx.NET
@werockstar And which is the first mobile OS uses Rx?
@werockstar And Android RxJava RxKotlin RxBinding Agera iOS RxSwift ReactiveCocoa
ReactiveSwift
Solve the same problem with Rx
@werockstar Zero to One Basic Rx on UI
@werockstar 'io.reactivex.rxjava2:rxjava:2.2.11' 'io.reactivex.rxjava2:rxkotlin:2.4.0' 'com.jakewharton.rxbinding3:rxbinding-core:3.0.0'
@werockstar click click click click
@werockstar click click click click click Time
@werockstar button.clicks() .subscribe() click click click click Button as an
producer(observable) Emitter of event() value over time Time
@werockstar button.clicks() .subscribe( { data -> println(data) }, { error
-> } ) Observer or subscriber Observer doesn't know anything about the data come from and when, or how many times
@werockstar button.clicks() .subscribe( { data -> println(data) }, { error
-> } ) Why <- Producer (Observable) <- Observer
@werockstar .subscribe( { data -> println(data) }, { error ->
} ) button.clicks() Why Decoupling the relationship Know little about each other
@werockstar click click click click Duplicate pages?
@werockstar button.clicks() .debounce(150, MILLISECONDS) .subscribe()
@werockstar click click click debounce(150, MILLISECONDS) 150 ms 150 ms
150 ms ✅
@werockstar Auto search editText.afterTextChangeEvents() .debounce(150, MILLISECONDS) .subscribe()
@werockstar editText.afterTextChangeEvents() .debounce(150, MILLISECONDS) .subscribe() A A B “A” and
“A” are duplicates?
@werockstar editText.afterTextChangeEvents() .debounce(150, MILLISECONDS) .distinctUntilChanged() ✅ .subscribe() A A B
“A” and “A” are duplicates?
@werockstar Sample Window Buffer Throttle
@werockstar ————
@werockstar
@werockstar A A B API?
@werockstar editText.afterTextChangeEvents() .debounce(200, MILLISECONDS) .distinctUntilChanged() .flatMap { api.getResult(it) } .subscribe()
A A B
@werockstar A A B API
@werockstar
@werockstar editText.afterTextChangeEvents() .debounce(200, MILLISECONDS) .distinctUntilChanged() .map { it.editable.toString() } .switchMap
{ api.getResult(it) } .subscribe() A A B
@werockstar Retry Patterns
@werockstar editText.afterTextChangeEvents() .debounce(200, MILLISECONDS) .distinctUntilChanged() .map { it.editable.toString() } .switchMap
{ api.getResult(it) } .subscribe() A A B ก้าวแรกไม่เป็นไร ก้าวต่อไปไฟเริ่มไหม้ getResult
@werockstar editText.afterTextChangeEvents() .debounce(200, TimeUnit.MILLISECONDS) .distinctUntilChanged() .map { it.editable.toString() } .switchMap
{ api.getResult(it) .retry(2) } .subscribe() A A B ✅
@werockstar But We shouldn't use retry in every situation
@werockstar editText.afterTextChangeEvents() .debounce(200, TimeUnit.MILLISECONDS) .distinctUntilChanged() .map { it.editable.toString() } .switchMap
{ api.getResult(it) .retry { attempt, throwable -> throwable is TimeoutException && attempt <= 2 } }.subscribe()
@werockstar editText.afterTextChangeEvents() .debounce(200, TimeUnit.MILLISECONDS) .distinctUntilChanged() .map { it.editable.toString() } .switchMap
{ api.getResult(it) .retry { attempt, throwable -> throwable is TimeoutException && attempt <= 2 } }.subscribe() .onErrorReturnItem("WeRockStar") ✅
@werockstar Reactively on precondition
@werockstar editText.afterTextChangeEvents() ... .switchMap { api.getResult(it) .retryWhen { it.flatMap {
throwable -> when (throwable.code()) { 401 -> api.getSomeToken("refresh_token") else -> Observable.error(throwable) } } } }.subscribe() 1 2
@werockstar And finally Delay error notification
@werockstar Observable.mergeDelayError( api.delete1(), api.delete2(), api.delete3() ).subscribe()
@werockstar And then
@werockstar Build in solutions
@werockstar Complex solution for complex problem
@werockstar Reactive Data Flow Back Pressure Flow Control Subject Push/Pull
Hot/Cold Messaging Responsive Elastic Publish/Subscribe Resilience Stream
@werockstar 80 Years of Life 5 ปีหมดไปการลองใช้ Rx 10 ปีหมดไปกับ
Observable 25 ปีหมดไปกับ FlatMap ส่วน 40 ปีที่เหลือหมดไปกับการทำความเข้าใจ และอธิบาย Reactive
@werockstar Questions and Answers @werockstar Thank you