UNPKG

canner

Version:

Build CMS in few lines of code for different data sources

72 lines (58 loc) 2.75 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread")); var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _lodash = require("lodash"); var ArrayPattern = function ArrayPattern() { var _this = this; (0, _classCallCheck2.default)(this, ArrayPattern); (0, _defineProperty2.default)(this, "actions", void 0); (0, _defineProperty2.default)(this, "removeAllActionIfDeleteAfterCreate", function () { if (_this.actions.length >= 2 && _this.actions[0].type === 'CREATE_ARRAY' && _this.actions.slice(-1)[0].type === 'DELETE_ARRAY') { _this.actions = []; } }); (0, _defineProperty2.default)(this, "removeAllUpdateBeforeDelete", function () { if (_this.actions.length >= 2 && _this.actions[0].type !== 'CREATE_ARRAY' && _this.actions.slice(-1)[0].type === 'DELETE_ARRAY') { _this.actions = _this.actions.slice(-1); } }); (0, _defineProperty2.default)(this, "mergeAllUpdate", function () { if (_this.actions.length >= 2 && _this.actions[0].type === 'UPDATE_ARRAY' && _this.actions.slice(-1)[0].type === 'UPDATE_ARRAY') { _this.actions = [_this.actions.reduce(function (result, action) { result.payload.value = (0, _objectSpread2.default)({}, result.payload.value, action.payload.value); return result; })]; } }); (0, _defineProperty2.default)(this, "mergeUpdateAndCreate", function () { if (_this.actions.length >= 2 && _this.actions[0].type === 'CREATE_ARRAY' && _this.actions.slice(-1)[0].type === 'UPDATE_ARRAY') { _this.actions = [_this.actions.reduce(function (result, action) { result.payload.value = (0, _objectSpread2.default)({}, result.payload.value, action.payload.value); return result; })]; } }); (0, _defineProperty2.default)(this, "addAction", function (action) { _this.actions.push(action); _this.mergeAction(); }); (0, _defineProperty2.default)(this, "_mergeAction", function () { _this.removeAllActionIfDeleteAfterCreate(); _this.removeAllUpdateBeforeDelete(); _this.mergeAllUpdate(); _this.mergeUpdateAndCreate(); return _this.actions; }); (0, _defineProperty2.default)(this, "mergeAction", (0, _lodash.throttle)(this._mergeAction, 150)); (0, _defineProperty2.default)(this, "getActions", function () { return _this.actions; }); this.actions = []; }; exports.default = ArrayPattern;