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. WPF命令

    WPF的命令是经常使用的,在MVVM中,RelayCommand更是用得非常多,但是命令的本质究竟是什么,有了事件为什么还要命令,命令与事件的区别是什么呢?MVVM里面是如何包装命令的呢?命令为什么能 ...

  2. web开发 关于src跳转

    src跳转看传递的参数值,如果参数值一样就不会再次跳转,也不会向后台的服务器提供request. 想要随时都能跳转可以传递不同的参数,如 onClick="this.src='http:// ...

  3. MFC框架类、文档类、视图类相互访问的方法

    1.获取应用程序指针 CMyApp* pApp=(CMyApp*)AfxGetApp(); 2.获取主框架指针 CWinApp 中的公有成员变量 m_pMainWnd 就是主框架的指针 CMainFr ...

  4. rhel安装eclipse

    smb --> IDE --> 环境gcc(开发c) g++(开发c++)c++操作linux --> sqlite数据库linux平台自带sqlite数据库 基本SQL语言划分:D ...

  5. css命名为何不推荐使用下划线_

    一直习惯了在命名CSS样式名时使用下划线“_”做为单词的分隔符,这也是在写JS时惯用的写法. 用过CSS hack的朋友应该知道,用下划线命名也是一种hack,如使用“_style”这样的命名,可以让 ...

  6. SxsTrace工具使用方法(转)

    http://blog.sina.com.cn/s/blog_494e45fe0102dtt3.html Windows7平台上有一个强大的SxsTrace工具,可以跟踪调试应用程序运行时需要的动态库 ...

  7. Linux(Debian)上安装Redis教程

    -- 第一步下载文件到该目录 cd /usr/local/src wget http:.tar.gz 解压 tar xzf redis.tar.gz -- 第二步编译安装 make make all ...

  8. 15 3Sum(寻找三个数之和为指定数的集合Medium)

    题目意思:给一个乱序数组,在里面寻找三个数之和为0的所有情况,这些情况不能重复,增序排列 思路:前面2sum,我用的是map,自然那道题map比双指针效率高,这道题需要先排序,再给三个指针,i.j.k ...

  9. 面向对象设计模式之Interpreter解释器模式(行为型)

    动机:在软件构建过程中 ,如果某一特定领域的问题比较复杂,类似的模式不断重复出现,如果使用普通的编程方式来实现将面临非常频繁的变化.在这种情况下,将特定领域的问题表达为某种语法规则的句子,然后构建一个 ...

  10. Tomcat基础教程(三)

    Tomcat中的Web应用 Web应用就是具有特定目录结构的目录和文件. 基于JAVA技术开发的Web应用中通常会包含以下的web对象: 静态文件对象:HTML页面,图片,普通文件 Servlet: ...