Functional Programmingis a model of programming that transform and compose stream of immutable sequences by applying map, filter and reduce. Events are immutable because you can't change history.Reactive Programmingis a model of programming focuses on data flow and change propagation.ReactiveXis an API that focuses on asynchronous composition and manipulation of observable streams of data or events by using a combination of the Observer pattern, Iterator pattern, and features of Functional Programming.RxJavais the open-source implementation ofReactiveXin Java.RxJavais a Java VM implementation ofReactiveX(Reactive Extensions): a library for composing asynchronous and event-based programs by using observable sequences.RxAndroidis a lightweight extension to RxJava that providers a Scheduler for Android’s Main Thread, as well as the ability to create a Scheduler that runs on any given Android Handler class.- The two main classes are
ObservableandSubscriber. Observableis a class that emits a stream of data or events.Subscriberis a class that acts upon the emitted items.- A
cold observableis one to which no one has subscribed, and is thus inanimate. - Observable
subscribehas many overloads. You can choose to implement an entireObserverwithonNext,onCompleteandonError, or only some of these in the form of anAction1. - Using
Observable.subscribeOn()can define a thread that will run our Observable’s code (the long running operation). - Using
Observable.observeOn()can define a thread that is used to monitor and check for newly emitted items from the Observable (the Subscriber’s onNext, onCompleted, and onError methods execute on the observeOn() thread). - RxJava comes with several out-of-the-box
Schedulersto use with Observables, such asSchedulers.io()(for blocking I/O operations),Schedulers.computation()(computational work), andSchedulers.newThread()(creates new thread for the work). Rxwas first conceived by Erik Meijer on the Microsoft .NET platform, as a way of combining data or event streams with reactive objects and functional composition- In Rx, events are modeled as
observable streamsto whichobserversaresubscribed. These streams, or observables for short, can befiltered,transformed, andcomposedin various ways before their results areemittedto anobserver. - The standard flow of an
Observableis to emit one or more items, and then complete successfully or with an error. - An
Observablecan have multipleSubscribers, and for each item emitted by theObservable, the item will be sent to theSubscriber.onNext()method to be handled. - Once an
Observablehas finished emitting items, it will call theSubscriber.onCompleted()method, or if there is an error theObservablewill call theSubscriber.onError()method. RxJava, at it’s core, is about two things:ObservablesandObservers.Observablesare said to “emit” values.Observers, watchObservablesby “subscribing” to them.- When an
Observersubscribes to anObservableaSubscriptionis created. - A
Subscriptionrepresents a connection between anObserverand anObservable. Subjectsare special objects that are both anObservableand anObserver.- The basic building blocks of reactive code are
ObservablesandSubscribers. - An
Observableemits items; aSubscriberconsumes those items.
-
-
Save bazted/7c9f786e1cad1a1b7de2c5efcf77afd9 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment