I am trying to create an @Effect() for my action. When I run action with type AuthenticationUserLoad I get an error.
ERROR Error: Effect "AuthenticationEffects.getUser$" dispatched an invalid action: [object Object]
Here is my Effect code
@Effect()
getUser$ = this.actions$.pipe(
ofType(AuthenticationUserActions.AuthenticationUserTypes.AuthenticationUserLoad),
map((action) => {
return this.authService.getUser().pipe(
map((user: User) => new AuthenticationUserActions.AuthenticationUserLoadSuccess({user})),
catchError(error => of(new AuthenticationUserActions.AuthenticationUserLoadFailure({error})))
);
})
);
UPDATE
I changed map to switchMap and it works.
@Effect()
getUser$ = this.actions$.pipe(
ofType(AuthenticationUserActions.AuthenticationUserTypes.AuthenticationUserLoad),
switchMap((action) => {
return this.authService.getUser().pipe(
map((user: User) => new AuthenticationUserActions.AuthenticationUserLoadSuccess({user})),
catchError(error => of(new AuthenticationUserActions.AuthenticationUserLoadFailure({error})))
);
})
);
Maybe I dont understand the difference between map and switchMap.
AuthenticationUserActions- You NguyengetUser$. For example:getUser$: Observable<Action> =...- Jota.Toledo