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
RxJava1からRxJava2へ
Search
Yasuhiro Shimizu
October 03, 2017
Programming
110
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RxJava1からRxJava2へ
Yasuhiro Shimizu
October 03, 2017
More Decks by Yasuhiro Shimizu
See All by Yasuhiro Shimizu
Jetpack Composeから始める、頑張らないVRT
yshrsmz
0
1.3k
Kotlin Multiplatform Projectを導入してみて
yshrsmz
1
1.2k
BIP39について
yshrsmz
0
210
Android Fireside Chatまとめ
yshrsmz
3
2.4k
Other Decks in Programming
See All in Programming
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
750
FDEが実現するAI駆動経営の現在地
gonta
2
280
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
620
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
710
生成AIで帳票OCRが「簡単に」作れる時代になった?
kon_shou
0
1k
Jindong: Introducing Declarative Haptics in Compose Multiplatform
l2hyunwoo
0
120
How I Won Prize Money at a Hackathon Using Codex and Symphony Alpha
yasei_no_otoko
0
100
VibeCodingからAgenticWorkflowへ
starfish719
0
560
ソフトウェアエンジニアにとっての生成AI - 特性を知って使い倒す / generative ai for software enginner
kishida
5
1.8k
引き算の組織 ― アウトカムとAIに全振りするために辞めたこと ― / Organization by Subtraction
hirokiyamamoto14
PRO
0
160
PHP に部分適用が来るぞ!……ところで何それ?おいしいの? #phpcon / phpcon-2026
shogogg
0
680
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
200
Featured
See All Featured
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
3
440
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.5k
Designing for Performance
lara
611
70k
How GitHub (no longer) Works
holman
316
150k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
470
How to train your dragon (web standard)
notwaldorf
97
6.8k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
340
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
410
Designing Experiences People Love
moore
143
24k
Google's AI Overviews - The New Search
badams
0
1.1k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.2k
Transcript
RxJava1 -> RxJava2 CA.APK - YASUHIRO SHIMIZU
ABOUT ME 清水泰博(Yasuhiro Shimizu) ▸ Android Engineer @AWA Co. Ltd.
▸ GitHub: yshrsmz ▸ Twitter: _yshrsmz Omnitweety Monotweety
MIGRATING TO RXJAVA2 今日話すこと ▸ 開発を止めずRxJava2に 徐々に移行するにはどうしたらいいか ▸ AWAの場合
MIGRATING TO RXJAVA2 今日話さないこと ▸ RxJavaとは何か ▸ RxJava1とRxJava2の違い
MIGRATING TO RXJAVA2 バージョンアップどうやる? dependencies { compile: "io.reactivex:rxjava:1.3.2" } dependencies
{ compile: "io.reactivex.rxjava2:rxjava:2.1.4" }
これはやめた方がいい
MIGRATING TO RXJAVA2 RxJava1への依存を削除するのはやめた方がいい ▸ RxJava1とRxJava2では変更点が多く、作業にも確認にも時 間がかかる ▸ つまり何度も何度もmasterの変更を取り込まなければなら ない
▸ RxJava1で書いたコードがmasterにどんどん追加されていく
RxJava2Interop を使って、 少しずつRxJava2に移行しよう
MIGRATING TO RXJAVA2 What is RxJava2Interop? ▸ https://github.com/akarnokd/RxJava2Interop ▸ RxJava1とRxJava2のReactive
Typeを相互に変換 ▸ 作: David Karnok(RxJavaのmain commiter) ▸ このライブラリを使うとステップ・バイ・ステップで RxJava2に移行できる
MIGRATING TO RXJAVA2 Usage // app/build.gradle android.packagingOptions { exclude 'META-INF/rxjava.properties'
} dependencies { compile: "io.reactivex:rxjava:1.3.2" compile: "io.reactivex.rxjava2:rxjava:2.1.4" compile: "com.github.akarnokd:rxjava2-interop:0.10.6 }
MIGRATING TO RXJAVA2 使い方(in java) RxJavaInterop.toV2Flowable(v1Observable); RxJavaInterop.toV2Maybe(v1Single); RxJavaInterop.toV1Observable(v2Publisher); // etc...
MIGRATING TO RXJAVA2 使い方(in Kotlin) fun <T> rx.Observable<T>.toV2Observable() = RxJavaInterop.toV2Observable(this)
fun <T> io.reactivex.Observable<T>.toV1Observable() = RxJavaInterop.toV1Observable(this, BackpressureStrategy.LATEST) // v1Observable.toV2Observable() // v2Observable.toV1Observable() 拡張関数を定義すると捗る
ANY REAL-LIFE EXAMPLE?
テキスト 移行の手順 ▸ 各種ライブラリの移行方法検討(Realm, SQLite, Retrofit) ▸ nullを流してるストリームをOptionalに書き換える ▸ ひたすらやっていき
MIGRATING TO RXJAVA2 Realm ▸ Realm v4.0はRxJava2をサポートする(未リリース) ▸ v3.xでは2つ選択肢がある ▸
RxJava2Interopを使う ▸ v4.0の実装を参考に自分で作る ▸ https://github.com/realm/realm-java/pull/4991 ▸ Kotlinの拡張関数使うと
テキスト SQLite ▸ 特にライブラリは使わずに実装しているので、地道に書き換 える ▸ Roomへの置き換えも進行中
MITRATING TO RXJAVA2 Retrofit ▸ RxJava2CallAdapterFactoryを使う ▸ RxJava1とRxJava2のCallAdapterは共存できる Retrofit.Builder() .baseUrl("https://api.example.com")
.addCallAdapterFactory( RxJavaCallAdapterFactory.create()) .addCallAdapterFactory( RxJava2CallAdapterFactory.create()) .build()
MIGRATING TO RXJAVA2 Architecture of AWA DbClient DbClient DbClient DbClient
DbClient ApiClient SharedPreferences Realm SQLite API Server DbClient DbClient Model DbClient DbClient UseCase DBCLIENT DBCLIENT Activity/Fragment View Domain Data
MIGRATING TO RXJAVA2 Architecture of AWA DbClient DbClient DbClient DbClient
DbClient ApiClient SharedPreferences Realm SQLite API Server DbClient DbClient Model DbClient DbClient UseCase DBCLIENT DBCLIENT Activity/Fragment View Domain Data DbClientをRxJava2化 RxJava2Interop でRxJava1に変換 Domainより上の レイヤは変更不要
MIGRATING TO RXJAVA2 Some random tips ▸ doOnDisposeではなくdoFinallyを使う ▸ https://github.com/ReactiveX/RxJava/wiki/What's-
different-in-2.0 ▸ Reactive Typeで「値がない状態」を通知したい時はOptionalを 使う ▸ Kotlinだとgojuno/koptionalがミニマムでよさそう ▸ Singleで↑の場合はMaybeを使いましょう
THANK YOU!