This lesson introduces operators empty(), never(), and throw(), which despite being plain and void of functionality, are very useful when combining with other Observables.

empty:

var foo = Rx.Observable.empty();
// the same as
var foo = Rx.Observable.create( function(observe) {
observe.complete();
}) foo.subscribe(function (x) {
console.log('next ' + x);
}, function (err) {
console.log('error ' + err);
}, function () {
console.log('done');
}); //done

never(): do nothing

var foo = Rx.Observable.never();
// the same as
var foo = Rx.Observable.create( function(observe) {
}) foo.subscribe(function (x) {
console.log('next ' + x);
}, function (err) {
console.log('error ' + err);
}, function () {
console.log('done');
});

throw(): throw a Javascript error

var foo = Rx.Observable.throw(new Error('blooom'));
// the same as
var foo = Rx.Observable.create( function(observe) {
observe.error('bloom');
}) foo.subscribe(function (x) {
console.log('next ' + x);
}, function (err) {
console.log('error ' + err);
}, function () {
console.log('done');
});

[RxJS] Creation operators: empty, never, throw的更多相关文章

  1. [RxJS] Creation operators: interval and timer

    It is quite common to need an Observable that ticks periodically, for instance every second or every ...

  2. [RxJS] Creation operators: fromEventPattern, fromEvent

    Besides converting arrays and promises to Observables, we can also convert other structures to Obser ...

  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] Creation operator: of()

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

  5. [RxJS] Creation operator: create()

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

  6. [RxJS] Transformation operators: debounce and debounceTime

    Debounce and debounceTime operators are similar to delayWhen and delay, with the difference that the ...

  7. [RxJS] Transformation operators: delay and delayWhen

    This lessons teaches about delay and delayWhen: simple operators that time shift. delay(number | dat ...

  8. [RxJS] Filtering operators: takeLast, last

    Operators take(), skip(), and first() all refer to values emitted in the beginning of an Observable ...

  9. [RxJS] Filtering operators: take, first, skip

    There are more operators in the filtering category besides filter(). This lesson will teach how take ...

随机推荐

  1. js删除数组指定的某个元素

    1.给js数组对象原型加indexof方法 获得元素索引 Array.prototype.indexOf = function(val) { for (var i = 0; i < this.l ...

  2. 数据类型的转换String

    x.toString(): 无法转换null和undefined 不过String()却是万能的,其中的原理如下 function String(x){ if(x===undefined){ retu ...

  3. sql注释

    一般使用数据库客户端软件是navicat,上面写sql用的注释符号一般是“#”或者“/* */”,比如: #我是注释 /*我是注释*/ 记得之前看别人sql里用“--”作为注释符号,结果我今天也试了一 ...

  4. javascript 常用array类型方法

    concat:基于当前数组中的所有项创建一个新数据,会创建当前数组一个副本,然后将接受到的参数放到数组末尾,最后返回新数组.如果没有参数,则复制当前数组并返回副本. slice:基于当前数组中一个或多 ...

  5. ExtJS智能提示工具spket安装与破解

    用myeclipse写java程序,最怕的是什么呢,写javascript代码,原因很简单,没有智能提示,ExtJS是完全js代码的界面库,写起来就更痛苦了,幸好有人做了spket插件,此文采用傻瓜式 ...

  6. 利用GDB在远程开发机进行调试

    由于一些环境的制约,很多同学都可能需要在开发机上进行调试,但由于开发机资源的限制,在开发机上直接进行本地的GDB环境配置就成了难题,这个时候其实我们可以利用GDB中自带的gdbserver工具就可以进 ...

  7. WebApi 4.0 默认方式不支持HttpGet 请求

    如果Controller方法中没有指定请求方式,在RC版本中默认是HttpPost ,Beta版本中支持所有方法GET, PUT, POST and Delete,而在RC版本后做了改变只支持Http ...

  8. Dapper inner join

    Dapper中的一些复杂操作和inner join应该注意的坑 上一篇博文中我们快速的介绍了dapper的一些基本CURD操作,也是我们manipulate db不可或缺的最小单元,这一篇我们介绍下相 ...

  9. Egret 矢量绘图、遮罩、碰撞检测

    矢量绘图: 1. 为矢量绘图绘制外边 - graphics.lineStype() private createGameScene():void { console.log("Runtime ...

  10. 后端推送给app等发生错误如何处理

    今天有人问了这样一个问题..当比如说Android客户不能看到后台返回的错误..这样用户看着是什么感觉.然后我直接答的都不是同一个东西.默默地反省了一下. 其实就是try{}..catch{} 啊.. ...