In the process of fetching all my posts, I have the code below:
` @Action(actions.FetchPosts)
fetchAll(ctx: StateContext<PostStateModel>){
return this.postService.fetchPosts().pipe(tap((postsResults) => {
const state = ctx.getState();
ctx.patchState({
...state,
posts: [
...postsResults
],
})
}),
mergeMap(() => {
console.log("Inside of mergeMap")
return ctx.dispatch(new actions.FetchPostsSuccess())
}),
catchError(err =>
{
console.log("Inside of catchError")
return ctx.dispatch(new actions.FetchPostsFail(err))
}
))
}`
Although the current implementation works, I am seeking a method to dispatch a start action before calling the post service. How can I ensure that the loading property is set to true during this initial dispatch and only call success once the request is completed successfully?
I am following the ngxs documentation and using mergeMap(), which appears to be effective. However, I would like to know whether the postService returns a single observable or a single observable with multiple inner observables.