"use strict";

exports.__esModule = true;
exports.veUndo = exports.veRedo = exports["default"] = exports.addToUndoStack = void 0;
var _reduxAct = require("redux-act");
var _createMetaAction = _interopRequireDefault(require("./utils/createMetaAction"));
var _createReducer;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
// ------------------------------------
// Actions
// ------------------------------------
var addToUndoStack = (0, _createMetaAction["default"])("ADD_TO_UNDO_STACK");
exports.addToUndoStack = addToUndoStack;
var veUndo = (0, _createMetaAction["default"])("VE_UNDO_META");
exports.veUndo = veUndo;
var veRedo = (0, _createMetaAction["default"])("VE_REDO_META");

// ------------------------------------
// Reducer
// ------------------------------------
exports.veRedo = veRedo;
var _default = (0, _reduxAct.createReducer)((_createReducer = {}, _createReducer[addToUndoStack] = function (state, payload) {
  return _extends({}, state, {
    future: [],
    past: [].concat(state.past || [], [payload])
  });
}, _createReducer[veUndo] = function (state, presentState) {
  return _extends({}, state, {
    past: (state.past || []).slice(0, -1),
    future: (state.future || []).concat(presentState)
  });
}, _createReducer[veRedo] = function (state, presentState) {
  return _extends({}, state, {
    future: (state.future || []).slice(0, -1),
    past: (state.past || []).concat(presentState)
  });
}, _createReducer), {
  past: [],
  future: []
});
exports["default"] = _default;