UNPKG

tsioc

Version:

tsioc is AOP, Ioc container, via typescript decorator

111 lines (109 loc) 3.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var typeCheck_1 = require("./typeCheck"); /** * object map set. * * @export * @class MapSet * @template TKey * @template TVal */ var ObjectMapSet = /** @class */ (function () { function ObjectMapSet() { this.valueMap = {}; this.keyMap = {}; } ObjectMapSet.prototype.clear = function () { this.valueMap = {}; this.keyMap = {}; }; ObjectMapSet.prototype.getTypeKey = function (key) { var strKey = ''; if (typeCheck_1.isString(key)) { strKey = key; } else if (typeCheck_1.isFunction(key)) { strKey = key.name; } else { strKey = key.toString(); } return strKey; }; ObjectMapSet.prototype.delete = function (key) { var strkey = this.getTypeKey(key).toString(); try { delete this.keyMap[strkey]; delete this.valueMap[strkey]; return true; } catch (_a) { return false; } }; ObjectMapSet.prototype.forEach = function (callbackfn, thisArg) { var _this = this; Object.keys(this.keyMap).forEach(function (name) { callbackfn(_this.valueMap[name], _this.keyMap[name], _this); }); }; ObjectMapSet.prototype.get = function (key) { var strKey = this.getTypeKey(key); return this.valueMap[strKey]; }; ObjectMapSet.prototype.has = function (key) { var strKey = this.getTypeKey(key); return !typeCheck_1.isUndefined(this.keyMap[strKey]); }; ObjectMapSet.prototype.set = function (key, value) { var strKey = this.getTypeKey(key); this.keyMap[strKey] = key; this.valueMap[strKey] = value; return this; }; Object.defineProperty(ObjectMapSet.prototype, "size", { get: function () { return Object.keys(this.keyMap).length; }, enumerable: true, configurable: true }); return ObjectMapSet; }()); exports.ObjectMapSet = ObjectMapSet; var MapSet = /** @class */ (function () { function MapSet() { this.map = typeCheck_1.isClass(Map) ? new Map() : new ObjectMapSet(); } MapSet.prototype.clear = function () { this.map.clear(); }; MapSet.prototype.delete = function (key) { return this.map.delete(key); }; MapSet.prototype.forEach = function (callbackfn, thisArg) { var map = this.map; map.forEach(callbackfn, thisArg); }; MapSet.prototype.get = function (key) { return this.map.get(key); }; MapSet.prototype.has = function (key) { return this.map.has(key); }; MapSet.prototype.set = function (key, value) { this.map.set(key, value); return this; }; Object.defineProperty(MapSet.prototype, "size", { get: function () { return this.map.size; }, enumerable: true, configurable: true }); return MapSet; }()); exports.MapSet = MapSet; //# sourceMappingURL=../sourcemaps/utils/MapSet.js.map