Share
Embed
Transcript
54 slides
-
CRUNCHING RXANDROID ABOUT THE SPEAKER Android 2.1+ Android Developer @
Ennova twitter.com/_tiwiz github.com/tiwiz medium.com/@_tiwiz ROBERTO ORGIU -
CRUNCHING RXANDROID A FEW STEPS BACK ▸ DESIGN PATTERNS ▸
OBSERVER PATTERN ▸ IMMUTABILITY ▸ FUNCTIONAL PROGRAMMING ▸ REACTIVE EXTENSIONS -
A DESIGN PATTERN IS A GENERAL REPEATABLE SOLUTION TO A
COMMONLY OCCURRING PROBLEM Wikipedia and a bunch of other people CRUNCHING RXANDROID DESIGN PATTERNS -
DESIGN PATTERNS Erich Gamma, Richard Helm, Ralph Johnson, John Glissades
ELEMENTS OF REUSABLE OBJECTED-ORIENTED SOFTWARE -
CRUNCHING RXANDROID A FEW STEPS BACK ▸ DESIGN PATTERNS ▸
OBSERVER PATTERN ▸ IMMUTABILITY ▸ FUNCTIONAL PROGRAMMING ▸ REACTIVE EXTENSIONS -
AN OBJECT MAINTAINS A LIST OF ITS OBSERVERS AND NOTIFIES
THEM AUTOMATICALLY OF ANY STATE CHANGES Wikipedia CRUNCHING RXANDROID OBSERVER PATTERN -
CRUNCHING RXANDROID A FEW STEPS BACK ▸ DESIGN PATTERNS ▸
OBSERVER PATTERN ▸ IMMUTABILITY ▸ FUNCTIONAL PROGRAMMING ▸ REACTIVE EXTENSIONS -
AN IMMUTABLE OBJECT IS AN OBJECT WHOSE STATE CANNOT BE
MODIFIED AFTER IT IS CREATED. BRIAN GOETZ, ORACLE CRUNCHING RXANDROID IMMUTABILITY -
CRUNCHING RXANDROID A FEW STEPS BACK ▸ DESIGN PATTERNS ▸
OBSERVER PATTERN ▸ IMMUTABILITY ▸ FUNCTIONAL PROGRAMMING ▸ REACTIVE EXTENSIONS -
TREATS COMPUTATION AS THE EVALUATION OF MATHEMATICAL FUNCTIONS AND AVOIDS
CHANGING STATE AND MUTABLE DATA. Wikipedia CRUNCHING RXANDROID FUNCTIONAL PROGRAMMING -
CRUNCHING RXANDROID REACTIVE EXTENSIONS ▸ PUSH (Observable) VS PULL (Iterable)
▸ .NET Came in first ▸ Netflix and the JVM ▸ Android bindings -
CRUNCHING RXANDROID KEY CONCEPTS ▸ OBSERVABLES ▸ SUBSCRIBERS ▸ OPERATORS
▸ SCHEDULERS ▸ SUBJECTS -
CRUNCHING RXANDROID OBSERVABLES ▸ Observable.create() ▸ onNext() ▸ onCompleted() ▸
onError() ▸ Hot & cold -
CRUNCHING RXANDROID OBSERVABLES Observable.create(new Observable.OnSubscribe<String>() { @Override public void call(Subscriber<?
super String> subscriber) { // do your stuff here } }); Observable.create() -
CRUNCHING RXANDROID OBSERVABLES ▸ Observable.create() ▸ onNext() ▸ onCompleted() ▸
onError() ▸ Hot & cold -
CRUNCHING RXANDROID OBSERVABLES Observable.create(new Observable.OnSubscribe<String>() { @Override public void call(Subscriber<?
super String> subscriber) { subscriber.onNext("Hello, world!"); subscriber.onCompleted(); } }); onNext() onCompleted() onError() -
CRUNCHING RXANDROID OBSERVABLES ▸ Observable.create() ▸ onNext() ▸ onCompleted() ▸
onError() ▸ Hot & cold -
CRUNCHING RXANDROID OBSERVABLES Observable.create(new Observable.OnSubscribe<String>() { @Override public void call(Subscriber<?
super String> subscriber) { subscriber.onNext("Hello, world!"); subscriber.onCompleted(); } }); Observable.create() -
CRUNCHING RXANDROID OBSERVABLES ▸ Observable.create() ▸ onNext() ▸ onCompleted() ▸
onError() ▸ Hot & cold ▸ Functions & Actions -
CRUNCHING RXANDROID KEY CONCEPTS ▸ OBSERVABLES ▸ SUBSCRIBERS ▸ OPERATORS
▸ SCHEDULERS ▸ SUBJECTS -
CRUNCHING RXANDROID SUBSCRIBERS observable.subscribe(new Subscriber<String>() { @Override public void onCompleted()
{} @Override public void onError(Throwable e) {} @Override public void onNext(String s) {} }); -
CRUNCHING RXANDROID KEY CONCEPTS ▸ OBSERVABLES ▸ SUBSCRIBERS ▸ OPERATORS
▸ SCHEDULERS ▸ SUBJECTS -
OPERATORS CAN BE CHAINED, AND EACH ONE OF THEM WILL
OPERATE SEQUENTIALLY ON THE OBSERVABLE GENERATED BY THE OPERATOR IMMEDIATELY PREVIOUS IN THE CHAIN CRUNCHING RXANDROID OPERATORS ReactiveX.io -
CRUNCHING RXANDROID OPERATORS ▸ Create ▸ Transform ▸ Filter ▸
Combine ▸ Error handling ▸ Utility ▸ Backpressure -
CRUNCHING RXANDROID OPERATORS ▸ create() ▸ just() ▸ from() ▸
defer() ▸ interval() ▸ range() ▸ timer() Create -
CRUNCHING RXANDROID OPERATORS ▸ Create ▸ Transform ▸ Filter ▸
Combine ▸ Error handling ▸ Utility ▸ Backpressure -
CRUNCHING RXANDROID OPERATORS ▸ flatMap() ▸ map() ▸
groupBy() Transform transform the items emitted by an Observable into Observables, then flatten the emissions from those into a single Observable transform the items emitted by an Observable by applying a function to each item divide an Observable into a set of Observables that each emit a different group of items from the original Observable, organised by key -
CRUNCHING RXANDROID OPERATORS ▸ Create ▸ Transform ▸ Filter ▸
Combine ▸ Error handling ▸ Utility ▸ Backpressure -
CRUNCHING RXANDROID OPERATORS ▸ filter() ▸ first() ▸ take() ▸
debounce() Filter emit only those items from an Observable that pass a predicate test emit only the first item (or the first item that meets some condition) emitted by an Observable emit only the first n items emitted by an Observable only emit an item from an Observable if a particular timespan has passed without it emitting another item -
CRUNCHING RXANDROID OPERATORS ▸ Create ▸ Transform ▸ Filter ▸
Combine ▸ Error handling ▸ Utility ▸ Backpressure -
CRUNCHING RXANDROID OPERATORS ▸ combineLatest() ▸ switch() ▸ retry() Combine
& Error handling when an item is emitted by either of two Observables, combine the latest item emitted by each Observable via a specified function and emit items based on the results of this function convert an Observable that emits Observables into a single Observable that emits the items emitted by the most-recently-emitted of those Observables if a source Observable sends an onError notification, resubscribe to it in the hopes that it will complete without error -
CRUNCHING RXANDROID OPERATORS ▸ Create ▸ Transform ▸ Filter ▸
Combine ▸ Error handling ▸ Utility ▸ Backpressure -
CRUNCHING RXANDROID KEY CONCEPTS ▸ OBSERVABLES ▸ SUBSCRIBERS ▸ OPERATORS
▸ SCHEDULERS ▸ SUBJECTS -
TO INTRODUCE MULTITHREADING INTO YOUR CASCADE OF OBSERVABLE OPERATORS, INSTRUCT
THOSE OPERATORS TO OPERATE ON PARTICULAR SCHEDULERS. ReactiveX.io CRUNCHING RXANDROID SCHEDULERS -
CRUNCHING RXANDROID SCHEDULERS ▸ Schedulers.computation() ▸ Schedulers.from(executor) ▸ Schedulers.immediate() ▸
Schedulers.io() ▸ Schedulers.newThread() ▸ Schedulers.trampoline() ▸ AndroidSchedulers.mainThread() -
CRUNCHING RXANDROID SCHEDULERS ▸ subscribeOn(scheduler) ▸ observeOn(scheduler) How to use
them On what Scheduler shall the Observable run? and on which shall it return its result? -
CRUNCHING RXANDROID KEY CONCEPTS ▸ OBSERVABLES ▸ SUBSCRIBERS ▸ OPERATORS
▸ SCHEDULERS ▸ SUBJECTS -
ACT AS A BRIDGE BETWEEN OBSERVABLES AND OBSERVERS, AS THEY
ARE BOTH. ReactiveX.io CRUNCHING RXANDROID SUBJECTS -
CRUNCHING RXANDROID SUBJECTS AsyncSubject it emits the last value (and
only the last value) emitted by the source Observable, and only after that source Observable completes. (If the source Observable does not emit any values, the AsyncSubject also completes without emitting any values.) -
CRUNCHING RXANDROID SUBJECTS BehaviorSubject When an observer subscribes to this
type of Subject, it begins by emitting the item most recently emitted by the source Observable (or a seed/default value if none has yet been emitted) and then continues to emit any other items emitted later by the source Observable(s). -
CRUNCHING RXANDROID SUBJECTS PublishSubject it emits to an observer only
those items that are emitted by the source Observable(s) subsequent to the time of the subscription. -
CRUNCHING RXANDROID SUBJECTS ReplaySubject it emits to any observer all
of the items that were emitted by the source Observable(s), regardless of when the observer subscribes. -
SUBJECTS CAN BE HANDY WHEN MANAGING NETWORKING REQUESTS AND ANDROID
LIFECYCLE CHANGES. CRUNCHING RXANDROID SUBJECTS -
CRUNCHING RXANDROID KEY CONCEPTS ▸ OBSERVABLES ▸ SUBSCRIBERS ▸ OPERATORS
▸ SCHEDULERS ▸ SUBJECTS -
CRUNCHING RXANDROID USEFUL STUFF ▸ RxAndroid ▸ RxLifecycle ▸ RxBinding
▸ Retrofit Libraries from Trello from Jake Wharton from Square from ReactiveX -
CRUNCHING RXANDROID USEFUL STUFF ▸ Dan Lew Codes ▸ Advanced
RxJava ▸ CoseNonJaviste Blogs akarnokd.blogspot.it cosenonjaviste.it/rxjava blog.danlew.net