UNPKG

@choerodon/master

Version:
86 lines (68 loc) 4.63 kB
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } import { toJS } from 'mobx'; import { merge, omit } from 'lodash'; var pages = new Map(); // 工作台不使用项目id作为前缀区分 var LocalPageCacheStore = /*#__PURE__*/function () { function LocalPageCacheStore() { _classCallCheck(this, LocalPageCacheStore); this.localData = pages; this.projectId = ''; this.clear = function () { pages.clear(); }; } _createClass(LocalPageCacheStore, [{ key: "setProjectId", value: function setProjectId(data) { this.projectId = data; } }, { key: "setItem", value: function setItem(pageKey, data) { var keyPrefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "".concat(this.projectId, "-"); pages.set("".concat(keyPrefix).concat(pageKey), data); } }, { key: "mergeSetItem", value: function mergeSetItem(pageKey, data) { var keyPrefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "".concat(this.projectId, "-"); var oldData = pages.get("".concat(keyPrefix).concat(pageKey)); var omitKeys = []; if (typeof oldData === 'object' && typeof data === 'object') { for (var _i = 0, _Object$entries = Object.entries(data); _i < _Object$entries.length; _i++) { var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), key = _Object$entries$_i[0], value = _Object$entries$_i[1]; if (typeof value === 'undefined' || Array.isArray(toJS(value)) && value.length === 0) { omitKeys.push(key); } } } var newData = merge(omit(oldData, omitKeys), data); pages.set("".concat(this.projectId, "-").concat(pageKey), newData); } }, { key: "getItem", value: function getItem(pageKey) { var keyPrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "".concat(this.projectId, "-"); return pages.get("".concat(keyPrefix).concat(pageKey)); } }, { key: "remove", value: function remove(pageKey) { var keyPrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "".concat(this.projectId, "-"); pages["delete"]("".concat(keyPrefix).concat(pageKey)); } }]); return LocalPageCacheStore; }(); var testLocalPageCacheStore = new LocalPageCacheStore(); export { testLocalPageCacheStore as localPageCacheStore };