1

I am trying to reset my redux-store on based of logout, but getting following error. Looking for better suggestion to reset my redux-store state so as everywhere I found to set it to undefined will help the case, but in my case it is not working.

    /**
 * 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);
      }
    }
  };
}

but getting this exception

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)

And here is my effect

    @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();
    })
  );
user366584
  • 1,016
  • 1
  • 16
  • 34

1 Answers1

3

ERROR Error: Effect "UserSessionEffects.logout$" dispatched an invalid action

A ngrx/effect must return an action (an object with a type property) unless it's decorated as @Effect({dispatch: false}).

Update your effect to return an action:

return Observable.of({ type: 'LOGGED OUT SUCCESS'});
timdeschryver
  • 14,415
  • 1
  • 19
  • 32