Issue
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?
Solution
I believe both merge
or race
would work. I prefer race
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 your doSomething
won't get executed multiple times.
Answered By - Nam
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.