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

[RxJS] Utility operator: do

时间:2016-05-24 22:20:18      阅读:283      评论:0      收藏:0      [点我收藏+]

标签:

We just saw map which is a transformation operator. There are a couple of categories of operators, such as filtering, combination, flattening, etc. One of these categories is the utility operators. The most important utility operator is do, useful for debugging.

 

var foo = Rx.Observable.interval(200).take(4);

/*
foo: ---0---1---2---3--...
      do(x => console.log(‘before ‘ + x))
     ---0---1---2---3--...
       map(x => x * 2)
     ---0---2---4---6--...
      do(x => console.log(‘after ‘ + x))
     ---0---2---4---6--...
*/

var bar = foo
  .do(x => console.log(‘before ‘ + x))
  .map(x => x * 2)
  .do(x => console.log(‘after ‘ + x));

bar.subscribe(
  function (x) { console.log(‘next ‘ + x); },
  function (err) { console.log(‘error ‘ + err); },
  function () { console.log(‘done‘); },
);

 

[RxJS] Utility operator: do

标签:

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

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