[RxJS] Creation Operator:create ()

Source: Internet
Author: User

We have the been using observable.create () a lot in previous lessons and so let's take a closer look how does it work.

The CREATE function:

varFoo =Rx.Observable.create (function (Observer) {Observer.next ( the); Observer.next ( -); Observer.next ( $);  Observer.complete ();}) ; Foo.subscribe ((x)=>{console.log ('Next'+x);}, (Err)=>{console.log ('Err'+err);}, ()=>{console.log (' Done');},)

In deep, create () function equal to New rx.observable ():

var New rx.observable (function (Observer) {  Observer.next);  Observer.next (+);  Observer.next ($);  Observer.complete ();})  ;

And this also equal to:

function Subscribe (Observer) {  Observer.next;  Observer.next (+);  Observer.next ($);  Observer.complete ();}   var New Rx.observable (subscribe);

So, if we get rid of RxJS, then we can create the Create () function like:

function Subscribe (Observer) {Observer.next ( the); Observer.next ( -); Observer.next ( $); Observer.complete ();}varObserver ={Next: (x)=>{console.log ('Next'+x);}, Error: (ERR)=>{console.log ('Err'+err);}, Complete: ()=>{console.log (' Done');}} SUBSCRIBE (Observer);

Of course, it's useful to having the observable type because then it had all those nice operators so we saw and that we AR e also seeing new operators coming next. If you paid attention and then you're going to remember so in the subscribe, we had previously three functions here as Argu ment. Instead of an object, as we had now, we had just these three functions.

Also, the observable type, it converts these three functions to an observer object. Before it calls this, it'll actually take these three functions and put labels in front of them as that, to create the Observer object. It ' s normalizing it.

[RxJS] Creation Operator:create ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.