Rxjava2 Getting Started tutorial: function reactive programming and Overview

To download the source code, please visit
https://github.com/fengchuanfang/Rxjava2Tutorial

RxJava is a concrete realization of a function reactive programming ideas on the java language. RxJava2 In this implementation, a comprehensive rewrite of Rxjava1, if no contact RxJava before, from the entry Rxjava2, without the need to understand the direct RxJava1.
Before using RxJava2, developed for Android, you need to add the following dependency in the project

    implementation "io.reactivex.rxjava2:rxjava:2.1.3"
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'

Reactive programming function is a function of programming and reactive programming product of the two regressed subvert the traditional programming paradigm superimposed.


Reactive programming (Reactive Programming): a paradigm for a programming data stream and the variations of propagation.
Reactive programming ultimate idea, and all are stream (everything is stream). As with object-oriented programming are all the same object. According to the idea of dialectical materialism, the material world is in constant motion universal connection and unity of the whole change, and everything 'motion of' this 'objective phenomenon' can be 'abstract description', it can be said, the material world by way of the data stream It is an objective data stream.
In the program all variables, arrays, collections, objects, events can be sent as a data stream processing.


Functional Programming (Functional programming): a combination of processing data by calling function or the function of acquiring the result of a programming paradigm.
Function is the core of functional programming, pure functions and higher-order functions are two important roles.
Pure function with the independence and closed to the outside of the characteristics of
a return to pure function of the result only affected the function parameters, if you enter the same parameters regardless of where to call, when to call, how many times the output result of the call is the same.
2, the data processing functions inside the pure from the external environment does not affect the external environment, inside each function has its own set of local variables, but this only works internally within the function call this function, which the initial value is determined by parameters of the function, is not affected by external variables, while the calculation result of the function only affects the function return value, it does not affect the value of the external variable.
Higher-order functions (Higher-order function): allows the function as a parameter, or a function as a function of the value returned is called higher-order functions. It can be transferred, combined, links and other operations to solve complex problems can not be solved by a single function of higher order functions for pure function.


Reactive programming function (Functional Reactive Programming: FRP): is a series of calls transmitted by a combination of functions, transition, monitor, response data stream programming paradigm.
In RxJava in response programming function embodied as an observer (Observer) Feed an observation target (Observable), the observation target can transmit a data stream by creating, through a series of operators (Operators) processing and thread scheduler ( Scheduler) forwarding between different threads, and finally accepted by the observer process and make a response.
In RxJava2, providing five of the observer pattern combination to complete the process of this series, each relying on a combination of their differences in a series of functions that can be called, has its own characteristics.
This combination of five (corresponding to the front after a viewer can observe the object) are:
ObservableSource / the Observer
may transmit a single data or data sequences onNext method, transmission completion notification sent by onComplete or abnormality notification by the onError, the back pressure does not support strategy.
Publisher / Subscriber
has been improved in ObservableSource / Observer, based on the policy processing by the back pressure back pressure problem, but not the first set of high efficiency.
The following three groups are responsive to achieve a new relationship, Not Rxjava1 may be seen as ObservableSource / Observer simplified version
SingleSource / SingleObserver
not send completion notification data sequence or only a single data transmission method onSuccess or by onError sends exception notifications
CompletableSource / CompletableObserve
We can not send any kind of data (a single data or a data sequence), only transmission completion notification by onComplete or abnormality notification sent by the onError
MaybeSource / MaybeObserver
may transmit a single data through the onSuccess, transmission completion notification by onComplete or an abnormality notification transmitted by onError.


 

Guess you like

Origin blog.csdn.net/suyimin2010/article/details/88091150