Rxjs understand

Speaking RxJs first talk about the history, Reactive Extension Rx is short, it is a realization of a reactive programming tool, or API, the concept of Rx:

Rx The concept was originally implemented by Microsoft and open source, that is Rx.NET, because Rx bring programming shutter mode zoomed zoomed improved asynchronous programming model, after .NET,Many developers on other platforms, and language also achieved Rx library. Visible, Rx is actually ⼀ a zoomed family, zoomed in this family, there Using Java implementation RxJava, Using C ++ implementation RxCpp, Using the Ruby implementations Rx.rb, Using Python implementation RxPy, of course, there is this family zoomed oldest Rx.NET. And RxJS, that is Rx JavaScript in your language and implementation.

The main purpose of birth is to solve the problem Rx asynchronous processing, it does not mean that it can only handle asynchronous issue. All languages are not inherently support reactive programming, so there are all kinds of language to achieve the above.
RxJs bothFunctional ProgrammingwithReactive programmingBoth features

Refers to functional programming to deal with the function, this function is not a function Generally, it has to be: declarative, pure functions, data immutability of the three characteristics.

Declarative refers to what to do, not on how to do, such as the following function, it is to solve the problem is to add an array passed one by one, as to how to do it does not care, it is the array to mapfunction, the mapgo processing, and finally get the data.

function addOne(arr) {
	return arr.map( function(item) { return item + 1 } );
}

And if we do not use the mapfunction, using the traditional way is through the forloop through each item, and then add 1 to return, this is the declarative programming corresponding imperative programming, it needs to be concerned about how to do each step required.

Pure function means:

1. Perform procedure function completely determined by the START input parameters, the influence is not affected by any data other than parameters.
2, the external function does not modify any state, such as to modify global variables or ⽐ pass the START parameter object.

Data immutability means: to maintain the original data unchanged, production ⽣ causes a new data, which means that if you need to change the data, then do not change the original data, but from a new data for us to use.

Reactive programming is in response to corresponding data input of the data is changed.

Learning RxJs has two important concepts Observable: the observed; Observer: observer; is between the viewer and the viewer by subscribeassociating function, the diagram illustrates the correlation between them, is a very primitive between them using
Here Insert Picture Description
reference: "layman rxjs"

Published 28 original articles · won praise 1 · views 8725

Guess you like

Origin blog.csdn.net/moqiuqin/article/details/96484440