[RxJS] Logging a Stream with do()
with stream Rxjs Do logging
2023-09-14 08:59:20 时间
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.
相关文章
- [Tools] Package Your node.js Projects Into a Standalone Applications with pkg
- [Typescript] Make TypeScript Class Usage Safer with Strict Property Initialization
- [RxJS] ReplaySubject with buffer
- [RxJS] Toggle A Stream On And Off With RxJS
- [RxJS] Completing a Stream with TakeWhile
- [Redux] Avoiding Array Mutations with concat(), slice(), and ...spread
- [DevOps] Environment Variables with Travis
- [Javascript] Construct a Regex to Match Twitter Mentions with Regexr
- [Recompose] Stream Props to React Children with RxJS
- [Node.js] Use nodejs-dashboard event loop delay with hrtime()
- [RxJS] Starting a Stream with SwitchMap & switchMapTo
- 已解决 You can enable repos with yum-config-manager --enable <repo>