[RxJS] Utility operator: do

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[RxJS] Utility operator: do相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

[RxJS] What RxJS operators are

Eslint 'rxjs/operators' 应该列在项目的依赖中

[RxJS] Combination operator: withLatestFrom

[RxJS] Combination operator: zip

[RxJS] Filtering operator: filter

错误:无法解析“rxjs/add/operator/map”