Skip to content

Commit

Permalink
Avoid mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
zalmoxisus committed Jan 7, 2016
1 parent eb3e240 commit a9f69d5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/app/store/updateState.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import parseJSON from '../utils/parseJSON';
function recompute(previousLiftedState, storeState, action, nextActionId) {
const actionId = nextActionId - 1;
const liftedState = { ...previousLiftedState };
liftedState.stagedActionIds.push(actionId);
liftedState.actionsById[actionId] = parseJSON(action);
liftedState.stagedActionIds = [...liftedState.stagedActionIds, actionId];
liftedState.actionsById = { ...liftedState.actionsById };
liftedState.actionsById[actionId] = action;
liftedState.nextActionId = nextActionId;
liftedState.computedStates.push({ state: storeState });
liftedState.computedStates = [...liftedState.computedStates, { state: storeState }];
liftedState.currentStateIndex++;
return liftedState;
}
Expand All @@ -17,7 +18,7 @@ export default function updateState(store, request) {

switch (request.type) {
case 'ACTION':
const newState = recompute(store.liftedStore.getState(), payload, request.action, request.nextActionId);
const newState = recompute(store.liftedStore.getState(), payload, parseJSON(request.action), request.nextActionId);
store.liftedStore.setState(newState);
return newState;
case 'STATE':
Expand Down

0 comments on commit a9f69d5

Please sign in to comment.