Consider this particular case involving TypeScript/angular with rxjs 6.5:
main(){
const items = ['session', 'user'];
const source: Observable<any> = from(items);
source
.pipe(
mergeMap(key => this.getKey().map((value) => ({key: key, value: value}))),
tap((result) => {
// forwarding the result elsewhere;
}),
).subscribe(
(result) => {
console.log('Final outcome ->', result);
}
);
console.log('\n');
}
getKey(): Observable<any> {
// Dummy function that generates an observable outputting a single value
const observable = from(['test']);
return observable;
}
The current output obtained is:
Final outcome -> {key: "session", value: "test"}
Final outcome -> {key: "user", value: "test"}
1st inquiry: How can I neatly acquire, upon subscribing to the source, just one value that combines results from inner observables?
I envision my desired output, following this manner of subscription (as the combined action should be within the pipeline), to look like:
(...).subscribe(
(result) => {console.log('Final Result:', result}
)
OUTPUT:
Final outcome -> [{key: "session", value: "test"}, {key: "user", value: "test"}]
2nd question: If disregarding the outcomes of inner observables, how do I obtain just one value or determine completion of all inner observables?
Your assistance is greatly appreciated.