我想了解effects
NgRX 6
我有一个示例效果:
@Effect()
createNonce$: Observable<Action> = this.actions$.pipe(
ofType(INVALID_SESSION),
map(() => generateNonce(32)),
map(nonce => of(this.store.dispatch(new IdentityRedirect(nonce)))),
catchError(error => of(console.error(error)))
);
我想要实现的是
INVALID_SESSION
generateNonce
并返回结果我收到以下错误
[ts]
Type 'Observable<void | Observable<void>>' is not assignable to type 'Observable<Action>'.
Type 'void | Observable<void>' is not assignable to type 'Action'.
Type 'void' is not assignable to type 'Action'.
答案 0 :(得分:0)
@Effect()
createNonce$: Observable<Action> = this.actions$.pipe(
ofType(INVALID_SESSION),
mergeMap(() =>
of(generateNonce(32)).pipe(
map(nonce => ({ type: REDIRECT_TO_LOGIN, payload: nonce }))
)
),
catchError(error => of({ type: REDIRECT_TO_LOGIN_FAILURE, payload: error }))
);