码迷,mamicode.com
首页 > Web开发 > 详细

[RxJS] Creation operators: empty, never, throw

时间:2016-04-14 06:44:02      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:

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

标签:

原文地址:http://www.cnblogs.com/Answer1215/p/5389550.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!