Apologies for bombarding you with more questions recently, but I'm really struggling to understand how everything links together.
Currently, a user is utilizing promise-based storage to store the names of feeds they wish to filter out. The Social Feeds widget displays the latest article from each feed that hasn't been hidden by the user.
I want to create a combination of the predefined list of feeds and the user's filtered feeds. To interact with the given API, I have to make multiple calls to the service to fetch each feed individually.
Once I've combined these feeds, my goal is to sequentially merge the observable produced by the getFeed
utility method.
This is roughly what I intend to do, outlined in pseudocode:
/**
* Retrieves the top items from all social media sources.
* @param limit {number} Number of items per source.
* @returns {Observable<SocialItem[]} Stream of SocialItem arrays.
*/
public getTopStories(limit: number = 1): Observable<SocialItem[]> {
// Combine available feeds with those the user wishes to hide.
const feedsToGet = this.storage.get('hiddenFeeds')
.then(hiddenFeeds => _.union(FeedList, hiddenFeeds));
// Retrieve and map feeds into an Observable<SocialItem[]>, adjusting the list as needed due to API limitations.
// Utilize mergeMap to transform the array structure into a single array of SocialItems.
const feeds$ = feedsToGet.map(feed => this.getFeed(feed).map(res = res ? res.slice(0, limit) : []).mergeMap(val => val));
// Combine and return the streams
return Observable.combineLatest(feed$);
}
Edit: Apologies for the fragmented code earlier.