I am trying to return the result of a forkJoin
in my effect using ngrx store, like this pseudocode demonstrates:
@Effect()
someEffect$: Observable<Action> = this.action$.pipe(
ofType<SomeActionType>(ActionTypes.SomeActionType),
switchMap((action: any) =>
this.http.get<any>('some/url').pipe(
map(someResult => {
// this implementation is unimportant, just the gist of the flow I'm after
const potentialResults = oneOrMany(someResult);
if( potentialResults.length === 1 ) {
return new SomeAction(potentialResults[0]);
} else {
observables: Observable<any> = getObservables(someResult);
forkJoin(observables).subscribe((result) =>
// this is where I get stuck
return new SomeAction(result);
)
}
}
))
)
How can I synchronously return an action from the result of a forkJoin
like this? At the moment, I'm dispatching an action directly to the store within the forkJoin
block, but this is rather smelly and I would like to know how I can return this action within the forkJoin
block, using another operator such as map
or something along those lines. Any ideas?
return forkJoin(...).map(result => new SomeAction(result))
– martinreturn
is within the map, and not outside of theforkJoin
block – serlingpa