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
実際のアプリ開発で使ったRxを紹介 #RxJaNight
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Yuki Funakoshi
February 25, 2016
Programming
1k
5
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
実際のアプリ開発で使ったRxを紹介 #RxJaNight
Yuki Funakoshi
February 25, 2016
More Decks by Yuki Funakoshi
See All by Yuki Funakoshi
Android Emulator 2.0
bl0lia
0
610
Introduction of ReactiveX
bl0lia
0
150
ApplivにRealmを導入した話
bl0lia
1
1.2k
Other Decks in Programming
See All in Programming
まずはプロンプトガイドを読もう、話はそれからだ
kiakiraki
1
240
AI時代に学ぶ 好きなルール 嫌いなルール Linter編
shorty5121
0
450
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
250
freeeにおけるEvalsの実践例の紹介
freee
PRO
0
160
Gmail/Google DriveをトリガーにAIエージェントを動かそう! / Run AI agents with Gmail/Google Drive as triggers!
har1101
3
460
Hello, Hiroshima Geospatial Data! — Exploring DoboX with Python
ra0kley
0
120
AWS Transform Customによる Spring Boot 2.xから4.xへのVerUp
satoshi256kbyte
2
120
生成AIで帳票OCRが「簡単に」作れる時代になった?
kon_shou
0
1.2k
Pythonの実行はどこまで賢くなったのか? CPythonとPyPyから見る最適化のしくみ
curekoshimizu
4
2.3k
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
280
AIに既存システムを理解させる技術 ~レガシーを見捨てないハーネスエンジニアリング入門~
ochtum
0
180
Deep dive into the select statement (GopherCon UK)
jespino
0
160
Featured
See All Featured
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
500
Crafting Experiences
bethany
1
270
Visualization
eitanlees
152
17k
Odyssey Design
rkendrick25
PRO
2
790
The Limits of Empathy - UXLibs8
cassininazir
1
620
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
390
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
480
Leo the Paperboy
mayatellez
8
2.2k
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
960
Transcript
㹋ꥷך،فٔ涪ד ⢪3Y稱➜ #RxJaNight
ࣗݾհ • Yuki Funakoshi (@bl_lia) • NYLE Inc. • Android
/ iOS Engineer
جຊతͳ
ඇಉظॲཧͷίϯϙʔωϯτԽ Πϕϯτϕʔεϓϩάϥϛϯά
Observable Subscriber subscribe send event
Observable Observable Observable Subscriber filter map send event operator
Observable Observable Subscriber send event send event
None
https://github.com/android10/Android-CleanArchitecture
public interface AppSearchRepository { Observable<List<SearchResult>> search(String query); Observable<List<SearchResult>> searchMore(String query);
Observable<List<Suggest>> suggest(String query); }
Case 1 Observableͷ࡞
• just(T value) • create(Observable.OnSubscribe<T> f)
http://reactivex.io/documentation/operators/just.html
Observable.just(sharedPreferences.getBoolean(KEY_ENABLE, true));
http://reactivex.io/documentation/operators/create.html
Observable.create(subscriber -> { final Gson gson = new Gson(); final
String alertJson = sharedPreferences.getString(KEY_ALERT, ""); final Alert alert = gson.fromJson(alertJson, Alert.class); subscriber.onNext(alert); subscriber.onCompleted(); });
Case 2 ॲཧͷՃ
• filter(Func1) • startWith(Iterable) / startWith(T)
http://reactivex.io/documentation/operators/filter.html
Ϧετ͔Βআ֎ ɾγεςϜΞϓϦ ɾApplivΞϓϦ
Observable.from(packageManager.getInstalledApplications(PackageManager.GET_META_DATA)) .filter(app -> { if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == ApplicationInfo.FLAG_SYSTEM)
return false; if (applicationInfo.packageName.equals(application.getPackageName())) return false; return true; }) .toList();
http://reactivex.io/documentation/operators/startwith.html
ةحف
recommendService.like(recommendId, isLike) .map(response -> response.recommend) .startWith(() -> { return fakeRecommend;
});
Case 3 API͔Βͷσʔλऔಘ
• Retrofit • map(Func1) • doOnNext(Action1)
{ "result": true, "items": [{ "id": "aaaaaa", "title": "Item A"
},{ "id": "bbbbbb", "title": "Item B" }] }
None
dependencies { compile 'io.reactivex:rxjava:1.1.1' compile 'com.squareup.retrofit:retrofit:2.0.0-beta2' compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta2' }
class Item { public final String id; public final String
title; public Item(String id, String title) { this.id = id; this.title = title; } } class ItemResponse { public final boolean result; public final List<Item> items; public ItemResponse(boolean result, List<Item> items) { this.result = result; this.items = items; } } interface ItemService { @GET("/items") Observable<ItemResponse> items(); }
public void getItems() { final Retrofit retrofit = new Retrofit.Builder().baseUrl("http://hogehoge.com")
.addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .build(); final ItemService service = retrofit.create(ItemService.class); service.items() .map(itemResponse -> itemResponse.items); }
http://reactivex.io/documentation/operators/map.html
Factory Class cached? Disk Data Store API Data Store Disk
Data Cache API
Factory Class cached? Disk Data Store API Data Store Disk
Data Cache API
Factory Class cached? Disk Data Store API Data Store Disk
Data Cache API
Factory Class cached? Disk Data Store API Data Store Disk
Data Cache API
http://reactivex.io/documentation/operators/do.html
interface ItemCache { void addItems(List<Item> items); } public void getItems(ItemCache
cache) { final Retrofit retrofit = new Retrofit.Builder().baseUrl("http://hogehoge.com") .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .build(); final ItemService service = retrofit.create(ItemService.class); service.items() .map(itemResponse -> itemResponse.items) .doOnNext(items -> cache.addItems(items)); }
ך➭
• Τϥʔॲཧܥ • subscriber.onError(Throwable) • OnErrorThrowable.from(Throwable) • Observable.onError(Throwable) • onErrorResumeNext(Observable)
• onErrorReturn(Func1)
• ςετ·ΘΓ • TestSubscriber<T> • assertCompleted() / assertNotCompleted() • assertValue(T
value) / assertNoValues() • assertError(java.lang.Throwable throwable) / assertNoErrors()