重置 - Redux抛出调度的无效操作:undefined

问题描述 投票:0回答:1

我正在尝试基于注销重置我的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();
    })
  );
redux ngrx ngrx-store ngrx-effects ngrx-entity
1个回答
2
投票

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

ngrx / effect必须返回一个动作(一个具有type属性的对象),除非它被装饰为@Effect({dispatch: false})

更新效果以返回操作:

return Observable.of({ type: 'LOGGED OUT SUCCESS'});
© www.soinside.com 2019 - 2024. All rights reserved.