@vived/app 4.10.1 → 4.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,6 +4,9 @@ export declare class AppObjectComponent {
|
|
|
4
4
|
readonly type: string;
|
|
5
5
|
readonly appObject: AppObject;
|
|
6
6
|
get appObjects(): AppObjectRepo;
|
|
7
|
+
private cachedSingletons;
|
|
8
|
+
getCachedSingleton<T extends AppObjectComponent>(type: string): T | undefined;
|
|
9
|
+
getSingleton<T extends AppObjectComponent>(type: string, logType?: "LOG" | "WARN" | "ERROR"): T | undefined;
|
|
7
10
|
dispose(): void;
|
|
8
11
|
log(message: string): void;
|
|
9
12
|
warn(message: string): void;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AppObjectComponent = void 0;
|
|
4
4
|
class AppObjectComponent {
|
|
5
5
|
constructor(appObject, type) {
|
|
6
|
+
this.cachedSingletons = new Map();
|
|
6
7
|
this.appObject = appObject;
|
|
7
8
|
this.type = type;
|
|
8
9
|
appObject.addComponent(this);
|
|
@@ -10,6 +11,37 @@ class AppObjectComponent {
|
|
|
10
11
|
get appObjects() {
|
|
11
12
|
return this.appObject.appObjectRepo;
|
|
12
13
|
}
|
|
14
|
+
getCachedSingleton(type) {
|
|
15
|
+
if (!this.cachedSingletons.has(type)) {
|
|
16
|
+
const component = this.appObjects.getSingleton(type);
|
|
17
|
+
if (!component) {
|
|
18
|
+
this.warn("Unable to get cached singleton type " + type);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
this.cachedSingletons.set(type, component);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return this.cachedSingletons.get(type);
|
|
25
|
+
}
|
|
26
|
+
getSingleton(type, logType = "WARN") {
|
|
27
|
+
const comp = this.appObjects.getSingleton(type);
|
|
28
|
+
if (!comp) {
|
|
29
|
+
const msg = "Unable to get singleton type " + type;
|
|
30
|
+
switch (logType) {
|
|
31
|
+
case "ERROR":
|
|
32
|
+
this.error(msg);
|
|
33
|
+
break;
|
|
34
|
+
case "LOG":
|
|
35
|
+
this.log(msg);
|
|
36
|
+
break;
|
|
37
|
+
case "WARN":
|
|
38
|
+
this.warn(msg);
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return comp;
|
|
43
|
+
}
|
|
44
|
+
;
|
|
13
45
|
dispose() {
|
|
14
46
|
if (this.appObject.getComponent(this.type) === this) {
|
|
15
47
|
this.appObject.removeComponent(this.type);
|
|
@@ -21,6 +53,7 @@ class AppObjectComponent {
|
|
|
21
53
|
warn(message) {
|
|
22
54
|
this.appObjects.submitWarning(`${this.appObject.id}/${this.type}`, message);
|
|
23
55
|
}
|
|
56
|
+
;
|
|
24
57
|
error(message) {
|
|
25
58
|
this.appObjects.submitError(`${this.appObject.id}/${this.type}`, message);
|
|
26
59
|
}
|