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

The create function:

var foo = Rx.Observable.create( function(observer){
observer.next();
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 foo = 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 foo = new Rx.Observable( subscribe );

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

function subscribe(observer){
observer.next();
observer.next();
observer.next();
observer.complete();
} var observer = {
next: (x)=>{console.log('next ' + x);},
error: (err)=>{console.log('err ' + err);},
complete: ()=>{console.log('done');}
} subscribe(observer);

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

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

[RxJS] Creation operator: create()的更多相关文章

  1. [RxJS] Creation operator: of()

    RxJS is a lot about the so-called "operators". We will learn most of the important operato ...

  2. rxjs自定义operator

    rxjs自定义operator

  3. [RxJS] Creation operators: from, fromArray, fromPromise

    The of() operator essentially converted a list of arguments to an Observable. Since arrays are often ...

  4. [RxJS] Using Observable.create for fine-grained control

    Sometimes, the helper methods that RxJS ships with such as fromEvent, fromPromise etc don't always p ...

  5. [RxJS] Connection operator: multicast and connect

    We have seen how Subjects are useful for sharing an execution of an RxJS observable to multiple obse ...

  6. [RxJS] Transformation operator: repeat

    Operator repeat() is somewhat similar to retry(), but is not for handling operators. In this lesson ...

  7. [RxJS] Transformation operator: buffer, bufferCount, bufferTime

    This lesson will teach you about another horizontal combination operator: buffer and its variants. B ...

  8. [RxJS] Transformation operator: scan

    All of the combination operators take two or more observables as input. These operators may also be ...

  9. [RxJS] Combination operator: withLatestFrom

    Operator combineLatest is not the only AND-style combinator. In this lesson we will explore withLate ...

随机推荐

  1. 删除重复记录的SQL语句

    1.所有字段均重复的记录(重复记录保留一条) Select distinct * into #Tmp from tblName Drop table tblName Select * into tbl ...

  2. sql 列轉行、行轉列

    PIVOT用于将列值旋转为列名(即行转列),在SQL Server 2000可以用聚合函数配合CASE语句实现 PIVOT的一般语法是:PIVOT(聚合函数(列) FOR 列 in (…) )AS P ...

  3. Python Function Note

    Python Function Note #汉诺塔问题Python实现 def my_move(n, a, b, c): if n == 1: print(a + ' --> ' + c) el ...

  4. bootstrap首页制作

    <!DOCTYPE html><html><head> <meta charset="utf-8"> <title>我的 ...

  5. Spring4.0学习笔记(9) —— Spring泛型依赖注入

    1.定义基础仓库 package com.spring.generic.di; public class BaseRepository<T> { } 2.定义基础服务层 package c ...

  6. 将与系统时间格式不同的字符串格式化为DATETIME类型

    若系统时间格式为2012/03/05 08:12:12,那么若将("2012-03-05 08:12:12")格式化为时间变量时会报错,在转化之前先将系统时间格式改变再转换就不会报 ...

  7. oracle创建表空间、用户、用户授权、删除表空间、删除用户

    --创建临时表空间 create temporary tablespace test_temp --test_temp表空间名称 tempfile 'E:\oracle\product\10.2.0\ ...

  8. angularJS内置指令一览

    基础ng指令 ng-href ng-src ng-disabled ng-readonly ng-checked ng-selected ng-class ng-style ng-show ng-hi ...

  9. 安卓环境搭建(1)hellow world

    本系列适合0基础的人员,因为我就是从0开始的,此系列记录我步入Android开发的一些经验分享,望与君共勉!作为Android队伍中的一个新人的我,如果有什么不对的地方,还望不吝赐教. 在开始Andr ...

  10. Google Protocal Buffer

    Google Protocal Buffer 是一种轻便高效的结构化数据存储格式,可以用于结构化数据串行化或者说序列化.它很适合做数据存储或RPC数据交换格式. 串行化(序列化):将对象存储到解释中式 ...