欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

rxjs里withLatestFrom operators的用法

发布时间:2023/12/19 编程问答 46 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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的用法的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。