zoukankan      html  css  js  c++  java
  • [RxJS] Logging a Stream with do()

    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.

  • 相关阅读:
    CSS3旋转动画
    CSS3的动画属性
    CSS选择器
    JS事件委托
    js 轮播图效果
    JS事件冒泡和事件捕获
    JS自定义播放器
    js闭包for循环只执行最后一个值得解决方法
    交通红绿灯
    汉明距
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5267227.html
Copyright © 2011-2022 走看看