In my scenario, I have an higher order observable which when emits we needs to fetch two different pieces of data as inner observables.
something like
$someDetails.pipe(
switchMap(sd => {
this.name = sd.name;
let innerObservableOne = getObservableOne(this.name);
let innerObservableTwo = getObservableTwo(this.name);
return {one: innerObservableOne, two: innerObservableTwo}
}).subscribe(r => ?????)
Can I get some lead on this?
Do I need to do something like this
The other option I have is to use two switchmaps one for each inner observable but that means two subscriptions which seems unnecessary.
$someDetails.pipe(
switchMap(sd => {
return getObservableOne(sd.name);
}).subscribe(.....);
$someDetails.pipe(
switchMap(sd => {
return getObservableTwo(sd.name);
}).subscribe(.....);
Edit1:
Any issues with following code:-
What about the following code.
details$ = $someDetails.pipe(share());
details$.pipe(switchMap(sd => getObservableOne(sd.name)).subscribe(...);
details$.pipe(switchMap(sd => getObservableTwo(sd.name)).subscribe(...);
Any thoughts or issues you see with this solution ?