UNPKG

@difizen/mana-core

Version:

67 lines 3.54 kB
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } var _dec, _class; 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, _toPropertyKey(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; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } import { singleton } from '@difizen/mana-syringe'; export var ConfigurationCache = (_dec = singleton(), _dec(_class = /*#__PURE__*/function () { function ConfigurationCache() { _classCallCheck(this, ConfigurationCache); this.cache = new Map(); this._disposed = false; } _createClass(ConfigurationCache, [{ key: "has", value: function has(provider, node) { var _this$cache$get; return this.cache.has(provider) && ((_this$cache$get = this.cache.get(provider)) === null || _this$cache$get === void 0 ? void 0 : _this$cache$get.has(node.id)); } }, { key: "set", value: function set(provider, node, value) { var _this$cache$get2; var providerCache = (_this$cache$get2 = this.cache.get(provider)) !== null && _this$cache$get2 !== void 0 ? _this$cache$get2 : new Map(); providerCache.set(node.id, value); this.cache.set(provider, providerCache); } }, { key: "get", value: function get(provider, node) { var _this$cache$get3; return (_this$cache$get3 = this.cache.get(provider)) === null || _this$cache$get3 === void 0 ? void 0 : _this$cache$get3.get(node.id); } }, { key: "remove", value: function remove(provider, node) { var _this$cache$get4; (_this$cache$get4 = this.cache.get(provider)) === null || _this$cache$get4 === void 0 || _this$cache$get4.delete(node.id); } }, { key: "clear", value: function clear(provider) { if (provider) { var _this$cache$get5; (_this$cache$get5 = this.cache.get(provider)) === null || _this$cache$get5 === void 0 || _this$cache$get5.clear(); } else { this.cache.clear(); } } }, { key: "disposed", get: function get() { return this._disposed; } }, { key: "dispose", value: function dispose() { if (this.disposed) { return; } this._disposed = true; this.clear(); } }]); return ConfigurationCache; }()) || _class);