I am seeking for help or a clue for an issue with rxjs that I am not able to solve.
Basically, I want to trigger an observable and complete before the original one trigger.
Case: I am working on a project in which I have two profiles, say profileA, profileB.
Sometimes profileA has some properties that I need to pass to the profileB in order to get the profileB. And at the end, I combine the both profiles and return the orignal observable.
Usually, I cache the profileA in localStorage and I can get the profileB.
getProfileB() {
const url = `${..}/xyz/${this.profileB.username}/userData`
return this.http.get(anUrl); // and returns the observale to the next destination
}
But sometimes could be that the profileA is not available in the localstorage, so in that case, first I have to find fetch the profileA and then continue with the profileB fetching.
I would like to use the following approch. Since I don't about
getProfileA() {
return this.http.get(anUrlForProfileA);
}
getProfileB() {
const url = `${..}/xyz/${this.profileB.username}/userData`
return this.http.get(anUrl).pipe(
aPipeOperator() => {
// the null could be the mean that continue with the current Observable, whereas concatenateFirst means, first completes the getProfileA observable and then continue with the original one.
return this.profileA?.username?.length > 0? concatenateFirst(this.getProfileA()) : null;
}
);
}
I am little struggling with the rxjs, and it is also difficult for me to explain, so please help me. This issue could solve me other problems too.
Thanks