How to reset all states of ngrx/store?

后端 未结 4 744
执笔经年
执笔经年 2020-12-15 17:11

I am using Angular 2 with ngrx/store. I want to reset the whole store states when user dispatch USER_LOGOUT.

I read the Dan Abramov\'s answer of How to

4条回答
  •  星月不相逢
    2020-12-15 17:58

    This isn't really an answer but the comments won't let me format it correctly. To add to what cartant said, if you are setting up your types like this:

    export const ActionTypes = {
      LOGOUT:  type('[Environment] Logout of portal'),
      ....
    }
    

    It's the long description that you should use. Also if you name your root reducer rootReducer instead of just reducer then you would change that as well. Following is an edited example:

    (I left this function within my root reducer)

    const developmentReducer: ActionReducer = compose(...DEV_REDUCERS,
    (rootReducer: Function) => {
        return function(state, action) {
          if (action.type === '[Environment] Logout of portal') {
            state = undefined;
          }
          return rootReducer(state, action);
        };
      }, combineReducers)(reducers);
    

提交回复
热议问题