首页 > Web开发 > 详细

[RxJS] Logging a Stream with do()

时间:2016-03-11 22:02:29      阅读:282      评论:0      收藏:0      [点我收藏+]

To help understand your stream, you’ll almost always want to log out some the intermediate values to see how it has progressed during its lifespan. This lesson teaches you how to use do to log values in the middle of the stream without having an impact on the rest of the stream.

 

Observable.combineLatest(
    timer$.do((x)=> console.log(x)),
    input$.do((x)=> console.log(x)),
    (timer, input)=> ({count: timer.count, text: input})
)
    .takeWhile((data)=> data.count <= 3)
    .filter((data)=> data.count === parseInt(data.text))
    .do(()=>{console.log("score!!")}) 
    .reduce((acc, curr)=> acc + 1, 0)
    .subscribe(
        (x)=> console.log(x),
        err=> console.log(err),
        ()=> console.log(complete)
    );

 

We put servel do() block in the code, it doesn‘t affect any logic, just simply loggout what we want to see, so it is good when we want to debug the stream.

[RxJS] Logging a Stream with do()

原文:http://www.cnblogs.com/Answer1215/p/5267227.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!