A very common problem when using RxJs seems to be to want the result of one or more observables to then use them in subsequent ones.
e.g. in pseudo-code (This is not rx or valid js syntax deliberately)
var someResult = $observable-A; // wait to complete
var finalResult = $observable-B(someResult.aValueINeed);
This can be done in an ugly way where you could subscribe to both and call one inside the other.. however, this is very messy and doesn't afford you much flexibility.
e.g. (real syntax)
$observable-A.subscribe(resultA => {
$observable-B(resultA.aValueINeed)
.subscribe(resultB => {
console.log('After everything completes: ', resultB);
}
}
This also means that nothing else can easily consume this stream as you're completing both of the observables.
My specific use case requires the following:
- An initial call to get $observable-A as it doesn't require anything else (it's a basic http GET call)
- An http GET call to another service that requires data from $observable-A, which returns $observable-B
- Using both observable results (A + B) to create an object for my service (In my case, an Angular service) to return a single list.
I also need to be able to subscribe to this function inside my service, this is why going with the subscribe method above, won't work for me.