$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
RxJava
Search
Douglas Kayama
August 29, 2015
Programming
5
570
RxJava
Palestra apresentada na QCon RJ 2015 e Android Dev Conference iMasters 2015
Douglas Kayama
August 29, 2015
Tweet
Share
More Decks by Douglas Kayama
See All by Douglas Kayama
TensorFlow no Android – v2
douglasdrumond
0
33
BLE
douglasdrumond
0
32
TensorFlow no Android
douglasdrumond
0
26
Firebase or Realm?
douglasdrumond
0
80
Rio Dev Day – Introdução ao Android
douglasdrumond
0
99
Google I/O
douglasdrumond
0
62
Criando apps com alto nível de qualidade (versão longa)
douglasdrumond
0
42
Criando apps com alto nível de qualidade (versão curta)
douglasdrumond
0
29
Primeiros Passos com Google Fit
douglasdrumond
0
190
Other Decks in Programming
See All in Programming
CSC305 Lecture 15
javiergs
PRO
0
240
Socio-Technical Evolution: Growing an Architecture and Its Organization for Fast Flow
cer
PRO
0
230
AI時代もSEOを頑張っている話
shirahama_x
0
220
WebRTC、 綺麗に見るか滑らかに見るか
sublimer
1
140
【CA.ai #3】Google ADKを活用したAI Agent開発と運用知見
harappa80
0
240
著者と進める!『AIと個人開発したくなったらまずCursorで要件定義だ!』
yasunacoffee
0
110
大体よく分かるscala.collection.immutable.HashMap ~ Compressed Hash-Array Mapped Prefix-tree (CHAMP) ~
matsu_chara
1
210
複数人でのCLI/Infrastructure as Codeの暮らしを良くする
shmokmt
5
2.1k
AIコーディングエージェント(NotebookLM)
kondai24
0
100
Google Antigravity and Vibe Coding: Agentic Development Guide
mickey_kubo
2
130
S3 VectorsとStrands Agentsを利用したAgentic RAGシステムの構築
tosuri13
4
260
エディターってAIで操作できるんだぜ
kis9a
0
630
Featured
See All Featured
Scaling GitHub
holman
464
140k
[RailsConf 2023] Rails as a piece of cake
palkan
58
6.1k
Done Done
chrislema
186
16k
Docker and Python
trallard
46
3.7k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
31
2.7k
GitHub's CSS Performance
jonrohan
1032
470k
Typedesign – Prime Four
hannesfritz
42
2.9k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
48
9.8k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.3k
Optimising Largest Contentful Paint
csswizardry
37
3.5k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
285
14k
Fireside Chat
paigeccino
41
3.7k
Transcript
RxJava Douglas Drumond
[email protected]
whoami
None
Por que RxJava? Eventos de UI Eventos do domínio Concorrência
RxJava Observer pattern Iterator pattern Functional programming
Lambda
Retrolambda export JAVA_HOME=/path/java8 export JAVA7_HOME=/path/java7
Retrolambda plugins { id "me.tatarka.retrolambda" version "3.2.2" } android {
compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } }
Retrolambda view.setOnClickListener(new View. OnClickListener() { @Override public void onClick(final View
v) { ... } });
Retrolambda view.setOnClickListener(v -> { });
Básico Observables Subscribers Operadores
Observables Emite itens Chama onNext, onComplete ou onError Hot or
Cold
Subscriber Implementa onNext onComplete onError
Operadores flatMap filter debounce create defer etc
Criando Observable e Subscriber DEMO
Operators Subscribers reagem, não mudam Operadores transformam dados
Operators DEMO
Exemplo com UI DEMO
Mais operadores filter Ex: .filter(query -> !TextUtils.isEmpty(query))
Threads subscribeOn observeOn NewThreadScheduler HandlerThreadScheduler
Rede DEMO
Tratamento de erros Observable.create(...) .map(s -> exception(s)) .map(s -> exception2(s))
.subscribe(new Subscriber<String>() { @Override public void onNext(String s) { Log.d(TAG, s); } @Override public void onCompleted() { Log.d(TAG, "uhu!"); } @Override public void onError(Throwable e) { Log.e(TAG, "ops!"); } });
Ciclo de vida da Activity .cache .unsubscribe ao rodar .subscribe
ao restaurar Use RxLifecycle
Google Play Services https://github.com /mcharmas/Android-ReactiveLocation https://github.com /zmarkan/Reactive-PlayServices
Google Play Services ReactiveLocationProvider locationProvider = new ReactiveLocationProvider(context); locationProvider.getLastKnownLocation() .subscribe(new
Action1<Location>() { @Override public void call(Location location) { doSthImportantWithObtainedLocation(location); } });
Testes @Test public void shouldLoadTwoUsers() throw Exception { TestSubscriber<User> testSubscriber
= new TestSubscriber<>(); databaseHelper.loadUser().subscribe(testSubscriber); testSubscriber.assertNoErrors(); testSubscriber.assertReceivedOnNext( Arrays.asList(user1, user2)) }
Testes https://github.com/ribot/assertj-rx + BlockingObservable
Testes (exemplo) assertThat(observable.toBlocking()). completes(); assertThat(observable.toBlocking()) .completes() .listOfValuesEmitted() .containsExactly("a", "b", "c");
Referências http://reactivex.io/ https://github.com/ReactiveX/RxJava/wiki /Alphabetical-List-of-Observable-Operators https://speakerdeck.com/benjchristensen https://github.com/mutexkid/rxjava-koans
Referências https://github.com/trello/RxLifecycle https://github.com/JakeWharton/RxBinding https://github.com/ReactiveX/RxAndroid/
Código https://github.com/ douglasdrumond/KnightsOfLambdaCalculus
Obrigado
Contato
[email protected]
@douglasdrumond +DouglasDrumond www.cafelinear.com
[email protected]