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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
600
Introduction of ReactiveX
bl0lia
0
150
ApplivにRealmを導入した話
bl0lia
1
1.2k
Other Decks in Programming
See All in Programming
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
200
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5.4k
トークンをケチるな、設計しろ:GitHub Copilotを賢く使うコンテキスト戦略
ochtum
0
190
dRuby over BLE
makicamel
2
390
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.3k
Performance Engineering for Everyone
elenatanasoiu
0
230
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
190
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
190
Vite+ Unified Toolchain for the Web
naokihaba
0
360
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
130
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
560
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
140
Featured
See All Featured
Google's AI Overviews - The New Search
badams
0
1k
Designing for humans not robots
tammielis
254
26k
From π to Pie charts
rasagy
0
220
Measuring & Analyzing Core Web Vitals
bluesmoon
9
870
Being A Developer After 40
akosma
91
590k
Writing Fast Ruby
sferik
630
63k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
210
Designing Powerful Visuals for Engaging Learning
tmiket
1
430
We Have a Design System, Now What?
morganepeng
55
8.2k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Optimising Largest Contentful Paint
csswizardry
37
3.7k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
200
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()