algopat
Version:
Utility library for implementing common design patterns and algorithms
36 lines • 1.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PrototypeRegistry = exports.AbstractPrototypeRegistry = exports.Prototype = void 0;
class Prototype {
}
exports.Prototype = Prototype;
class AbstractPrototypeRegistry {
}
exports.AbstractPrototypeRegistry = AbstractPrototypeRegistry;
class PrototypeRegistry extends AbstractPrototypeRegistry {
constructor() {
super(...arguments);
this.prototypes = new Map();
}
register(id, prototype) {
if (this.prototypes.has(id)) {
throw new Error(`Prototype with id ${id} already registered`);
}
this.prototypes.set(id, prototype);
}
unregister(id) {
const prototype = this.prototypes.get(id);
if (!prototype) {
throw new Error(`Prototype with id ${id} not found`);
}
this.prototypes.delete(id);
}
get(id) {
const prototype = this.prototypes.get(id);
if (!prototype)
return;
return prototype;
}
}
exports.PrototypeRegistry = PrototypeRegistry;
//# sourceMappingURL=prototype.pattern.js.map