Я пытаюсь создать @Effect()
для своего действия.Когда я запускаю действие с типом AuthenticationUserLoad
, я получаю сообщение об ошибке.
ERROR Error: Effect "AuthenticationEffects.getUser$" dispatched an invalid action: [object Object]
Вот мой Effect
код
@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})))
);
})
);
ОБНОВЛЕНИЕ
Я изменил map
на switchMap
, и это работает.
@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})))
);
})
);
Может быть, я не понимаю разницу между map и switchMap.