text: import { UNDO_ACTION } from "./storeUndo";
  export function handleUndo(rootReducer, bufferSize) {
      var executedActions = [];
      var initialState = undefined;
      return function (state, action) {
          if (action.type === UNDO_ACTION) {
              // if the action is UNDO_ACTION,
              // then call all the actions again on the rootReducer,
              // except the one we want to rollback
              var newState_1 = initialState;
              executedActions = executedActions.filter(function (eAct) { return eAct !== action.payload; });
              // update the state for every action untill we get the
              // exact same state as before, but without the action we want to rollback
              executedActions.forEach(function (executedAction) {
                  return newState_1 = rootReducer(newState_1, executedAction);
              });
              return newState_1;
          }
          // push every action that isn't an UNDO_ACTION to the executedActions property
          executedActions.push(action);
          var updatedState = rootReducer(state, action);
          if (executedActions.length === bufferSize + 1) {
              var firstAction = executedActions[0];
              // calculate the state x (buffersize) actions ago
              initialState = rootReducer(initialState, firstAction);
              // keep the correct actions
              executedActions = executedActions.slice(1, bufferSize + 1);
          }
          return updatedState;
      };
  }
  //# sourceMappingURL=handleUndo.js.map