I am managing a subject that consumers subscribe to:
private request$: Subject<Service> = new BehaviorSubject(null);
Upon initialization, my components utilize this function:
public service(id: number): Observable<Service> {
return this.request$
.pipe(
switchMap((request) => request && request.serviceId ? of(request) : this.requestById(id)));
}
and make a service call:
private requestById(serviceId: number): Observable<Service> {
// http call
}
Various components invoke this function with different id
s. I want to update the subject if the incoming id
parameter value does not match the current subject's id
value.
Is it possible to achieve this? I came across an iif
function, but I'm unsure if it's the right fit for me.
Thank you