前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >rxjs里withLatestFrom operators的用法

rxjs里withLatestFrom operators的用法

作者头像
Jerry Wang
发布2020-10-27 15:06:05
8380
发布2020-10-27 15:06:05
举报

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.

看个例子:

代码语言:javascript
复制
const clicks = fromEvent(document, 'click');
const timer = interval(1000);
const result = clicks.pipe(withLatestFrom(timer));
result.subscribe(x => console.log('diablo : ' + x));

输出:

如果我们把另一个Observable emit值也打印出来,就能看得更清楚:

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-10-18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档