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. IOS 在Xcode 4.x以上添加静态库

    参考网站:http://my.oschina.net/edwardlau/blog/95924 常用的代码可以通过静态库进行抽出来作为公共类方法,方便在其他地方调用,一般来说我们要准备2套静态库,一套 ...

  2. 你好,C++(35)类是如何藏私房钱的?6.2.4 拷贝构造函数

    6.2.6  类成员的访问控制 类成员包括类的成员变量和成员函数,它们分别用来描述类的属性和行为.而类成员的访问控制决定了哪些成员是公开的,可以被外界访问,也可以被自身访问:哪些成员是私有的,只能在类 ...

  3. 2D简单图形相关算法罗列

    因为平常在Qt开发过程中经常会与一些简单的2D几何图形打交道,因此学习和掌握一些基本的2D几何计算还是很有必要的,在这里罗列一些常用的基本情况,之后会适时补充. [1] 两点之间距离,根据两个点的差值 ...

  4. Linq介绍

    什么是LINQ? LINQ全称Language Integrated Query,中文翻译"语言集成查询".在.NET框架中,大致使用三大组件实现这个封装,分别 LINQ to O ...

  5. z-index的理解 z-index 属性仅在节点的 position 属性为 relative, absolute 或者 fixed 时生效.

    今天做游戏的Exercise模式的时候,发现把所有的div设置为position:absolute;后,点击play进入到游戏界面的时候,鼠标点击数字的时候,完全没反应.经过我的反复检查,发现只要给所 ...

  6. 栈的讲解 和 栈的生长方向 源代码技巧分析,简直没SEI 啦

    函数的局部变量,都是存放在"栈"里面,栈的英文是:STACK.STACK的大小,我们可以在stm32的启动文件里面设置,以战舰stm32开发板为例,在startup_stm32f1 ...

  7. UVa 10020 - Minimal coverage(区间覆盖并贪心)

    Given several segments of line (int the X axis) with coordinates [Li, Ri]. You are to choose the min ...

  8. Android数据库升级、降级、创建(onCreate() onUpgrade() onDowngrade())[4]

    数据库版本升级对软件的管理操作. 我们手机经常会收到xxx软件升级什么的提醒,你的软件版本更新,同时你的数据库对应的版本也要相应的更新. 数据库版本更新需要主要的问题: 软件的1.0版本升级到1.1版 ...

  9. Hibernate的批量处理

    Hibernate完全以面向对象的方式操作数据库,当程序员以面向对象的方式操作持久化对象时,将自动转换为对数据的操作.例如我们Session的delete()方法,来删除持久化对象,Hibernate ...

  10. Lambert

    Dmap -- 贴图信息 LightColor  -- 灯光颜色 KL -- 灯光强度值(开放给美术) EnvColor -- 环境颜色 ka -- 环境光强度 (开放给美术) Dmap * (max ...