There are two variables depending on each other (color and pictures). Depending means following: When the variable color has the value of'BLUE' I want to filter all the pictues which have the color blue and so on. Variable pictures is a subject with a service/backend call:
this.colorSubject.subscribe((color) => {
subject.switchMap((searchTerm: string) => serviceCall(searchTerm, color) ).subsribe(...)
});
For that I need to listen for the change of the color variable and then calling the above line of code. But this causes multiple calls of the service.
Any ideas how to handle this issue?
If I am understanding you correctly, you need a third stream that represents the joined result of
color
andpictures
. Let's call itfilteredPictures$
. That stream should utilizecolor
andpictures
usingcombineLatest
. Now, if either of the streams change,filteredPictures$
will notify all subscribers of the new value.