您的位置:首页 > Web前端 > JavaScript

[RxJS] Utility operator: do

2016-05-24 20:45 453 查看
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'); },
);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: