I'm trying to process data returned from the first API call using NgRx effects.
fetchPages$ = createEffect(() =>
this._actions$.pipe(
ofType(FETCH_PAGES),
switchMap(() => this._confApi.getPages()
.pipe(
map(pages => {
pages.forEach(page => {
this._confApi.getPageVersion(page.url).pipe(map(version => page.version = version));
});
return pages;
}),
map(pages => SAVE_PAGES({pages}))
)
)
)
);
But in this case the API call in the first map isn't even called. I also tried this way:
fetchPages$ = createEffect(() =>
this._actions$.pipe(
ofType(FETCH_PAGES),
switchMap(() => this._confApi.getPages()
.pipe(
map(pages => {
pages.forEach(page => {
this._confApi.getPageVersion(page.url).subscribe(version => page.version = version);
});
return pages;
}),
map(pages => SAVE_PAGES({pages}))
)
)
)
);
And while it does the call, the value isn't added to page property (map to SAVE_PAGES doesn't actually wait).
What is the right way to approach this problem?