@vived/app 4.0.0 → 4.0.1

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.
@@ -12,6 +12,8 @@ export declare abstract class AppObjectRepo extends ObservableEntity {
12
12
  abstract submitWarning(sender: string, message: string): void;
13
13
  abstract submitError(sender: string, message: string): void;
14
14
  abstract submitFatal(sender: string, message: string): void;
15
+ abstract registerSingleton(component: AppObjectComponent): void;
16
+ abstract getSingleton<T extends AppObjectComponent>(type: string): T | undefined;
15
17
  abstract getAppObjectComponent<T extends AppObjectComponent>(appObjectID: string, type: string): T | undefined;
16
18
  abstract getAllAppObjectsWithComponent(componentType: string): AppObject[];
17
19
  abstract getAllComponents<T extends AppObjectComponent>(type: string): T[];
@@ -14,6 +14,7 @@ class AppObjectRepoImp extends AppObjectRepo {
14
14
  constructor() {
15
15
  super(...arguments);
16
16
  this.appObjectLookup = new Map();
17
+ this.singletons = new Map();
17
18
  this.onAppObjectAddedObserver = new Entities_1.ObserverList();
18
19
  this.addAppObjectAddedObserver = (observer) => {
19
20
  this.onAppObjectAddedObserver.add(observer);
@@ -104,4 +105,28 @@ class AppObjectRepoImp extends AppObjectRepo {
104
105
  submitFatal(sender, message) {
105
106
  console.error(`FATAL ERROR - [${sender}]: ${message}`);
106
107
  }
108
+ registerSingleton(component) {
109
+ if (this.singletons.has(component.type)) {
110
+ this.submitWarning("AppObjectRepo", `Singleton for type ${component.type} already exists. Relpacing`);
111
+ }
112
+ this.singletons.set(component.type, component);
113
+ }
114
+ getSingleton(type) {
115
+ if (this.singletons.has(type)) {
116
+ return this.singletons.get(type);
117
+ }
118
+ const components = this.getAllComponents(type);
119
+ if (components.length === 1) {
120
+ this.singletons.set(components[0].type, components[0]);
121
+ return components[0];
122
+ }
123
+ else if (components.length === 0) {
124
+ this.submitWarning("AppObjectRepo", `Unable to find a singleton for ${type}`);
125
+ return undefined;
126
+ }
127
+ else if (components.length > 1) {
128
+ this.submitWarning("AppObjectRepo", `Multiple ${type} found. There should only be one if it truly a singleton. Using the first one`);
129
+ return components[0];
130
+ }
131
+ }
107
132
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vived/app",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "Public package for the VIVED Learning App system",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",