Skip to content

Commit

Permalink
Do not recompute states unless necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Sep 27, 2015
1 parent a5dd802 commit e4c03d8
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/devTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function liftReducer(reducer, initialState) {
* Manages how the DevTools actions modify the DevTools state.
*/
return function liftedReducer(liftedState = initialLiftedState, liftedAction) {
let shouldRecomputeStates = true;
let {
committedState,
stagedActions,
Expand Down Expand Up @@ -144,6 +145,16 @@ function liftReducer(reducer, initialState) {
}
stagedActions = [...stagedActions, liftedAction.action];
timestamps = [...timestamps, liftedAction.timestamp];

const previousEntry = computedStates[computedStates.length - 1];
const nextEntry = computeNextEntry(
reducer,
liftedAction.action,
previousEntry.state,
previousEntry.error
);
computedStates = [...computedStates, nextEntry];
shouldRecomputeStates = false;
break;
case ActionTypes.SET_MONITOR_STATE:
monitorState = liftedAction.monitorState;
Expand All @@ -159,12 +170,14 @@ function liftReducer(reducer, initialState) {
break;
}

computedStates = recomputeStates(
reducer,
committedState,
stagedActions,
skippedActions
);
if (shouldRecomputeStates) {
computedStates = recomputeStates(
reducer,
committedState,
stagedActions,
skippedActions
);
}

return {
committedState,
Expand Down

0 comments on commit e4c03d8

Please sign in to comment.