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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
450
Embedded SREと共に達成した会員管理システムのAWS移行 - SRE NEXT 2026 ランチスポンサーセッション
niftycorp
PRO
1
3.4k
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
130
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
16
3.8k
AI時代に設計が 最大の生産性レバーになる 意図駆動開発とデータを消さない設計|Don't Delete Your Data or Your Intent — Design as the Deepest Lever in the AI Era
tomohisa
1
560
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
200
生成AI導入の「期待外れ」を乗り越える ー 開発フロー改革が目指す、真の組織変革
starfish719
0
3.7k
AIが無かった頃の素敵な出会いの話
codmoninc
1
360
生成AIで帳票OCRが「簡単に」作れる時代になった?
kon_shou
0
360
Laravelで学ぶ Webアプリケーションチューニング入門/web_application_tuning_101
hanhan1978
4
1.6k
言葉の格闘技のススメ~紙とペンと言葉から始める、キャリアの描き方~
progresscicada
1
120
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
150
Featured
See All Featured
Java REST API Framework Comparison - PWX 2021
mraible
34
9.6k
Being A Developer After 40
akosma
91
590k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.5k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
620
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
270
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.4k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
360
Build your cross-platform service in a week with App Engine
jlugia
234
19k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
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()