清除metareducer中的存储后的ngrx链操作

时间:2018-11-27 17:43:31

标签: angular ngrx ngrx-effects

在metareducer内的应用程序中,我将在触发特定操作后清除商店。此操作只是导航到主页。问题是我无法在与此操作相关的效果内生成新令牌,因为该令牌已被此功能清除:

  return function (state: AppState, action: Action): AppState {
    if (action.type === OfferActionTypes.GoToBaseInfoPage) {
      state = undefined;
    }
    return reducer(state, action);
  };
}

我试图在导航后将一个动作链接到相关效果中,但是它不起作用:

  navigateToIndex$ = this.actions$.pipe(
    ofType(fromOfferAction.OfferActionTypes.GoToBaseInfoPage),
    tap (() => this._router.navigate(['', this.currentLang]) ),
    map(() => this._store.dispatch(new AuthenticationCustomTokenRequested()))
   );

在导航和清除完成之后,是否可以启动操作以获取新令牌?

谢谢

1 个答案:

答案 0 :(得分:0)

1-使用效果在注销和导航后调度新动作(例如NEW_ACTION)

 @Effect()
  logout$ = this.actions.ofType(fromActions.LOGOUT).pipe(
    switchMap(() =>
      fromPromise(this.service.signOut()).pipe(
        map(() => new NewAction()),
        catchError(err =>
          of(new AuthError(err)))
        )
      )
    )
  );

2-从

更新代码
    if (action.type === OfferActionTypes.GoToBaseInfoPage) {

    if (action.type === OfferActionTypes.NEW_ACTION) {