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
Introduction of ReactiveX
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Yuki Funakoshi
February 08, 2016
Programming
150
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Introduction of ReactiveX
Yuki Funakoshi
February 08, 2016
More Decks by Yuki Funakoshi
See All by Yuki Funakoshi
Android Emulator 2.0
bl0lia
0
610
実際のアプリ開発で使ったRxを紹介 #RxJaNight
bl0lia
5
1k
ApplivにRealmを導入した話
bl0lia
1
1.2k
Other Decks in Programming
See All in Programming
ソフトウェアラスタライザ
fadis
1
740
GKE アップグレード前に知っておきたい Blue/Green と PDB の関係
stkk
0
110
異なる設計思想のフレームワークを経験して得た学び
amekuhideki
2
1.1k
仕様駆動開発へのトライを機に チームに適合する手法を模索し続けている話
freee
PRO
0
670
Go 1.27からのGODEBUG / Go 1.27 リリースパーティ #go127party
mazrean
0
260
片田舎のおっさん、 Swift Buildのダイアモンド問題解決の不具合修正PRを出すが、解決方法がキャッシュをしないようにすることであり、ビルド時間が伸びると言われてマージされないので高速化もする/swiftbuild
yimajo
0
320
Hello, Hiroshima Geospatial Data! — Exploring DoboX with Python
ra0kley
0
120
いまどきの Codex で開発する visionOS アプリの開発スタイルについて
karad
0
170
AIの中の人になってみる
htkym
0
140
初心者DevRelとして参加者だった私が、DevRel Talks!#2に登壇するまでにしてきたこと
sokohirai
0
180
typoなんかねぇよ
raspython3
0
630
AI時代に学ぶ 好きなルール 嫌いなルール Linter編
shorty5121
0
450
Featured
See All Featured
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
260
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
Claude Code のすすめ
schroneko
67
230k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
What's in a price? How to price your products and services
michaelherold
247
13k
Color Theory Basics | Prateek | Gurzu
gurzu
0
440
Fireside Chat
paigeccino
42
4k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
67
57k
It's Worth the Effort
3n
188
29k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
680
Everyday Curiosity
cassininazir
0
300
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
550
Transcript
Introduction Yuki Funakoshi (@bl_lia) NYLE Inc. Android / iOS Engineer
Appliv use Android Clean Architecture use Dependency Injection use Realm
use Kotlin … and use RxJava!
Introduction of RxJava
Observable.from(arrayOf( "Introduction", "Appliv App for Android", "Basic of ReactiveX", “ReactiveX
with Appliv" )).subscribe{ title -> present(title) };
Do you know ReactveX ?
ReactiveX is… Composing asynchronous Event-based programs
Observable Subscriber Subscribe Send Event Async
Observable Subscriber Observable Observable Filter Map Send Event
Observable Observable Subscriber Send Event Send Event
Observable.from(arrayOf(1,2,3,4,5,6,7,8,9,10)) .filter { it % 2 == 0 } .subscribe
{ println(it) } 2 4 6 8 10
val a = Observable.from(arrayOf(1,2,3,4,5)) val b = Observable.from(arrayOf(6,7,8,9,10)) Observable.merge(a, b)
.filter { it % 2 == 0 } .subscribe { println(it) } 2 4 6 8 10
val a = Observable.from(arrayOf(1,2,3,4,5)) val b = Observable.from(arrayOf(6,7,8,9,10)) Observable.merge(a, b)
.filter { it % 2 == 0 } .subscribeOn(Schedulers.newThread()) .subscribe { println(it) } 2 4 6 8 10
val a = Observable.create<Int> { subscriber -> subscriber.onNext(2); subscriber.onCompleted(); }
val b = Observable.from(arrayOf(6,7,8,9,10)) Observable.merge(a, b) .filter { it % 2 == 0 } .subscribe { println(it) } 2 6 8 10
data class Item(val id: String, val title: String) interface ItemService
{ @GET("/api/v2/items") fun items(): Observable<List<Item>> } fun api() { val retrofit = Retrofit.Builder() .baseUrl("http://qiita.com") .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .build(); val service = retrofit.create(ItemService::class.java) service.items().subscribe { it.map { println(it.title) } } } https://gist.github.com/bl-lia/49130ad9d9730c826d02
Cache Control Factory Class cached? Disk Data Store API Data
Store Disk Data Cache API
interface ItemDataStore { fun items(): Observable<List<Item>> } // Singleton Class
object ItemCache : ItemDataStore { override fun items(): Observable<List<Item>> { // Return cached items } fun reset(newItemList: List<Item>) { // Replace cached items } fun isCached(): Boolean { // Cache data exists? } } class ItemApi(cache: ItemCache) : ItemDataStore { val cache = cache override fun items(): Observable<List<Item>> { val retrofit = Retrofit.Builder()...build() val service = retrofit.create(ItemService::class.java) return service.items().doOnNext { cache.reset(it) } } } https://gist.github.com/bl-lia/23023d968ab884708f30
class ItemStoreFactory { val cache = ItemCache fun create(): ItemDataStore
{ if (cache.isCached()) { return cache } return ItemApi(cache) } } fun main(args : Array<String>) { ItemStoreFactory().create().items() } https://gist.github.com/bl-lia/23023d968ab884708f30
UI Control with RxJava
None
RxTextView.textChanges(textView) .debounce(1, TimeUnit.SECONDS) .subscribe { search(it) }
https://github.com/bl-lia/RxFb
RxLoginManager.from(loginManager) .logInWithReadPermissions(callbackManager, fragment, permissions) .flatMap { return RxGraphRequest.newMeRequest(accessToken, params) }
.subscribe { doAnything() }
onCompleted()