futurice/pepperoni-app-kit

How do you reset the state?

octohedron opened this issue · 0 comments

//resetState.js

export const initialState = Map({
  token: null
});

export const resetAction = () => {
  mainReducer({ }, {
    payload: initialState,
    type: 'RESET'
  }); // Crashes, Cannot read type of undefined
};

//reducer.js

const reducers = {
  auth: AuthStateReducer,
  ...
  reset: ResetStateReducer
};

const immutableStateContainer = Map();
const getImmutable = (child, key) => child ? child.get(key) : void 0;
const setImmutable = (child, key, value) => child.set(key, value);

const namespacedReducer = combineReducers(
  reducers,
  immutableStateContainer,
  getImmutable,
  setImmutable
);

export default function mainReducer(state, action) {
  const [nextState, effects] = action.type === 'RESET'
    ? namespacedReducer(action.payload, action)
    : namespacedReducer(state || void 0, action);
  return loop(fromJS(nextState), effects);
}

It's throwing in createStore.js

function dispatch(action) {
  if (!(0, _isPlainObject2['default'])(action)) {
    // this
    throw new Error('Actions must be plain objects. ' + 'Use custom middleware for async actions.');
}

Fixed it, If you have the same problem, god have mercy on your soul.