SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Downloaden Sie, um offline zu lesen
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
DbClientDbClientDbClient
DbClientDbClientApiClient
SharedPreferences Realm SQLite API Server
DbClientDbClientModel
DbClientDbClientUseCase
DBCLIENTDBCLIENTActivity/Fragment
View
Domain
Data
MIGRATING TO RXJAVA2
Architecture of AWA
DbClientDbClientDbClient
DbClientDbClientApiClient
SharedPreferences Realm SQLite API Server
DbClientDbClientModel
DbClientDbClientUseCase
DBCLIENTDBCLIENTActivity/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!

Weitere ähnliche Inhalte

Empfohlen

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Migrating to RxJava2 from RxJava1