Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
実際のアプリ開発で使った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
620
Introduction of ReactiveX
bl0lia
0
150
ApplivにRealmを導入した話
bl0lia
1
1.2k
Other Decks in Programming
See All in Programming
AI活用は、個人から組織へ|マルチプレイヤーエージェントハーネス「QM」の社内活用事例 / AI use is moving from individuals to orgs
rkaga
1
120
XHTMLが残したもの
yosuke_furukawa
PRO
2
830
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
300
GKE で Pod の見方を変えたら、スケールアウト時の挙動を真に捉えられた話
stkk
0
130
AHC070解法紹介
eijirou
0
130
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
520
技術的負債を組織課題として解く-増えすぎたマイクロサービスとの戦い-
reimaru
1
2k
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
2.2k
SONY CISC-NEWS NWS-1750 + NWB-225 フレームバッファの NetBSD/news68k ドライバ実装 / OSC2026Hiroshima
tsutsui
0
120
大喜利で理解するLLM as a Judge / Understanding LLM-as-a-Judge through Ogiri
rockname
0
150
WebAssembly in Android Apps 〜 WASMはJNIの夢を見るか
keiji
1
110
すこし踏み込む CancellationToken
htkym
2
620
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
142
7.7k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.6k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Mobile First: as difficult as doing things right
swwweet
225
10k
The browser strikes back
jonoalderson
0
1.7k
My Coaching Mixtape
mlcsv
0
320
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Docker and Python
trallard
47
4.2k
Visualization
eitanlees
152
17k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
660
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()