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. 三、T4模板与实体生成

         上文我们最后虽然用模板创建了一个实体类,但是类的内容仍旧是静态的,这里我们需要用动态方式生成类的内容.因为需要查询数据库这里又免不了各种繁琐的连接数据库操作,为了使我们的编码更加直观,仍然采 ...

  2. oracle事务特性详解

    原子性 事务是一个完整的操作.事务的各步操作是不可分的(原子的):要么都执行,要么都不执行. -- 创建表 create table account_money ( id number(4) not ...

  3. Oracle10g、 Oracle11g完美共存

    Oracle10g. Oracle11g完美共存           环境描述 客户服务器上已经安装Oracle9i软件并部署多套数据库,现在客户要求安装Oracle11g软件,并且创建11g数据库, ...

  4. iOS开发网络资源整理-持续更新

    本文记录iOS开发相关的网络社区和博客 1.objc中国 网址:http://objccn.io 简介:onevcat创建,项目的成立源于国内 Objective-C 社区对 objc.io 的翻译活 ...

  5. cas sso单点登录系列2:cas客户端和cas服务端交互原理动画图解,cas协议终极分析

    转:http://blog.csdn.net/ae6623/article/details/8848107 1)PPT流程图:ppt下载:http://pan.baidu.com/s/1o7KIlom ...

  6. ERROR:the server has either erred or is incapable of performing the requested operation

    openstack中,有时会经常出现这种错误,原因无二,一是安全组没有设置正确,二是openstack中网络配置会有些问题或者是相关的服务没有启动. 解决方法:1.安全组问题在nova.conf和ne ...

  7. 225 Implement Stack using Queues(用队列实现栈Medium)

    题目意思:用队列实现栈,push(),pop(),top(),empty() 思路:用两个queue,pop时将一个queue的元素pop再push到另一个队列,queue只留最后一个元素,并pop, ...

  8. JS操作性能优化

    1. 适当使用变量 Maybe document.getElementById("myField").style.backgroundColor = "#CCC" ...

  9. android 模拟微信消息 OnItemClickListener()方法 [3]

    在 http://www.cnblogs.com/Seven-cjy/p/6101555.html 是基础上修改 MainActivity.java /winxinmff/src/com/exampl ...

  10. infinitescroll 通过无限制分页(json方式完整代码)

    @{ ViewBag.Title = " ";} <style type="text/css"> #infscr-loading { text-al ...