@txdfe/at
Version:
一个设计体系组件库
70 lines (60 loc) • 2.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
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); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
var Cache = /*#__PURE__*/function () {
function Cache() {
_classCallCheck(this, Cache);
this._root = null;
this._store = new Map();
}
_createClass(Cache, [{
key: "empty",
value: function empty() {
return this._store.size === 0;
}
}, {
key: "has",
value: function has(key) {
return this._store.has(key);
}
}, {
key: "get",
value: function get(key, defaultValue) {
var res = this.has(key) ? this._store.get(key) : this.root();
return typeof res === 'undefined' || res === null ? defaultValue : res;
}
}, {
key: "add",
value: function add(key, value) {
if (this.empty()) {
this._root = key;
}
this._store.set(key, value);
}
}, {
key: "update",
value: function update(key, value) {
if (this.has(key)) {
this._store.set(key, value);
}
}
}, {
key: "remove",
value: function remove(key) {
this._store["delete"](key);
}
}, {
key: "root",
value: function root() {
return this._store.get(this._root);
}
}]);
return Cache;
}();
var _default = Cache;
exports["default"] = _default;