2019-01-03 17:14:25 +03:00
|
|
|
// Based on https://github.com/gaearon/redux-devtools/pull/241
|
|
|
|
/* eslint-disable no-param-reassign */
|
|
|
|
|
|
|
|
export default function commitExcessActions(liftedState, n = 1) {
|
|
|
|
// Auto-commits n-number of excess actions.
|
|
|
|
let excess = n;
|
|
|
|
let idsToDelete = liftedState.stagedActionIds.slice(1, excess + 1);
|
|
|
|
|
|
|
|
for (let i = 0; i < idsToDelete.length; i++) {
|
|
|
|
if (liftedState.computedStates[i + 1].error) {
|
|
|
|
// Stop if error is found. Commit actions up to error.
|
|
|
|
excess = i;
|
|
|
|
idsToDelete = liftedState.stagedActionIds.slice(1, excess + 1);
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
delete liftedState.actionsById[idsToDelete[i]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
liftedState.skippedActionIds = liftedState.skippedActionIds.filter(
|
|
|
|
id => idsToDelete.indexOf(id) === -1
|
|
|
|
);
|
2019-01-10 21:51:14 +03:00
|
|
|
liftedState.stagedActionIds = [
|
|
|
|
0,
|
|
|
|
...liftedState.stagedActionIds.slice(excess + 1)
|
|
|
|
];
|
2019-01-03 17:14:25 +03:00
|
|
|
liftedState.committedState = liftedState.computedStates[excess].state;
|
|
|
|
liftedState.computedStates = liftedState.computedStates.slice(excess);
|
2019-01-10 21:51:14 +03:00
|
|
|
liftedState.currentStateIndex =
|
|
|
|
liftedState.currentStateIndex > excess
|
|
|
|
? liftedState.currentStateIndex - excess
|
|
|
|
: 0;
|
2019-01-03 17:14:25 +03:00
|
|
|
}
|