@ngrx中效果中的链操作

Tan*_*may 4 rxjs redux ngrx angular

我在制作HTTP请求的效果中一个接一个地链接动作时遇到了一些麻烦.

这是效果代码:

export class UserEffects {

    @Effect()
    update$: Observable<Action> = this.actions$.ofType(user.USERCHANGE).pipe(
        switchMap(data => this.authService.login(data['payload'])),
        map(userInfo => new UserChangedAction(userInfo)),
        tap(() => this.store.dispatch(
             new LoginStateChangeAction(localStorage.getItem('token')))
        )
    );

    constructor(private authService: AuthService, private actions$: Actions,
        public store: Store<fromRoot.State>) {}
}
Run Code Online (Sandbox Code Playgroud)

问题是这两个动作是同时被调用的.LoginStateChange操作取决于要完成的UserChanged操作.

我怎样才能做到这一点?

谢谢!

tim*_*ver 5

您可以按照Austin的帖子中的说明返回多个操作:从NGRX效果调度多个操作

@Effect()
update$ = this.actions$.ofType(user.USERCHANGE).pipe(
  switchMap(data => this.authService.login(data['payload'])),
  switchMap(userInfo => [
    new UserChangedAction(userInfo),
    new LoginStateChangeAction(localStorage.getItem('token')),
  ])
);
Run Code Online (Sandbox Code Playgroud)