I'm struggling with getting a function to properly return. There's a condition where I want it to return an Observable, and another condition where I'd like it to return the combined results of two observables.
Here is an example.
getSearchFeed(): Observable<items[]> {
if (this.condition) {
return this.populateItemsArray(); //function Returns Items Array Observable
}
//second condition
const someItems = this.populateSearch(); //function Returns Items Array Observable
const otherItems = this.populateOtherSearch(); //function Returns Items Array Observable
return forkJoin(someItems,otherItems)
.pipe((res:Array) => {
return [...res[0],...res[1]];
});
}
I've seen discussions about merging results from different observables, which I understand how to do by subscribing and joining. My question is more focused on how to return an Observable for the second condition.
Here are some things I've tried,
return forkJoin(someItems,otherItems)
.pipe(map((res:Array<Observerable<Items[]>>) => {
return [...res[0],res[1]];
});
and
const source = of([someItems,otherItems]);
const merged = source.pipe(mergeMap( q => forkJoin(...q)));
return merged;