rxjs里withLatestFrom operators的用法
生活随笔
收集整理的这篇文章主要介绍了
rxjs里withLatestFrom operators的用法
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
Combines the source Observable with other Observables to create an Observable whose values are calculated from the latest values of each, only when the source emits.
上图说明:从时间轴上看,source
Observable emit value a时,没有其他输入的Observable,因此value a被discard;emit b时,其他Observable最新的值为1,因此最后output为b1;对c,d,e来说,另一个Observable最新的值为4,因此最后的值为c4,d4和e4.
看个例子:
const clicks = fromEvent(document, 'click'); const timer = interval(1000); const result = clicks.pipe(withLatestFrom(timer)); result.subscribe(x => console.log('diablo : ' + x));输出:
如果我们把另一个Observable emit值也打印出来,就能看得更清楚:
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
总结
以上是生活随笔为你收集整理的rxjs里withLatestFrom operators的用法的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 只狼商人黑笠在哪 只狼黑笠之狸位置一览
- 下一篇: rxjs里debounceTime op