-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStrategyNoteRegistry.js
43 lines (43 loc) · 1.41 KB
/
StrategyNoteRegistry.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.instance = exports.StrategyNoteRegistry = void 0;
const EntityRegistry_1 = require("@civ-clone/core-registry/EntityRegistry");
const StrategyNote_1 = require("./StrategyNote");
class StrategyNoteRegistry extends EntityRegistry_1.EntityRegistry {
constructor() {
super(StrategyNote_1.default);
}
getByKey(key) {
return this.getBy('key', key)[0];
}
getOrCreateByKey(key, value) {
const existing = this.getByKey(key);
if (existing) {
return existing;
}
const note = new StrategyNote_1.default(key, value);
this.register(note);
return note;
}
register(...entities) {
entities.forEach((entity) => {
if (this.getByKey(entity.key())) {
throw new TypeError(`Entity with key '${entity.key()}' already exists.`);
}
super.register(entity);
});
}
replace(...entities) {
entities.forEach((entity) => {
const existing = this.getByKey(entity.key());
if (existing) {
this.unregister(existing);
}
this.register(entity);
});
}
}
exports.StrategyNoteRegistry = StrategyNoteRegistry;
exports.instance = new StrategyNoteRegistry();
exports.default = StrategyNoteRegistry;
//# sourceMappingURL=StrategyNoteRegistry.js.map