组合主题而无需等待每个主题
我有4个主题在用户输入上散发值
this.combine$ = zip(
this.filterInputStore.selectedCurrenciesHandler,
this.filterInputStore.searchInputHandler,
this.filterInputStore.selectedTypesHandler,
this.filterInputStore.selectedPrivacyOptionsHandler
).pipe(tap(() => { doSomething() }));
我的目标是触发dosomething(),一旦其中一个发出值。
问题:所有RXJS运算符(例如zip或CombineLatest)都需要等到所有受试者发出。如果我想过滤列表并想要结果,这是非常不切实际的,即使我只使用一个过滤器。 有RXJS的最佳实践吗?
I Have 4 Subjects that emit values on user Input
this.combine$ = zip(
this.filterInputStore.selectedCurrenciesHandler,
this.filterInputStore.searchInputHandler,
this.filterInputStore.selectedTypesHandler,
this.filterInputStore.selectedPrivacyOptionsHandler
).pipe(tap(() => { doSomething() }));
My Goal is to trigger the doSomething(), as soon as one of them emits a value.
Problem: All rxjs operators like zip or combineLatest require to wait until all subjects in it emit. This is extremely impractical if say i want to filter a list and want results even if i only use one filter.
Is there a rxjs best practise for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信
合并
或race
都可以使用。我更喜欢race
,因为该方法表明您正在等待第一个可观察到的发射(并赢得比赛!)。另外,race
只会触发一次,因此您的dosomething
不会多次执行。I believe both
merge
orrace
would work. I preferrace
because the method indicate that you're waiting for the first observable to emit (and win the race!). Also,race
will trigger only ONCE, so yourdoSomething
won't get executed multiple times.