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
0
100
RxJava1からRxJava2へ
Yasuhiro Shimizu
October 03, 2017
Tweet
Share
More Decks by Yasuhiro Shimizu
See All by Yasuhiro Shimizu
Jetpack Composeから始める、頑張らないVRT
yshrsmz
0
1.1k
Kotlin Multiplatform Projectを導入してみて
yshrsmz
1
1.1k
BIP39について
yshrsmz
0
170
Android Fireside Chatまとめ
yshrsmz
3
2.2k
Other Decks in Programming
See All in Programming
Google Agent Development Kit でLINE Botを作ってみた
ymd65536
2
160
童醫院敏捷轉型的實踐經驗
cclai999
0
190
GraphRAGの仕組みまるわかり
tosuri13
7
480
LT 2025-06-30: プロダクトエンジニアの役割
yamamotok
0
340
Benchmark
sysong
0
260
Beyond Portability: Live Migration for Evolving WebAssembly Workloads
chikuwait
0
390
Select API from Kotlin Coroutine
jmatsu
1
190
AIエージェントはこう育てる - GitHub Copilot Agentとチームの共進化サイクル
koboriakira
0
370
ReadMoreTextView
fornewid
1
480
CursorはMCPを使った方が良いぞ
taigakono
1
170
イベントストーミング図からコードへの変換手順 / Procedure for Converting Event Storming Diagrams to Code
nrslib
1
340
C++20 射影変換
faithandbrave
0
530
Featured
See All Featured
Balancing Empowerment & Direction
lara
1
370
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Rebuilding a faster, lazier Slack
samanthasiow
81
9.1k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
700
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.8k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
138
34k
Agile that works and the tools we love
rasmusluckow
329
21k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Designing for humans not robots
tammielis
253
25k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
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!