通过ngrx / effects根据条件调度操作

时间:2018-02-08 09:13:32

标签: javascript angular ngrx ngrx-effects

我创建了一个注册用户的效果,但是当我尝试向现有用户注册时,它会调度成功动作。

显然,我想根据我在后端success: false or success: true的条件发送失败动作。另外,我能通过效果两次调度失败动作吗?

效果如下:

 @Effect() register$: Observable<Action> = this.actions$
        .ofType(fromActions.REGISTER)
        .pipe(
        map((action: fromActions.Register) => action.payload),
        switchMap(user => {
            return this.authService.RegisterUser(user)
        }))
        .pipe(
        map(message => ({ type: fromActions.REGISTER_SUCCESS, payload: message })),
        catchError(err => {
            return Observable.of({ type: fromActions.REGISTER_FAILURE, payload: err })
        }));

Here is the payload:

0 个答案:

没有答案