39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
var RegistryBase = (function () {
|
|
function RegistryBase() {
|
|
this._registryMap = new Map();
|
|
}
|
|
RegistryBase.prototype.entries = function () {
|
|
return this._registryMap.entries();
|
|
};
|
|
RegistryBase.prototype.getAll = function (key) {
|
|
this.ensure(key);
|
|
return this._registryMap.get(key);
|
|
};
|
|
RegistryBase.prototype.get = function (key) {
|
|
this.ensure(key);
|
|
var value = this._registryMap.get(key);
|
|
return value[value.length - 1] || null;
|
|
};
|
|
RegistryBase.prototype.set = function (key, value) {
|
|
this.ensure(key);
|
|
this._registryMap.get(key).push(value);
|
|
};
|
|
RegistryBase.prototype.setAll = function (key, value) {
|
|
this._registryMap.set(key, value);
|
|
};
|
|
RegistryBase.prototype.has = function (key) {
|
|
this.ensure(key);
|
|
return this._registryMap.get(key).length > 0;
|
|
};
|
|
RegistryBase.prototype.clear = function () {
|
|
this._registryMap.clear();
|
|
};
|
|
RegistryBase.prototype.ensure = function (key) {
|
|
if (!this._registryMap.has(key)) {
|
|
this._registryMap.set(key, []);
|
|
}
|
|
};
|
|
return RegistryBase;
|
|
}());
|
|
export default RegistryBase;
|