Attempting to understand the correct approach in RxJs, as I am relatively new to it. My goal is to create an Observable array of Observables.
I aim to fetch a list of User's Posts with each Post being an Observable. These individual Post Observables should be stored in an Observable array so that any changes to the array can notify the calling code and update all subscriptions related to the post "list". While this task seems straightforward, I also require each Post to itself be an Observable for subscribing to individual objects like posts[i]. What would be the best practice to achieve this?
My current setup involves Angular 9:
public getPosts(): Observable<Array<Post>> {
return new Promise((resolve, reject) = {
let posts: Observable<Array<Post>> = new Observable<Array<Post>>();
this.get<Array<Post>>('posts').subscribe(r => {
posts = from(r);
return resolve(posts);
});
});
}
This code provides an
Observable<Array<Post>>
, but how can I generate an Observable<Array<Observable<Post>>>
? Is this considered an anti-pattern?