0

我正在尝试基于注销重置我的 redux-store,但出现以下错误。寻找更好的建议来重置我的 redux-store 状态,以便在我发现将其设置为 undefined 的任何地方都会有所帮助,但在我的情况下它不起作用。

    /**
 * Our state is composed of a map of action reducer functions.
 * Here we are going to reset the state of root reducer to undefined to clear data store
 * Logged Action is triggered from User session effects.
 */
export function resetState(reducer: ActionReducer<State>): ActionReducer<State> {
  return function (state: State, action: UserSessionActions.UserSessionActionsUnion): State {

    switch (action.type) {
      case UserSessionActions.UserSessionActionTypes.LoggedOut: {
        state = undefined;
        return reducer(state, action);
      }
      default: {
        return reducer(state, action);
      }
    }
  };
}

但得到这个例外

ERROR Error: Effect "UserSessionEffects.logout$" dispatched an invalid action: [object Object]
at reportInvalidActions (effects.es5.js:236)
at verifyOutput (effects.es5.js:214)
at MapSubscriber.project (effects.es5.js:284)
at MapSubscriber._next (map.js:79)
at MapSubscriber.Subscriber.next (Subscriber.js:90)
at SwitchFirstMapSubscriber.notifyNext (exhaustMap.js:113)
at InnerSubscriber._next (InnerSubscriber.js:23)
at InnerSubscriber.Subscriber.next (Subscriber.js:90)
at MapSubscriber._next (map.js:85)
at MapSubscriber.Subscriber.next (Subscriber.js:90)

这是我的效果

    @Effect()
  logout$ = this.actions$.pipe(
    ofType(UserSessionActions.UserSessionActionTypes.LoggedOut),
    map((action: any) => {
      this.logger.log('logout ' + JSON.stringify(action));
      return Observable.of({});
    }),
    catchError((err) => {
      this.logger.log(err);
      return Observable.of();
    })
  );
4

1 回答 1

2

ERROR 错误:效果“UserSessionEffects.logout$”调度了无效操作

一个ngrx/效果必须返回一个动作(一个具有类型属性的对象),除非它被修饰为@Effect({dispatch: false}).

更新你的效果以返回一个动作:

return Observable.of({ type: 'LOGGED OUT SUCCESS'});
于 2019-04-01T20:58:45.913 回答