[RxJS] Creation operator: create()
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()的更多相关文章
- [RxJS] Creation operator: of()
RxJS is a lot about the so-called "operators". We will learn most of the important operato ...
- rxjs自定义operator
rxjs自定义operator
- [RxJS] Creation operators: from, fromArray, fromPromise
The of() operator essentially converted a list of arguments to an Observable. Since arrays are often ...
- [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 ...
- [RxJS] Connection operator: multicast and connect
We have seen how Subjects are useful for sharing an execution of an RxJS observable to multiple obse ...
- [RxJS] Transformation operator: repeat
Operator repeat() is somewhat similar to retry(), but is not for handling operators. In this lesson ...
- [RxJS] Transformation operator: buffer, bufferCount, bufferTime
This lesson will teach you about another horizontal combination operator: buffer and its variants. B ...
- [RxJS] Transformation operator: scan
All of the combination operators take two or more observables as input. These operators may also be ...
- [RxJS] Combination operator: withLatestFrom
Operator combineLatest is not the only AND-style combinator. In this lesson we will explore withLate ...
随机推荐
- SQL 查询的执行过程
所述内容均来自互联网,文章仅作为学习笔记,备忘使用. 有时候我在想我们总是在谈优化,FA 优化结构.优化框架.优化程序…,可是我真的了解将要进行的操作[优化]吗?以最近我的工作-优化SQL为例,我真的 ...
- 【转】 iOS学习之sqlite的创建数据库,表,插入查看数据
原文: http://blog.csdn.net/totogo2010/article/details/7702207 iOS sqlite数据库操作.步骤是: 先加入sqlite开发库libsql ...
- Hibernate中session的产生的方式
* session的产生的方式 * 1. sessionFactory.openSession 每次都会新创建一个session,只要新创建一个session,hiber ...
- 你好,C++(7)第三部分 C++世界众生相 3.2.1 变量的定义与初始化
第3部分 C++世界众生相 在听过了HelloWorld.exe的自我介绍,完成了与C++世界的第一次亲密接触后,大家是不是都急不可待地想要一试身手,开始编写C++程序了呢?程序的两大任务是描述数据和 ...
- sae crop 文档
原文是google缓存:http://webcache.googleusercontent.com/search?q=cache:MD_FP-G6RI8J:sae.sina.com.cn/%3Fm%3 ...
- jQuery banner 滑动
jQuery(document).ready(function() { var abovePos = 50; var customMax = 1600; var zIdx = 100; var $bn ...
- 如何让Hadoop运行得更快一些
在数据处理方面,我们发现数据输入速度一般要比的数据处理速度快很多,这种现象在大多数据领域尤为明显.随着数据不断膨胀,相应的响应时间自然要有所增加,数据处理的复杂度也在不断提高.作为一个开发者,我们自然 ...
- (转)Android Studio系列教程一下载与安装 背景Android Studio VS Eclipse准备下载创建HelloWorld项目
背景 相信大家对Android Studio已经不陌生了,Android Studio是Google于2013 I/O大会针对Android开发推出的新的开发工具,目前很多开源项目都已经在采用,Goo ...
- Linq学习系列
LINQ之路系列博客导航 http://www.cnblogs.com/lifepoem/archive/2011/12/16/2288017.html LINQ体验系列文章导航 http://www ...
- js中定义变量加var与不加var的区别?
var 不一定是用来定义局部变量的 jscript的全局变量和局部变量的分界是这样的: 过程体(包括方法function,对象Object o ={})外的所有变量不 ...