UNPKG

dash-renderer

Version:

render dash components in react

66 lines (65 loc) 2.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); } function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } var initialHistory = { past: [], present: {}, future: [] }; function history() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialHistory; var action = arguments.length > 1 ? arguments[1] : undefined; switch (action.type) { case 'UNDO': { var past = state.past, present = state.present, future = state.future; var previous = past[past.length - 1]; var newPast = past.slice(0, past.length - 1); return { past: newPast, present: previous, future: [present].concat(_toConsumableArray(future)) }; } case 'REDO': { var _past = state.past, _present = state.present, _future = state.future; var next = _future[0]; var newFuture = _future.slice(1); return { past: [].concat(_toConsumableArray(_past), [_present]), present: next, future: newFuture }; } case 'REVERT': { var _past2 = state.past, _future2 = state.future; var _previous = _past2[_past2.length - 1]; var _newPast = _past2.slice(0, _past2.length - 1); return { past: _newPast, present: _previous, future: _toConsumableArray(_future2) }; } default: { return state; } } } var _default = exports.default = history;