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.

  • 相关阅读:
    APIO2018 题解
    【THUWC2017】在美妙的数学王国中畅游(bzoj5020)
    【bzoj3270】博物馆
    【库存】NOI笔试习题集
    装饰器
    异常
    类的详解
    函数
    流程控制
    运算符
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5267227.html
Copyright © 2011-2022 走看看