@vived/core 1.6.0 → 2.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.
- package/dist/cjs/AppObject/AppObjectComponent.js +8 -10
- package/dist/cjs/AppObject/AppObjectComponent.js.map +1 -1
- package/dist/cjs/AppObject/AppObjectEntityRepo.js +113 -11
- package/dist/cjs/AppObject/AppObjectEntityRepo.js.map +1 -1
- package/dist/cjs/AppObject/AppObjectPM.js +106 -6
- package/dist/cjs/AppObject/AppObjectPM.js.map +1 -1
- package/dist/cjs/AppObject/AppObjectRepo.js +4 -1
- package/dist/cjs/AppObject/AppObjectRepo.js.map +1 -1
- package/dist/cjs/AppObject/AppObjectSingletonEntity.js +40 -0
- package/dist/cjs/AppObject/AppObjectSingletonEntity.js.map +1 -0
- package/dist/cjs/AppObject/AppObjectSingletonEntityRepo.js +54 -0
- package/dist/cjs/AppObject/AppObjectSingletonEntityRepo.js.map +1 -0
- package/dist/cjs/AppObject/AppObjectSingletonPM.js +69 -0
- package/dist/cjs/AppObject/AppObjectSingletonPM.js.map +1 -0
- package/dist/cjs/AppObject/AppObjectSingletonUC.js +60 -0
- package/dist/cjs/AppObject/AppObjectSingletonUC.js.map +1 -0
- package/dist/cjs/AppObject/index.js +4 -0
- package/dist/cjs/AppObject/index.js.map +1 -1
- package/dist/cjs/Entities/ObserverList.js +6 -0
- package/dist/cjs/Entities/ObserverList.js.map +1 -1
- package/dist/cjs/ExampleFeature/Entities/ExampleRepo.js +10 -22
- package/dist/cjs/ExampleFeature/Entities/ExampleRepo.js.map +1 -1
- package/dist/cjs/ExampleFeature/Entities/ExampleSingletonEntity.js +1 -3
- package/dist/cjs/ExampleFeature/Entities/ExampleSingletonEntity.js.map +1 -1
- package/dist/cjs/ExampleFeature/Factory/ExampleFeatureFactory.js +1 -1
- package/dist/cjs/ExampleFeature/Factory/ExampleFeatureFactory.js.map +1 -1
- package/dist/cjs/ExampleFeature/PMs/ExamplePM.js +5 -13
- package/dist/cjs/ExampleFeature/PMs/ExamplePM.js.map +1 -1
- package/dist/cjs/ExampleFeature/PMs/ExampleSingletonPM.js +8 -12
- package/dist/cjs/ExampleFeature/PMs/ExampleSingletonPM.js.map +1 -1
- package/dist/cjs/ExampleFeature/UCs/EditExampleStringUC.js +0 -4
- package/dist/cjs/ExampleFeature/UCs/EditExampleStringUC.js.map +1 -1
- package/dist/cjs/ExampleFeature/UCs/ToggleExampleBooleanUC.js +2 -8
- package/dist/cjs/ExampleFeature/UCs/ToggleExampleBooleanUC.js.map +1 -1
- package/dist/esm/AppObject/AppObjectComponent.js +8 -10
- package/dist/esm/AppObject/AppObjectComponent.js.map +1 -1
- package/dist/esm/AppObject/AppObjectEntityRepo.js +113 -11
- package/dist/esm/AppObject/AppObjectEntityRepo.js.map +1 -1
- package/dist/esm/AppObject/AppObjectPM.js +107 -7
- package/dist/esm/AppObject/AppObjectPM.js.map +1 -1
- package/dist/esm/AppObject/AppObjectRepo.js +4 -1
- package/dist/esm/AppObject/AppObjectRepo.js.map +1 -1
- package/dist/esm/AppObject/AppObjectSingletonEntity.js +36 -0
- package/dist/esm/AppObject/AppObjectSingletonEntity.js.map +1 -0
- package/dist/esm/AppObject/AppObjectSingletonEntityRepo.js +50 -0
- package/dist/esm/AppObject/AppObjectSingletonEntityRepo.js.map +1 -0
- package/dist/esm/AppObject/AppObjectSingletonPM.js +65 -0
- package/dist/esm/AppObject/AppObjectSingletonPM.js.map +1 -0
- package/dist/esm/AppObject/AppObjectSingletonUC.js +56 -0
- package/dist/esm/AppObject/AppObjectSingletonUC.js.map +1 -0
- package/dist/esm/AppObject/index.js +4 -0
- package/dist/esm/AppObject/index.js.map +1 -1
- package/dist/esm/Entities/ObserverList.js +6 -0
- package/dist/esm/Entities/ObserverList.js.map +1 -1
- package/dist/esm/ExampleFeature/Entities/ExampleRepo.js +10 -22
- package/dist/esm/ExampleFeature/Entities/ExampleRepo.js.map +1 -1
- package/dist/esm/ExampleFeature/Entities/ExampleSingletonEntity.js +2 -4
- package/dist/esm/ExampleFeature/Entities/ExampleSingletonEntity.js.map +1 -1
- package/dist/esm/ExampleFeature/Factory/ExampleFeatureFactory.js +1 -1
- package/dist/esm/ExampleFeature/Factory/ExampleFeatureFactory.js.map +1 -1
- package/dist/esm/ExampleFeature/PMs/ExamplePM.js +5 -13
- package/dist/esm/ExampleFeature/PMs/ExamplePM.js.map +1 -1
- package/dist/esm/ExampleFeature/PMs/ExampleSingletonPM.js +9 -13
- package/dist/esm/ExampleFeature/PMs/ExampleSingletonPM.js.map +1 -1
- package/dist/esm/ExampleFeature/UCs/EditExampleStringUC.js +0 -4
- package/dist/esm/ExampleFeature/UCs/EditExampleStringUC.js.map +1 -1
- package/dist/esm/ExampleFeature/UCs/ToggleExampleBooleanUC.js +3 -9
- package/dist/esm/ExampleFeature/UCs/ToggleExampleBooleanUC.js.map +1 -1
- package/dist/types/AppObject/AppObjectComponent.d.ts +6 -4
- package/dist/types/AppObject/AppObjectComponent.d.ts.map +1 -1
- package/dist/types/AppObject/AppObjectEntityRepo.d.ts +80 -7
- package/dist/types/AppObject/AppObjectEntityRepo.d.ts.map +1 -1
- package/dist/types/AppObject/AppObjectPM.d.ts +82 -2
- package/dist/types/AppObject/AppObjectPM.d.ts.map +1 -1
- package/dist/types/AppObject/AppObjectRepo.d.ts +6 -0
- package/dist/types/AppObject/AppObjectRepo.d.ts.map +1 -1
- package/dist/types/AppObject/AppObjectSingletonEntity.d.ts +31 -0
- package/dist/types/AppObject/AppObjectSingletonEntity.d.ts.map +1 -0
- package/dist/types/AppObject/AppObjectSingletonEntityRepo.d.ts +46 -0
- package/dist/types/AppObject/AppObjectSingletonEntityRepo.d.ts.map +1 -0
- package/dist/types/AppObject/AppObjectSingletonPM.d.ts +60 -0
- package/dist/types/AppObject/AppObjectSingletonPM.d.ts.map +1 -0
- package/dist/types/AppObject/AppObjectSingletonUC.d.ts +51 -0
- package/dist/types/AppObject/AppObjectSingletonUC.d.ts.map +1 -0
- package/dist/types/AppObject/index.d.ts +4 -0
- package/dist/types/AppObject/index.d.ts.map +1 -1
- package/dist/types/Entities/ObserverList.d.ts +4 -0
- package/dist/types/Entities/ObserverList.d.ts.map +1 -1
- package/dist/types/ExampleFeature/Entities/ExampleRepo.d.ts +1 -5
- package/dist/types/ExampleFeature/Entities/ExampleRepo.d.ts.map +1 -1
- package/dist/types/ExampleFeature/Entities/ExampleSingletonEntity.d.ts +2 -2
- package/dist/types/ExampleFeature/Entities/ExampleSingletonEntity.d.ts.map +1 -1
- package/dist/types/ExampleFeature/PMs/ExampleSingletonPM.d.ts +4 -4
- package/dist/types/ExampleFeature/PMs/ExampleSingletonPM.d.ts.map +1 -1
- package/dist/types/ExampleFeature/UCs/ToggleExampleBooleanUC.d.ts +2 -2
- package/dist/types/ExampleFeature/UCs/ToggleExampleBooleanUC.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppObjectRepo.js","sourceRoot":"","sources":["../../../src/AppObject/AppObjectRepo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAa,aAAa,EAAE,MAAM,aAAa,CAAC;AAGvD;;;;;;;;GAQG;AACH,MAAM,OAAgB,aAAc,SAAQ,gBAAgB;CAyK3D;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,IAAI,gBAAgB,EAAE,CAAC;AAChC,CAAC;AAED;;;;;GAKG;AACH,MAAM,gBAAiB,SAAQ,aAAa;IAA5C;;QACU,oBAAe,GAAG,IAAI,GAAG,EAAqB,CAAC;QAC/C,eAAU,GAAG,IAAI,GAAG,EAA8B,CAAC;QAEnD,6BAAwB,GAAG,IAAI,YAAY,EAAa,CAAC;QACjE,8BAAyB,GAAG,CAAC,QAA0C,EAAE,EAAE;YACzE,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,QAAQ,CAAC,CA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AC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACjD,CAAC;IAED,YAAY,CAAC,IAAY;QACvB,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,gBAAgB,CAAqB,IAAI,CAAC,CAAC;QACnE,OAAO,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,YAAY,CAA+B,IAAY;QACrD,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAM,CAAC;QACxC,CAAC;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,gBAAgB,CAAqB,IAAI,CAAC,CAAC;QACnE,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC5B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;YACvD,OAAO,UAAU,CAAC,CAAC,CAAM,CAAC;QAC5B,CAAC;aAAM,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnC,IAAI,CAAC,aAAa,CAChB,eAAe,EACf,kCAAkC,IAAI,EAAE,CACzC,CAAC;YACF,OAAO,SAAS,CAAC;QACnB,CAAC;aAAM,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACjC,IAAI,CAAC,aAAa,CAChB,eAAe,EACf,YAAY,IAAI,+EAA+E,CAChG,CAAC;YACF,OAAO,UAAU,CAAC,CAAC,CAAM,CAAC;QAC5B,CAAC;IACH,CAAC;CACF","sourcesContent":["import { ObservableEntity, ObserverList } from \"../Entities\";\r\nimport { AppObject, makeAppObject } from \"./AppObject\";\r\nimport { AppObjectComponent } from \"./AppObjectComponent\";\r\n\r\n/**\r\n * Abstract repository class for managing AppObjects and their components.\r\n *\r\n * This class provides the interface for storing, retrieving, and managing application\r\n * objects, their components, and singletons. It also includes logging functionality\r\n * and observer pattern implementation for tracking changes to the repository.\r\n *\r\n * @extends ObservableEntity\r\n */\r\nexport abstract class AppObjectRepo extends ObservableEntity {\r\n /**\r\n * Checks if an AppObject with the specified ID exists in the repository.\r\n *\r\n * @param {string} appObjectID - The ID of the AppObject to check\r\n * @returns {boolean} True if the AppObject exists, false otherwise\r\n */\r\n abstract has(appObjectID: string): boolean;\r\n\r\n /**\r\n * Adds an AppObject to the repository.\r\n *\r\n * @param {AppObject} appObject - The AppObject to add\r\n */\r\n abstract add(appObject: AppObject): void;\r\n\r\n /**\r\n * Removes an AppObject with the specified ID from the repository.\r\n *\r\n * @param {string} appObjectID - The ID of the AppObject to remove\r\n */\r\n abstract remove(appObjectID: string): void;\r\n\r\n /**\r\n * Gets an AppObject by its ID.\r\n *\r\n * @param {string} appObjectID - The ID of the AppObject to retrieve\r\n * @returns {AppObject | undefined} The AppObject if found, undefined otherwise\r\n */\r\n abstract get(appObjectID: string): AppObject | undefined;\r\n\r\n /**\r\n * Gets an AppObject by its ID, or creates a new one if it doesn't exist.\r\n *\r\n * @param {string} appObjectID - The ID of the AppObject to retrieve or create\r\n * @returns {AppObject} The existing or newly created AppObject\r\n */\r\n abstract getOrCreate(appObjectID: string): AppObject;\r\n\r\n /**\r\n * Gets all AppObjects in the repository.\r\n *\r\n * @returns {AppObject[]} An array of all AppObjects\r\n */\r\n abstract getAll(): AppObject[];\r\n\r\n /**\r\n * Logs an informational message.\r\n *\r\n * @param {string} sender - The identifier of the message sender\r\n * @param {string} message - The message to log\r\n */\r\n abstract submitLog(sender: string, message: string): void;\r\n\r\n /**\r\n * Logs a warning message.\r\n *\r\n * @param {string} sender - The identifier of the message sender\r\n * @param {string} message - The warning message to log\r\n */\r\n abstract submitWarning(sender: string, message: string): void;\r\n\r\n /**\r\n * Logs an error message.\r\n *\r\n * @param {string} sender - The identifier of the message sender\r\n * @param {string} message - The error message to log\r\n */\r\n abstract submitError(sender: string, message: string): void;\r\n\r\n /**\r\n * Logs a fatal error message.\r\n *\r\n * @param {string} sender - The identifier of the message sender\r\n * @param {string} message - The fatal error message to log\r\n */\r\n abstract submitFatal(sender: string, message: string): void;\r\n\r\n /**\r\n * Registers a component as a singleton in the repository.\r\n *\r\n * @param {AppObjectComponent} component - The component to register as a singleton\r\n */\r\n abstract registerSingleton(component: AppObjectComponent): void;\r\n\r\n /**\r\n * Checks if a singleton component of the specified type exists.\r\n *\r\n * @param {string} type - The type of the singleton to check\r\n * @returns {boolean} True if a singleton of the specified type exists, false otherwise\r\n */\r\n abstract hasSingleton(type: string): boolean;\r\n\r\n /**\r\n * Gets a singleton component of the specified type.\r\n *\r\n * @template T - Type of the component to retrieve, must extend AppObjectComponent\r\n * @param {string} type - The type of the singleton to retrieve\r\n * @returns {T | undefined} The singleton component if found, undefined otherwise\r\n */\r\n abstract getSingleton<T extends AppObjectComponent>(\r\n type: string\r\n ): T | undefined;\r\n\r\n /**\r\n * Gets a component of the specified type from an AppObject.\r\n *\r\n * @template T - Type of the component to retrieve, must extend AppObjectComponent\r\n * @param {string} appObjectID - The ID of the AppObject containing the component\r\n * @param {string} type - The type of the component to retrieve\r\n * @returns {T | undefined} The component if found, undefined otherwise\r\n */\r\n abstract getAppObjectComponent<T extends AppObjectComponent>(\r\n appObjectID: string,\r\n type: string\r\n ): T | undefined;\r\n\r\n /**\r\n * Gets all AppObjects that have a component of the specified type.\r\n *\r\n * @param {string} componentType - The component type to filter by\r\n * @returns {AppObject[]} An array of AppObjects having the specified component type\r\n */\r\n abstract getAllAppObjectsWithComponent(componentType: string): AppObject[];\r\n\r\n /**\r\n * Gets all components of the specified type across all AppObjects.\r\n *\r\n * @template T - Type of the components to retrieve, must extend AppObjectComponent\r\n * @param {string} type - The type of components to retrieve\r\n * @returns {T[]} An array of all components of the specified type\r\n */\r\n abstract getAllComponents<T extends AppObjectComponent>(type: string): T[];\r\n\r\n /**\r\n * Adds an observer to be notified when an AppObject is added to the repository.\r\n *\r\n * @param {(addedEntity: AppObject) => void} observer - The observer function\r\n */\r\n abstract addAppObjectAddedObserver: (\r\n observer: (addedEntity: AppObject) => void\r\n ) => void;\r\n\r\n /**\r\n * Removes an observer previously registered for AppObject addition notifications.\r\n *\r\n * @param {(addedEntity: AppObject) => void} observer - The observer function to remove\r\n */\r\n abstract removeAppObjectAddedObserver: (\r\n observer: (addedEntity: AppObject) => void\r\n ) => void;\r\n\r\n /**\r\n * Adds an observer to be notified when an AppObject is removed from the repository.\r\n *\r\n * @param {(addedEntity: AppObject) => void} observer - The observer function\r\n */\r\n abstract addAppObjectRemovedObserver: (\r\n observer: (addedEntity: AppObject) => void\r\n ) => void;\r\n\r\n /**\r\n * Removes an observer previously registered for AppObject removal notifications.\r\n *\r\n * @param {(addedEntity: AppObject) => void} observer - The observer function to remove\r\n */\r\n abstract removedAppObjectRemovedObserver: (\r\n observer: (addedEntity: AppObject) => void\r\n ) => void;\r\n}\r\n\r\n/**\r\n * Creates and returns a new AppObjectRepo instance.\r\n *\r\n * @returns {AppObjectRepo} A new AppObjectRepo instance\r\n */\r\nexport function makeAppObjectRepo(): AppObjectRepo {\r\n return new AppObjectRepoImp();\r\n}\r\n\r\n/**\r\n * Implementation of the AppObjectRepo abstract class.\r\n *\r\n * @private\r\n * @extends AppObjectRepo\r\n */\r\nclass AppObjectRepoImp extends AppObjectRepo {\r\n private appObjectLookup = new Map<string, AppObject>();\r\n private singletons = new Map<string, AppObjectComponent>();\r\n\r\n private onAppObjectAddedObserver = new ObserverList<AppObject>();\r\n addAppObjectAddedObserver = (observer: (addedEntity: AppObject) => void) => {\r\n this.onAppObjectAddedObserver.add(observer);\r\n };\r\n removeAppObjectAddedObserver = (\r\n observer: (addedEntity: AppObject) => void\r\n ): void => {\r\n this.onAppObjectAddedObserver.remove(observer);\r\n };\r\n\r\n private onAppObjectRemovedObservers = new ObserverList<AppObject>();\r\n addAppObjectRemovedObserver = (\r\n observer: (removedEntity: AppObject) => void\r\n ) => {\r\n this.onAppObjectRemovedObservers.add(observer);\r\n };\r\n removedAppObjectRemovedObserver = (\r\n observer: (removedEntity: AppObject) => void\r\n ): void => {\r\n this.onAppObjectRemovedObservers.remove(observer);\r\n };\r\n\r\n has = (id: string): boolean => {\r\n return this.appObjectLookup.has(id);\r\n };\r\n\r\n add = (appObject: AppObject) => {\r\n const existing = this.appObjectLookup.get(appObject.id);\r\n if (existing) {\r\n existing.removeObserver(this.notify);\r\n }\r\n\r\n this.appObjectLookup.set(appObject.id, appObject);\r\n appObject.addObserver(this.notify);\r\n this.notify();\r\n this.onAppObjectAddedObserver.notify(appObject);\r\n };\r\n\r\n remove = (id: string) => {\r\n const existing = this.appObjectLookup.get(id);\r\n if (!existing) return;\r\n\r\n this.appObjectLookup.delete(id);\r\n existing.removeObserver(this.notify);\r\n this.notify();\r\n this.onAppObjectRemovedObservers.notify(existing);\r\n };\r\n\r\n get = (id: string): AppObject | undefined => {\r\n return this.appObjectLookup.get(id);\r\n };\r\n\r\n getOrCreate = (id: string): AppObject => {\r\n const existing = this.appObjectLookup.get(id);\r\n\r\n if (!existing) {\r\n return makeAppObject(id, this);\r\n } else {\r\n return existing;\r\n }\r\n };\r\n\r\n getAll = (): AppObject[] => {\r\n return Array.from(this.appObjectLookup.values());\r\n };\r\n\r\n getAllAppObjectsWithComponent(componentType: string): AppObject[] {\r\n const rArray: AppObject[] = [];\r\n\r\n this.appObjectLookup.forEach((appObj) => {\r\n if (appObj.hasComponent(componentType)) {\r\n rArray.push(appObj);\r\n }\r\n });\r\n\r\n return rArray;\r\n }\r\n\r\n getAllComponents<T extends AppObjectComponent>(type: string): T[] {\r\n const rArray: T[] = [];\r\n\r\n this.appObjectLookup.forEach((appObj) => {\r\n const aoEntity = appObj.getComponent(type);\r\n if (aoEntity) {\r\n rArray.push(aoEntity as T);\r\n }\r\n });\r\n\r\n return rArray;\r\n }\r\n\r\n getAppObjectComponent<T extends AppObjectComponent>(\r\n id: string,\r\n entityType: string\r\n ): T | undefined {\r\n const ao = this.appObjectLookup.get(id);\r\n if (!ao) {\r\n return undefined;\r\n }\r\n\r\n return ao.getComponent(entityType) as T;\r\n }\r\n\r\n submitLog(sender: string, message: string): void {\r\n console.log(`[${sender}]: ${message}`);\r\n }\r\n submitWarning(sender: string, message: string): void {\r\n console.warn(`[${sender}]: ${message}`);\r\n }\r\n submitError(sender: string, message: string): void {\r\n console.error(`[${sender}]: ${message}`);\r\n }\r\n submitFatal(sender: string, message: string): void {\r\n console.error(`FATAL ERROR - [${sender}]: ${message}`);\r\n }\r\n\r\n registerSingleton(component: AppObjectComponent): void {\r\n if (this.singletons.has(component.type)) {\r\n this.submitWarning(\r\n \"AppObjectRepo\",\r\n `Singleton for type ${component.type} already exists. Relpacing`\r\n );\r\n }\r\n\r\n this.singletons.set(component.type, component);\r\n }\r\n\r\n hasSingleton(type: string): boolean {\r\n if (this.singletons.has(type)) {\r\n return true;\r\n }\r\n\r\n const components = this.getAllComponents<AppObjectComponent>(type);\r\n return components.length === 1;\r\n }\r\n\r\n getSingleton<T extends AppObjectComponent>(type: string): T | undefined {\r\n if (this.singletons.has(type)) {\r\n return this.singletons.get(type) as T;\r\n }\r\n\r\n const components = this.getAllComponents<AppObjectComponent>(type);\r\n if (components.length === 1) {\r\n this.singletons.set(components[0].type, components[0]);\r\n return components[0] as T;\r\n } else if (components.length === 0) {\r\n this.submitWarning(\r\n \"AppObjectRepo\",\r\n `Unable to find a singleton for ${type}`\r\n );\r\n return undefined;\r\n } else if (components.length > 1) {\r\n this.submitWarning(\r\n \"AppObjectRepo\",\r\n `Multiple ${type} found. There should only be one if it truly a singleton. Using the first one`\r\n );\r\n return components[0] as T;\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"AppObjectRepo.js","sourceRoot":"","sources":["../../../src/AppObject/AppObjectRepo.ts"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,CAAC,CAAC;QACnE,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC5B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;YACvD,OAAO,UAAU,CAAC,CAAC,CAAM,CAAC;QAC5B,CAAC;aAAM,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnC,IAAI,CAAC,aAAa,CAChB,eAAe,EACf,kCAAkC,IAAI,EAAE,CACzC,CAAC;YACF,OAAO,SAAS,CAAC;QACnB,CAAC;aAAM,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACjC,IAAI,CAAC,aAAa,CAChB,eAAe,EACf,YAAY,IAAI,+EAA+E,CAChG,CAAC;YACF,OAAO,UAAU,CAAC,CAAC,CAAM,CAAC;QAC5B,CAAC;IACH,CAAC;CACF","sourcesContent":["import { ObservableEntity, ObserverList } from \"../Entities\";\r\nimport { AppObject, makeAppObject } from \"./AppObject\";\r\nimport { AppObjectComponent } from \"./AppObjectComponent\";\r\n\r\n/**\r\n * Abstract repository class for managing AppObjects and their components.\r\n *\r\n * This class provides the interface for storing, retrieving, and managing application\r\n * objects, their components, and singletons. It also includes logging functionality\r\n * and observer pattern implementation for tracking changes to the repository.\r\n *\r\n * @extends ObservableEntity\r\n */\r\nexport abstract class AppObjectRepo extends ObservableEntity {\r\n /**\r\n * Checks if an AppObject with the specified ID exists in the repository.\r\n *\r\n * @param {string} appObjectID - The ID of the AppObject to check\r\n * @returns {boolean} True if the AppObject exists, false otherwise\r\n */\r\n abstract has(appObjectID: string): boolean;\r\n\r\n /**\r\n * Adds an AppObject to the repository.\r\n *\r\n * @param {AppObject} appObject - The AppObject to add\r\n */\r\n abstract add(appObject: AppObject): void;\r\n\r\n /**\r\n * Removes an AppObject with the specified ID from the repository.\r\n *\r\n * @param {string} appObjectID - The ID of the AppObject to remove\r\n */\r\n abstract remove(appObjectID: string): void;\r\n\r\n /**\r\n * Gets an AppObject by its ID.\r\n *\r\n * @param {string} appObjectID - The ID of the AppObject to retrieve\r\n * @returns {AppObject | undefined} The AppObject if found, undefined otherwise\r\n */\r\n abstract get(appObjectID: string): AppObject | undefined;\r\n\r\n /**\r\n * Gets an AppObject by its ID, or creates a new one if it doesn't exist.\r\n *\r\n * @param {string} appObjectID - The ID of the AppObject to retrieve or create\r\n * @returns {AppObject} The existing or newly created AppObject\r\n */\r\n abstract getOrCreate(appObjectID: string): AppObject;\r\n\r\n /**\r\n * Gets all AppObjects in the repository.\r\n *\r\n * @returns {AppObject[]} An array of all AppObjects\r\n */\r\n abstract getAll(): AppObject[];\r\n\r\n /**\r\n * Logs an informational message.\r\n *\r\n * @param {string} sender - The identifier of the message sender\r\n * @param {string} message - The message to log\r\n */\r\n abstract submitLog(sender: string, message: string): void;\r\n\r\n /**\r\n * Logs a warning message.\r\n *\r\n * @param {string} sender - The identifier of the message sender\r\n * @param {string} message - The warning message to log\r\n */\r\n abstract submitWarning(sender: string, message: string): void;\r\n\r\n /**\r\n * Logs an error message.\r\n *\r\n * @param {string} sender - The identifier of the message sender\r\n * @param {string} message - The error message to log\r\n */\r\n abstract submitError(sender: string, message: string): void;\r\n\r\n /**\r\n * Logs a fatal error message.\r\n *\r\n * @param {string} sender - The identifier of the message sender\r\n * @param {string} message - The fatal error message to log\r\n */\r\n abstract submitFatal(sender: string, message: string): void;\r\n\r\n /**\r\n * Registers a component as a singleton in the repository.\r\n *\r\n * @param {AppObjectComponent} component - The component to register as a singleton\r\n */\r\n abstract registerSingleton(component: AppObjectComponent): void;\r\n\r\n /**\r\n * Unregisters a singleton component from the repository.\r\n *\r\n * @param {string} type - The type of the singleton to unregister\r\n */\r\n abstract unregisterSingleton(type: string): void;\r\n\r\n /**\r\n * Checks if a singleton component of the specified type exists.\r\n *\r\n * @param {string} type - The type of the singleton to check\r\n * @returns {boolean} True if a singleton of the specified type exists, false otherwise\r\n */\r\n abstract hasSingleton(type: string): boolean;\r\n\r\n /**\r\n * Gets a singleton component of the specified type.\r\n *\r\n * @template T - Type of the component to retrieve, must extend AppObjectComponent\r\n * @param {string} type - The type of the singleton to retrieve\r\n * @returns {T | undefined} The singleton component if found, undefined otherwise\r\n */\r\n abstract getSingleton<T extends AppObjectComponent>(\r\n type: string\r\n ): T | undefined;\r\n\r\n /**\r\n * Gets a component of the specified type from an AppObject.\r\n *\r\n * @template T - Type of the component to retrieve, must extend AppObjectComponent\r\n * @param {string} appObjectID - The ID of the AppObject containing the component\r\n * @param {string} type - The type of the component to retrieve\r\n * @returns {T | undefined} The component if found, undefined otherwise\r\n */\r\n abstract getAppObjectComponent<T extends AppObjectComponent>(\r\n appObjectID: string,\r\n type: string\r\n ): T | undefined;\r\n\r\n /**\r\n * Gets all AppObjects that have a component of the specified type.\r\n *\r\n * @param {string} componentType - The component type to filter by\r\n * @returns {AppObject[]} An array of AppObjects having the specified component type\r\n */\r\n abstract getAllAppObjectsWithComponent(componentType: string): AppObject[];\r\n\r\n /**\r\n * Gets all components of the specified type across all AppObjects.\r\n *\r\n * @template T - Type of the components to retrieve, must extend AppObjectComponent\r\n * @param {string} type - The type of components to retrieve\r\n * @returns {T[]} An array of all components of the specified type\r\n */\r\n abstract getAllComponents<T extends AppObjectComponent>(type: string): T[];\r\n\r\n /**\r\n * Adds an observer to be notified when an AppObject is added to the repository.\r\n *\r\n * @param {(addedEntity: AppObject) => void} observer - The observer function\r\n */\r\n abstract addAppObjectAddedObserver: (\r\n observer: (addedEntity: AppObject) => void\r\n ) => void;\r\n\r\n /**\r\n * Removes an observer previously registered for AppObject addition notifications.\r\n *\r\n * @param {(addedEntity: AppObject) => void} observer - The observer function to remove\r\n */\r\n abstract removeAppObjectAddedObserver: (\r\n observer: (addedEntity: AppObject) => void\r\n ) => void;\r\n\r\n /**\r\n * Adds an observer to be notified when an AppObject is removed from the repository.\r\n *\r\n * @param {(addedEntity: AppObject) => void} observer - The observer function\r\n */\r\n abstract addAppObjectRemovedObserver: (\r\n observer: (addedEntity: AppObject) => void\r\n ) => void;\r\n\r\n /**\r\n * Removes an observer previously registered for AppObject removal notifications.\r\n *\r\n * @param {(addedEntity: AppObject) => void} observer - The observer function to remove\r\n */\r\n abstract removedAppObjectRemovedObserver: (\r\n observer: (addedEntity: AppObject) => void\r\n ) => void;\r\n}\r\n\r\n/**\r\n * Creates and returns a new AppObjectRepo instance.\r\n *\r\n * @returns {AppObjectRepo} A new AppObjectRepo instance\r\n */\r\nexport function makeAppObjectRepo(): AppObjectRepo {\r\n return new AppObjectRepoImp();\r\n}\r\n\r\n/**\r\n * Implementation of the AppObjectRepo abstract class.\r\n *\r\n * @private\r\n * @extends AppObjectRepo\r\n */\r\nclass AppObjectRepoImp extends AppObjectRepo {\r\n private appObjectLookup = new Map<string, AppObject>();\r\n private singletons = new Map<string, AppObjectComponent>();\r\n\r\n private onAppObjectAddedObserver = new ObserverList<AppObject>();\r\n addAppObjectAddedObserver = (observer: (addedEntity: AppObject) => void) => {\r\n this.onAppObjectAddedObserver.add(observer);\r\n };\r\n removeAppObjectAddedObserver = (\r\n observer: (addedEntity: AppObject) => void\r\n ): void => {\r\n this.onAppObjectAddedObserver.remove(observer);\r\n };\r\n\r\n private onAppObjectRemovedObservers = new ObserverList<AppObject>();\r\n addAppObjectRemovedObserver = (\r\n observer: (removedEntity: AppObject) => void\r\n ) => {\r\n this.onAppObjectRemovedObservers.add(observer);\r\n };\r\n removedAppObjectRemovedObserver = (\r\n observer: (removedEntity: AppObject) => void\r\n ): void => {\r\n this.onAppObjectRemovedObservers.remove(observer);\r\n };\r\n\r\n has = (id: string): boolean => {\r\n return this.appObjectLookup.has(id);\r\n };\r\n\r\n add = (appObject: AppObject) => {\r\n const existing = this.appObjectLookup.get(appObject.id);\r\n if (existing) {\r\n existing.removeObserver(this.notify);\r\n }\r\n\r\n this.appObjectLookup.set(appObject.id, appObject);\r\n appObject.addObserver(this.notify);\r\n this.notify();\r\n this.onAppObjectAddedObserver.notify(appObject);\r\n };\r\n\r\n remove = (id: string) => {\r\n const existing = this.appObjectLookup.get(id);\r\n if (!existing) return;\r\n\r\n this.appObjectLookup.delete(id);\r\n existing.removeObserver(this.notify);\r\n this.notify();\r\n this.onAppObjectRemovedObservers.notify(existing);\r\n };\r\n\r\n get = (id: string): AppObject | undefined => {\r\n return this.appObjectLookup.get(id);\r\n };\r\n\r\n getOrCreate = (id: string): AppObject => {\r\n const existing = this.appObjectLookup.get(id);\r\n\r\n if (!existing) {\r\n return makeAppObject(id, this);\r\n } else {\r\n return existing;\r\n }\r\n };\r\n\r\n getAll = (): AppObject[] => {\r\n return Array.from(this.appObjectLookup.values());\r\n };\r\n\r\n getAllAppObjectsWithComponent(componentType: string): AppObject[] {\r\n const rArray: AppObject[] = [];\r\n\r\n this.appObjectLookup.forEach((appObj) => {\r\n if (appObj.hasComponent(componentType)) {\r\n rArray.push(appObj);\r\n }\r\n });\r\n\r\n return rArray;\r\n }\r\n\r\n getAllComponents<T extends AppObjectComponent>(type: string): T[] {\r\n const rArray: T[] = [];\r\n\r\n this.appObjectLookup.forEach((appObj) => {\r\n const aoEntity = appObj.getComponent(type);\r\n if (aoEntity) {\r\n rArray.push(aoEntity as T);\r\n }\r\n });\r\n\r\n return rArray;\r\n }\r\n\r\n getAppObjectComponent<T extends AppObjectComponent>(\r\n id: string,\r\n entityType: string\r\n ): T | undefined {\r\n const ao = this.appObjectLookup.get(id);\r\n if (!ao) {\r\n return undefined;\r\n }\r\n\r\n return ao.getComponent(entityType) as T;\r\n }\r\n\r\n submitLog(sender: string, message: string): void {\r\n console.log(`[${sender}]: ${message}`);\r\n }\r\n submitWarning(sender: string, message: string): void {\r\n console.warn(`[${sender}]: ${message}`);\r\n }\r\n submitError(sender: string, message: string): void {\r\n console.error(`[${sender}]: ${message}`);\r\n }\r\n submitFatal(sender: string, message: string): void {\r\n console.error(`FATAL ERROR - [${sender}]: ${message}`);\r\n }\r\n\r\n registerSingleton(component: AppObjectComponent): void {\r\n if (this.singletons.has(component.type)) {\r\n this.submitWarning(\r\n \"AppObjectRepo\",\r\n `Singleton for type ${component.type} already exists. Replacing`\r\n );\r\n }\r\n\r\n this.singletons.set(component.type, component);\r\n }\r\n\r\n unregisterSingleton(type: string): void {\r\n this.singletons.delete(type);\r\n }\r\n\r\n hasSingleton(type: string): boolean {\r\n if (this.singletons.has(type)) {\r\n return true;\r\n }\r\n\r\n const components = this.getAllComponents<AppObjectComponent>(type);\r\n return components.length === 1;\r\n }\r\n\r\n getSingleton<T extends AppObjectComponent>(type: string): T | undefined {\r\n if (this.singletons.has(type)) {\r\n return this.singletons.get(type) as T;\r\n }\r\n\r\n const components = this.getAllComponents<AppObjectComponent>(type);\r\n if (components.length === 1) {\r\n this.singletons.set(components[0].type, components[0]);\r\n return components[0] as T;\r\n } else if (components.length === 0) {\r\n this.submitWarning(\r\n \"AppObjectRepo\",\r\n `Unable to find a singleton for ${type}`\r\n );\r\n return undefined;\r\n } else if (components.length > 1) {\r\n this.submitWarning(\r\n \"AppObjectRepo\",\r\n `Multiple ${type} found. There should only be one if it truly a singleton. Using the first one`\r\n );\r\n return components[0] as T;\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AppObjectEntity } from "./AppObjectEntity";
|
|
2
|
+
/**
|
|
3
|
+
* Singleton entity component that manages application state
|
|
4
|
+
*
|
|
5
|
+
* AppObjectSingletonEntity extends AppObjectEntity and automatically registers itself
|
|
6
|
+
* as a singleton in the AppObjectRepo upon construction. This ensures only one instance
|
|
7
|
+
* of this entity type exists across the entire application.
|
|
8
|
+
*
|
|
9
|
+
* Use this class when you need an entity that should have only one instance globally,
|
|
10
|
+
* such as application-wide configuration or shared state managers.
|
|
11
|
+
*/
|
|
12
|
+
export class AppObjectSingletonEntity extends AppObjectEntity {
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new singleton entity component and attaches it to the specified AppObject
|
|
15
|
+
* Automatically registers itself as a singleton in the AppObjectRepo
|
|
16
|
+
*
|
|
17
|
+
* @param appObject The parent AppObject this component will be attached to
|
|
18
|
+
* @param type The unique type identifier for this component
|
|
19
|
+
*/
|
|
20
|
+
constructor(appObject, type) {
|
|
21
|
+
super(appObject, type);
|
|
22
|
+
this.appObjects.registerSingleton(this);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Cleans up resources and unregisters the singleton
|
|
26
|
+
*
|
|
27
|
+
* This method:
|
|
28
|
+
* 1. Unregisters itself from the singleton registry
|
|
29
|
+
* 2. Calls the parent class dispose method
|
|
30
|
+
*/
|
|
31
|
+
dispose() {
|
|
32
|
+
this.appObjects.unregisterSingleton(this.type);
|
|
33
|
+
super.dispose();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=AppObjectSingletonEntity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AppObjectSingletonEntity.js","sourceRoot":"","sources":["../../../src/AppObject/AppObjectSingletonEntity.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;;;;;;GASG;AACH,MAAM,OAAO,wBAAyB,SAAQ,eAAe;IAC3D;;;;;;OAMG;IACH,YAAY,SAAoB,EAAE,IAAY;QAC5C,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAEvB,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;;OAMG;IACH,OAAO;QACL,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/C,KAAK,CAAC,OAAO,EAAE,CAAC;IAClB,CAAC;CACF","sourcesContent":["import { AppObject } from \"./AppObject\";\r\nimport { AppObjectEntity } from \"./AppObjectEntity\";\r\n\r\n/**\r\n * Singleton entity component that manages application state\r\n *\r\n * AppObjectSingletonEntity extends AppObjectEntity and automatically registers itself\r\n * as a singleton in the AppObjectRepo upon construction. This ensures only one instance\r\n * of this entity type exists across the entire application.\r\n *\r\n * Use this class when you need an entity that should have only one instance globally,\r\n * such as application-wide configuration or shared state managers.\r\n */\r\nexport class AppObjectSingletonEntity extends AppObjectEntity {\r\n /**\r\n * Creates a new singleton entity component and attaches it to the specified AppObject\r\n * Automatically registers itself as a singleton in the AppObjectRepo\r\n *\r\n * @param appObject The parent AppObject this component will be attached to\r\n * @param type The unique type identifier for this component\r\n */\r\n constructor(appObject: AppObject, type: string) {\r\n super(appObject, type);\r\n\r\n this.appObjects.registerSingleton(this);\r\n }\r\n\r\n /**\r\n * Cleans up resources and unregisters the singleton\r\n *\r\n * This method:\r\n * 1. Unregisters itself from the singleton registry\r\n * 2. Calls the parent class dispose method\r\n */\r\n dispose() {\r\n this.appObjects.unregisterSingleton(this.type);\r\n super.dispose();\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { AppObjectEntityRepo } from "./AppObjectEntityRepo";
|
|
2
|
+
/**
|
|
3
|
+
* A singleton repository for managing collections of AppObjectEntity instances.
|
|
4
|
+
*
|
|
5
|
+
* This generic class extends AppObjectEntityRepo and automatically registers itself
|
|
6
|
+
* as a singleton in the AppObjectRepo upon construction. This ensures only one instance
|
|
7
|
+
* of this repository type exists across the entire application.
|
|
8
|
+
*
|
|
9
|
+
* Use this class when you need a centralized repository that should have only one instance
|
|
10
|
+
* globally, such as application-wide entity collections or shared resource managers.
|
|
11
|
+
*
|
|
12
|
+
* @template T - The type of entities managed by this repository, must extend AppObjectEntity
|
|
13
|
+
* @extends AppObjectEntityRepo
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Create a singleton repository for player entities
|
|
18
|
+
* class PlayerRepo extends AppObjectSingletonEntityRepo<PlayerEntity> {
|
|
19
|
+
* static type = "playerRepo";
|
|
20
|
+
* constructor(appObject: AppObject) {
|
|
21
|
+
* super(appObject, PlayerRepo.type);
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export class AppObjectSingletonEntityRepo extends AppObjectEntityRepo {
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new singleton entity repository component and attaches it to the specified AppObject
|
|
29
|
+
* Automatically registers itself as a singleton in the AppObjectRepo
|
|
30
|
+
*
|
|
31
|
+
* @param appObject The parent AppObject this component will be attached to
|
|
32
|
+
* @param type The unique type identifier for this component
|
|
33
|
+
*/
|
|
34
|
+
constructor(appObject, type) {
|
|
35
|
+
super(appObject, type);
|
|
36
|
+
this.appObjects.registerSingleton(this);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Cleans up resources and unregisters the singleton
|
|
40
|
+
*
|
|
41
|
+
* This method:
|
|
42
|
+
* 1. Unregisters itself from the singleton registry
|
|
43
|
+
* 2. Calls the parent class dispose method
|
|
44
|
+
*/
|
|
45
|
+
dispose() {
|
|
46
|
+
this.appObjects.unregisterSingleton(this.type);
|
|
47
|
+
super.dispose();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=AppObjectSingletonEntityRepo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AppObjectSingletonEntityRepo.js","sourceRoot":"","sources":["../../../src/AppObject/AppObjectSingletonEntityRepo.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,4BAEX,SAAQ,mBAAsB;IAC9B;;;;;;OAMG;IACH,YAAY,SAAoB,EAAE,IAAY;QAC5C,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAEvB,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;;OAMG;IACH,OAAO;QACL,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/C,KAAK,CAAC,OAAO,EAAE,CAAC;IAClB,CAAC;CACF","sourcesContent":["import { AppObject } from \"./AppObject\";\r\nimport { AppObjectEntity } from \"./AppObjectEntity\";\r\nimport { AppObjectEntityRepo } from \"./AppObjectEntityRepo\";\r\n\r\n/**\r\n * A singleton repository for managing collections of AppObjectEntity instances.\r\n *\r\n * This generic class extends AppObjectEntityRepo and automatically registers itself\r\n * as a singleton in the AppObjectRepo upon construction. This ensures only one instance\r\n * of this repository type exists across the entire application.\r\n *\r\n * Use this class when you need a centralized repository that should have only one instance\r\n * globally, such as application-wide entity collections or shared resource managers.\r\n *\r\n * @template T - The type of entities managed by this repository, must extend AppObjectEntity\r\n * @extends AppObjectEntityRepo\r\n *\r\n * @example\r\n * ```typescript\r\n * // Create a singleton repository for player entities\r\n * class PlayerRepo extends AppObjectSingletonEntityRepo<PlayerEntity> {\r\n * static type = \"playerRepo\";\r\n * constructor(appObject: AppObject) {\r\n * super(appObject, PlayerRepo.type);\r\n * }\r\n * }\r\n * ```\r\n */\r\nexport class AppObjectSingletonEntityRepo<\r\n T extends AppObjectEntity,\r\n> extends AppObjectEntityRepo<T> {\r\n /**\r\n * Creates a new singleton entity repository component and attaches it to the specified AppObject\r\n * Automatically registers itself as a singleton in the AppObjectRepo\r\n *\r\n * @param appObject The parent AppObject this component will be attached to\r\n * @param type The unique type identifier for this component\r\n */\r\n constructor(appObject: AppObject, type: string) {\r\n super(appObject, type);\r\n\r\n this.appObjects.registerSingleton(this);\r\n }\r\n\r\n /**\r\n * Cleans up resources and unregisters the singleton\r\n *\r\n * This method:\r\n * 1. Unregisters itself from the singleton registry\r\n * 2. Calls the parent class dispose method\r\n */\r\n dispose() {\r\n this.appObjects.unregisterSingleton(this.type);\r\n super.dispose();\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { AppObjectPM } from "./AppObjectPM";
|
|
2
|
+
/**
|
|
3
|
+
* Singleton Presentation Manager (PM) component that transforms application state into view models
|
|
4
|
+
*
|
|
5
|
+
* AppObjectSingletonPM extends AppObjectPM and automatically registers itself as a singleton
|
|
6
|
+
* in the AppObjectRepo upon construction. This ensures only one instance of this PM type exists
|
|
7
|
+
* across the entire application.
|
|
8
|
+
*
|
|
9
|
+
* Use this class when you need a presentation manager that should have only one instance globally,
|
|
10
|
+
* such as application-wide UI state managers or shared view model providers.
|
|
11
|
+
*
|
|
12
|
+
* A singleton PM typically:
|
|
13
|
+
* 1. Observes entity changes
|
|
14
|
+
* 2. Transforms entity data into view models
|
|
15
|
+
* 3. Notifies attached views when view models change
|
|
16
|
+
* 4. Handles view model caching and optimization
|
|
17
|
+
* 5. Exists as a single instance across the application
|
|
18
|
+
*
|
|
19
|
+
* @typeparam T The view model type this PM produces
|
|
20
|
+
* @extends AppObjectPM
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* class GlobalSettingsPM extends AppObjectSingletonPM<SettingsVM> {
|
|
25
|
+
* static type = "globalSettingsPM";
|
|
26
|
+
*
|
|
27
|
+
* constructor(appObject: AppObject) {
|
|
28
|
+
* super(appObject, GlobalSettingsPM.type);
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* vmsAreEqual(a: SettingsVM, b: SettingsVM): boolean {
|
|
32
|
+
* return a.theme === b.theme && a.language === b.language;
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* formVM(): void {
|
|
36
|
+
* // Form view model from entities
|
|
37
|
+
* }
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export class AppObjectSingletonPM extends AppObjectPM {
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new singleton presentation manager component and attaches it to the specified AppObject
|
|
44
|
+
* Automatically registers itself as a singleton in the AppObjectRepo
|
|
45
|
+
*
|
|
46
|
+
* @param appObject The parent AppObject this component will be attached to
|
|
47
|
+
* @param type The unique type identifier for this component
|
|
48
|
+
*/
|
|
49
|
+
constructor(appObject, type) {
|
|
50
|
+
super(appObject, type);
|
|
51
|
+
this.appObjects.registerSingleton(this);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Cleans up resources and unregisters the singleton
|
|
55
|
+
*
|
|
56
|
+
* This method:
|
|
57
|
+
* 1. Unregisters itself from the singleton registry
|
|
58
|
+
* 2. Calls the parent class dispose method (which handles entity observers and views)
|
|
59
|
+
*/
|
|
60
|
+
dispose() {
|
|
61
|
+
this.appObjects.unregisterSingleton(this.type);
|
|
62
|
+
super.dispose();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=AppObjectSingletonPM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AppObjectSingletonPM.js","sourceRoot":"","sources":["../../../src/AppObject/AppObjectSingletonPM.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,OAAgB,oBAAwB,SAAQ,WAAc;IAClE;;;;;;OAMG;IACH,YAAY,SAAoB,EAAE,IAAY;QAC5C,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAEvB,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;;OAMG;IACH,OAAO;QACL,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/C,KAAK,CAAC,OAAO,EAAE,CAAC;IAClB,CAAC;CACF","sourcesContent":["import { AppObject } from \"./AppObject\";\r\nimport { AppObjectPM } from \"./AppObjectPM\";\r\n\r\n/**\r\n * Singleton Presentation Manager (PM) component that transforms application state into view models\r\n *\r\n * AppObjectSingletonPM extends AppObjectPM and automatically registers itself as a singleton\r\n * in the AppObjectRepo upon construction. This ensures only one instance of this PM type exists\r\n * across the entire application.\r\n *\r\n * Use this class when you need a presentation manager that should have only one instance globally,\r\n * such as application-wide UI state managers or shared view model providers.\r\n *\r\n * A singleton PM typically:\r\n * 1. Observes entity changes\r\n * 2. Transforms entity data into view models\r\n * 3. Notifies attached views when view models change\r\n * 4. Handles view model caching and optimization\r\n * 5. Exists as a single instance across the application\r\n *\r\n * @typeparam T The view model type this PM produces\r\n * @extends AppObjectPM\r\n *\r\n * @example\r\n * ```typescript\r\n * class GlobalSettingsPM extends AppObjectSingletonPM<SettingsVM> {\r\n * static type = \"globalSettingsPM\";\r\n *\r\n * constructor(appObject: AppObject) {\r\n * super(appObject, GlobalSettingsPM.type);\r\n * }\r\n *\r\n * vmsAreEqual(a: SettingsVM, b: SettingsVM): boolean {\r\n * return a.theme === b.theme && a.language === b.language;\r\n * }\r\n *\r\n * formVM(): void {\r\n * // Form view model from entities\r\n * }\r\n * }\r\n * ```\r\n */\r\nexport abstract class AppObjectSingletonPM<T> extends AppObjectPM<T> {\r\n /**\r\n * Creates a new singleton presentation manager component and attaches it to the specified AppObject\r\n * Automatically registers itself as a singleton in the AppObjectRepo\r\n *\r\n * @param appObject The parent AppObject this component will be attached to\r\n * @param type The unique type identifier for this component\r\n */\r\n constructor(appObject: AppObject, type: string) {\r\n super(appObject, type);\r\n\r\n this.appObjects.registerSingleton(this);\r\n }\r\n\r\n /**\r\n * Cleans up resources and unregisters the singleton\r\n *\r\n * This method:\r\n * 1. Unregisters itself from the singleton registry\r\n * 2. Calls the parent class dispose method (which handles entity observers and views)\r\n */\r\n dispose() {\r\n this.appObjects.unregisterSingleton(this.type);\r\n super.dispose();\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { AppObjectUC } from "./AppObjectUC";
|
|
2
|
+
/**
|
|
3
|
+
* AppObjectSingletonUC (Use Case) serves as a singleton use case class within the application framework.
|
|
4
|
+
*
|
|
5
|
+
* This class extends AppObjectUC and automatically registers itself as a singleton in the
|
|
6
|
+
* AppObjectRepo upon construction. This ensures only one instance of this use case type exists
|
|
7
|
+
* across the entire application.
|
|
8
|
+
*
|
|
9
|
+
* Use Cases are components that represent specific application operations or workflows.
|
|
10
|
+
* They encapsulate business rules and coordinate interactions between different parts
|
|
11
|
+
* of the application. Use this singleton version when the use case should exist as a
|
|
12
|
+
* single instance globally, such as application-wide orchestration or workflow managers.
|
|
13
|
+
*
|
|
14
|
+
* @extends AppObjectUC
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* class GlobalPurchaseManagerUC extends AppObjectSingletonUC {
|
|
19
|
+
* static type = "globalPurchaseManagerUC";
|
|
20
|
+
*
|
|
21
|
+
* constructor(appObject: AppObject) {
|
|
22
|
+
* super(appObject, GlobalPurchaseManagerUC.type);
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* execute(itemId: string, quantity: number): boolean {
|
|
26
|
+
* // Implement the purchase item use case
|
|
27
|
+
* return true; // if successful
|
|
28
|
+
* }
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export class AppObjectSingletonUC extends AppObjectUC {
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new singleton use case component and attaches it to the specified AppObject
|
|
35
|
+
* Automatically registers itself as a singleton in the AppObjectRepo
|
|
36
|
+
*
|
|
37
|
+
* @param appObject The parent AppObject this component will be attached to
|
|
38
|
+
* @param type The unique type identifier for this component
|
|
39
|
+
*/
|
|
40
|
+
constructor(appObject, type) {
|
|
41
|
+
super(appObject, type);
|
|
42
|
+
this.appObjects.registerSingleton(this);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Cleans up resources and unregisters the singleton
|
|
46
|
+
*
|
|
47
|
+
* This method:
|
|
48
|
+
* 1. Unregisters itself from the singleton registry
|
|
49
|
+
* 2. Calls the parent class dispose method
|
|
50
|
+
*/
|
|
51
|
+
dispose() {
|
|
52
|
+
this.appObjects.unregisterSingleton(this.type);
|
|
53
|
+
super.dispose();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=AppObjectSingletonUC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AppObjectSingletonUC.js","sourceRoot":"","sources":["../../../src/AppObject/AppObjectSingletonUC.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,OAAO,oBAAqB,SAAQ,WAAW;IACnD;;;;;;OAMG;IACH,YAAY,SAAoB,EAAE,IAAY;QAC5C,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAEvB,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;;OAMG;IACH,OAAO;QACL,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/C,KAAK,CAAC,OAAO,EAAE,CAAC;IAClB,CAAC;CACF","sourcesContent":["import { AppObject } from \"./AppObject\";\r\nimport { AppObjectUC } from \"./AppObjectUC\";\r\n\r\n/**\r\n * AppObjectSingletonUC (Use Case) serves as a singleton use case class within the application framework.\r\n *\r\n * This class extends AppObjectUC and automatically registers itself as a singleton in the\r\n * AppObjectRepo upon construction. This ensures only one instance of this use case type exists\r\n * across the entire application.\r\n *\r\n * Use Cases are components that represent specific application operations or workflows.\r\n * They encapsulate business rules and coordinate interactions between different parts\r\n * of the application. Use this singleton version when the use case should exist as a\r\n * single instance globally, such as application-wide orchestration or workflow managers.\r\n *\r\n * @extends AppObjectUC\r\n *\r\n * @example\r\n * ```typescript\r\n * class GlobalPurchaseManagerUC extends AppObjectSingletonUC {\r\n * static type = \"globalPurchaseManagerUC\";\r\n *\r\n * constructor(appObject: AppObject) {\r\n * super(appObject, GlobalPurchaseManagerUC.type);\r\n * }\r\n *\r\n * execute(itemId: string, quantity: number): boolean {\r\n * // Implement the purchase item use case\r\n * return true; // if successful\r\n * }\r\n * }\r\n * ```\r\n */\r\nexport class AppObjectSingletonUC extends AppObjectUC {\r\n /**\r\n * Creates a new singleton use case component and attaches it to the specified AppObject\r\n * Automatically registers itself as a singleton in the AppObjectRepo\r\n *\r\n * @param appObject The parent AppObject this component will be attached to\r\n * @param type The unique type identifier for this component\r\n */\r\n constructor(appObject: AppObject, type: string) {\r\n super(appObject, type);\r\n\r\n this.appObjects.registerSingleton(this);\r\n }\r\n\r\n /**\r\n * Cleans up resources and unregisters the singleton\r\n *\r\n * This method:\r\n * 1. Unregisters itself from the singleton registry\r\n * 2. Calls the parent class dispose method\r\n */\r\n dispose() {\r\n this.appObjects.unregisterSingleton(this.type);\r\n super.dispose();\r\n }\r\n}\r\n"]}
|
|
@@ -6,6 +6,10 @@ export * from "./AppObjectRepo";
|
|
|
6
6
|
export * from "./AppObjectUC";
|
|
7
7
|
export * from "./AppObjectController";
|
|
8
8
|
export * from "./AppObjectView";
|
|
9
|
+
export * from "./AppObjectSingletonEntity";
|
|
10
|
+
export * from "./AppObjectSingletonEntityRepo";
|
|
11
|
+
export * from "./AppObjectSingletonPM";
|
|
12
|
+
export * from "./AppObjectSingletonUC";
|
|
9
13
|
export * from "./getSingletonComponent";
|
|
10
14
|
export * from "./printAppObjectDetails";
|
|
11
15
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/AppObject/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/AppObject/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC","sourcesContent":["export * from \"./AppObject\";\r\nexport * from \"./AppObjectEntity\";\r\nexport * from \"./AppObjectEntityRepo\";\r\nexport * from \"./AppObjectPM\";\r\nexport * from \"./AppObjectRepo\";\r\nexport * from \"./AppObjectUC\";\r\nexport * from \"./AppObjectController\";\r\nexport * from \"./AppObjectView\";\r\nexport * from \"./AppObjectSingletonEntity\";\r\nexport * from \"./AppObjectSingletonEntityRepo\";\r\nexport * from \"./AppObjectSingletonPM\";\r\nexport * from \"./AppObjectSingletonUC\";\r\nexport * from \"./getSingletonComponent\";\r\nexport * from \"./printAppObjectDetails\";\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObserverList.js","sourceRoot":"","sources":["../../../src/Entities/ObserverList.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,OAAO,YAAY;IAAzB;QACU,cAAS,GAAyB,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"ObserverList.js","sourceRoot":"","sources":["../../../src/Entities/ObserverList.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,OAAO,YAAY;IAAzB;QACU,cAAS,GAAyB,EAAE,CAAC;QAS7C;;;WAGG;QACI,WAAM,GAAG,CAAC,GAAM,EAAE,EAAE;YACzB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;gBAC7B,GAAG,CAAC,GAAG,CAAC,CAAC;YACX,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;QAEF;;;WAGG;QACI,QAAG,GAAG,CAAC,GAAqB,EAAE,EAAE;YACrC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC3B,CAAC,CAAC;QAEF;;;WAGG;QACI,WAAM,GAAG,CAAC,GAAqB,EAAE,EAAE;YACxC,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YAC1C,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;gBACf,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YAClC,CAAC;QACH,CAAC,CAAC;QAEF;;WAEG;QACI,UAAK,GAAG,GAAG,EAAE;YAClB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QACtB,CAAC,CAAC;IACJ,CAAC;IA1CC;;OAEG;IACH,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;IAC/B,CAAC;CAqCF","sourcesContent":["/**\r\n * A generic implementation of the Observer pattern.\r\n * Maintains a list of observer functions that can be notified with a message.\r\n *\r\n * @typeParam T - The type of message that will be passed to observers\r\n */\r\nexport class ObserverList<T> {\r\n private observers: ((msg: T) => void)[] = [];\r\n\r\n /**\r\n * Gets the number of observers in the list\r\n */\r\n public get length(): number {\r\n return this.observers.length;\r\n }\r\n\r\n /**\r\n * Notifies all observers by calling them with the provided message\r\n * @param msg - The message to send to all observers\r\n */\r\n public notify = (msg: T) => {\r\n this.observers.forEach((obs) => {\r\n obs(msg);\r\n });\r\n };\r\n\r\n /**\r\n * Adds a new observer function to the list\r\n * @param obs - The observer function to add\r\n */\r\n public add = (obs: (msg: T) => void) => {\r\n this.observers.push(obs);\r\n };\r\n\r\n /**\r\n * Removes an observer from the list\r\n * @param obs - The observer function to remove\r\n */\r\n public remove = (obs: (msg: T) => void) => {\r\n const index = this.observers.indexOf(obs);\r\n if (index >= 0) {\r\n this.observers.splice(index, 1);\r\n }\r\n };\r\n\r\n /**\r\n * Removes all observers from the list\r\n */\r\n public clear = () => {\r\n this.observers = [];\r\n };\r\n}\r\n"]}
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
* 4. Delete entities through the repository when they're no longer needed
|
|
18
18
|
*/
|
|
19
19
|
import { AppObjectEntityRepo } from "../../AppObject";
|
|
20
|
-
import { generateUniqueID } from "../../Utilities/generateUniqueID";
|
|
21
20
|
import { makeExampleEntity } from "./ExampleEntity";
|
|
22
21
|
/**
|
|
23
22
|
* ExampleRepo manages a collection of ExampleEntity instances.
|
|
@@ -71,38 +70,27 @@ export function makeExampleRepo(appObject) {
|
|
|
71
70
|
* This private class handles the actual implementation details
|
|
72
71
|
*/
|
|
73
72
|
class ExampleRepoImp extends ExampleRepo {
|
|
73
|
+
/**
|
|
74
|
+
* Factory implementation for creating ExampleEntity instances
|
|
75
|
+
* @param appObject The AppObject for the entity
|
|
76
|
+
* @returns A newly created ExampleEntity
|
|
77
|
+
*/
|
|
78
|
+
entityFactory(appObject) {
|
|
79
|
+
return makeExampleEntity(appObject);
|
|
80
|
+
}
|
|
74
81
|
/**
|
|
75
82
|
* Deletes an ExampleEntity from the repository by its AppObject ID
|
|
76
83
|
* @param id The ID of the entity's AppObject
|
|
77
84
|
*/
|
|
78
85
|
deleteExampleEntity(id) {
|
|
79
|
-
const entity = this.
|
|
86
|
+
const entity = this.getById(id);
|
|
80
87
|
if (!entity)
|
|
81
88
|
return;
|
|
82
89
|
entity.appObject.dispose();
|
|
83
|
-
this.
|
|
90
|
+
this.removeById(id);
|
|
84
91
|
}
|
|
85
92
|
constructor(appObject) {
|
|
86
93
|
super(appObject, ExampleRepo.type);
|
|
87
|
-
/**
|
|
88
|
-
* Creates a new ExampleEntity and adds it to the repository
|
|
89
|
-
* @param id Optional ID for the entity's AppObject (generates one if not provided)
|
|
90
|
-
* @returns The newly created ExampleEntity
|
|
91
|
-
*/
|
|
92
|
-
this.createExampleEntity = (id) => {
|
|
93
|
-
const idToUse = id ?? generateUniqueID();
|
|
94
|
-
const entity = this.exampleEntityFactory(idToUse);
|
|
95
|
-
this.add(entity);
|
|
96
|
-
return entity;
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
* Default factory implementation for creating ExampleEntity instances
|
|
100
|
-
* Can be overridden to create specialized entities
|
|
101
|
-
*/
|
|
102
|
-
this.exampleEntityFactory = (id) => {
|
|
103
|
-
const ao = this.appObjects.getOrCreate(id);
|
|
104
|
-
return makeExampleEntity(ao);
|
|
105
|
-
};
|
|
106
94
|
}
|
|
107
95
|
}
|
|
108
96
|
//# sourceMappingURL=ExampleRepo.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExampleRepo.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Entities/ExampleRepo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"ExampleRepo.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Entities/ExampleRepo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAa,mBAAmB,EAAiB,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAiB,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAKnE;;;GAGG;AACH,MAAM,OAAgB,WAAY,SAAQ,mBAAkC;IAO1E;;;;OAIG;IACH,MAAM,CAAC,GAAG,CAAC,MAAiB;QAC1B,OAAO,MAAM,CAAC,YAAY,CAAc,IAAI,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CACZ,EAAU,EACV,UAAyB;QAEzB,OAAO,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,YAAY,CAAc,IAAI,CAAC,IAAI,CAAC,CAAC;IAClE,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,YAAY,CAAC,SAAoB;QACtC,MAAM,QAAQ,GAAG,SAAS,CAAC,YAAY,CAAc,WAAW,CAAC,IAAI,CAAC,CAAC;QACvE,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC;QAClB,CAAC;aAAM,CAAC;YACN,OAAO,eAAe,CAAC,SAAS,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;;AAxCD,gDAAgD;AAChC,gBAAI,GAAG,iBAAiB,CAAC;AA0C3C;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,SAAoB;IAClD,OAAO,IAAI,cAAc,CAAC,SAAS,CAAC,CAAC;AACvC,CAAC;AAED;;;GAGG;AACH,MAAM,cAAe,SAAQ,WAAW;IACtC;;;;OAIG;IACH,aAAa,CAAC,SAAoB;QAChC,OAAO,iBAAiB,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;IAED;;;OAGG;IACH,mBAAmB,CAAC,EAAU;QAC5B,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAChC,IAAI,CAAC,MAAM;YAAE,OAAO;QAEpB,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QAC3B,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IACtB,CAAC;IAED,YAAY,SAAoB;QAC9B,KAAK,CAAC,SAAS,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;CACF","sourcesContent":["/**\r\n * ExampleRepo.ts\r\n *\r\n * This file demonstrates how to implement a repository to manage collections of entities.\r\n * Repositories are responsible for creating, retrieving, and deleting entities.\r\n *\r\n * Key concepts:\r\n * - Repositories extend AppObjectEntityRepo<T> where T is the entity type\r\n * - They provide methods to create and delete entities\r\n * - They manage collections of entities and provide access to them\r\n * - They can use custom entity factories to create specialized entities\r\n *\r\n * Usage pattern:\r\n * 1. Get or create a repository using getById, get, or addIfMissing\r\n * 2. Use the repository to create new entities\r\n * 3. Access entities through the repository's getters\r\n * 4. Delete entities through the repository when they're no longer needed\r\n */\r\n\r\nimport { AppObject, AppObjectEntityRepo, AppObjectRepo } from \"../../AppObject\";\r\nimport { ExampleEntity, makeExampleEntity } from \"./ExampleEntity\";\r\n\r\n/** Type definition for a factory function that creates ExampleEntity instances */\r\nexport type ExampleEntityFactory = (appObject: AppObject) => ExampleEntity;\r\n\r\n/**\r\n * ExampleRepo manages a collection of ExampleEntity instances.\r\n * Abstract class provides the interface and static helper methods.\r\n */\r\nexport abstract class ExampleRepo extends AppObjectEntityRepo<ExampleEntity> {\r\n /** Unique type identifier for this component */\r\n static readonly type = \"ExampleRepoType\";\r\n\r\n /** Deletes an entity by its AppObject ID */\r\n abstract deleteExampleEntity(id: string): void;\r\n\r\n /**\r\n * Retrieves an ExampleRepo component from an AppObject\r\n * @param appObj The AppObject to get the component from\r\n * @returns The ExampleRepo component or undefined if not found\r\n */\r\n static get(appObj: AppObject): ExampleRepo | undefined {\r\n return appObj.getComponent<ExampleRepo>(this.type);\r\n }\r\n\r\n /**\r\n * Retrieves an ExampleRepo by its parent AppObject's ID\r\n * @param id The ID of the parent AppObject\r\n * @param appObjects The AppObjectRepo to search in\r\n * @returns The ExampleRepo component or undefined if not found\r\n */\r\n static getById(\r\n id: string,\r\n appObjects: AppObjectRepo\r\n ): ExampleRepo | undefined {\r\n return appObjects.get(id)?.getComponent<ExampleRepo>(this.type);\r\n }\r\n\r\n /**\r\n * Ensures an ExampleRepo exists on the AppObject, creating one if needed\r\n * @param appObject The AppObject to check/add the component to\r\n * @returns The existing or newly created ExampleRepo\r\n */\r\n static addIfMissing(appObject: AppObject): ExampleRepo {\r\n const existing = appObject.getComponent<ExampleRepo>(ExampleRepo.type);\r\n if (existing) {\r\n return existing;\r\n } else {\r\n return makeExampleRepo(appObject);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Factory function to create a new ExampleRepo\r\n * @param appObject The AppObject to attach the repo to\r\n * @returns A new ExampleRepo instance\r\n */\r\nexport function makeExampleRepo(appObject: AppObject): ExampleRepo {\r\n return new ExampleRepoImp(appObject);\r\n}\r\n\r\n/**\r\n * Concrete implementation of ExampleRepo\r\n * This private class handles the actual implementation details\r\n */\r\nclass ExampleRepoImp extends ExampleRepo {\r\n /**\r\n * Factory implementation for creating ExampleEntity instances\r\n * @param appObject The AppObject for the entity\r\n * @returns A newly created ExampleEntity\r\n */\r\n entityFactory(appObject: AppObject): ExampleEntity {\r\n return makeExampleEntity(appObject);\r\n }\r\n\r\n /**\r\n * Deletes an ExampleEntity from the repository by its AppObject ID\r\n * @param id The ID of the entity's AppObject\r\n */\r\n deleteExampleEntity(id: string): void {\r\n const entity = this.getById(id);\r\n if (!entity) return;\r\n\r\n entity.appObject.dispose();\r\n this.removeById(id);\r\n }\r\n\r\n constructor(appObject: AppObject) {\r\n super(appObject, ExampleRepo.type);\r\n }\r\n}\r\n"]}
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
* 2. Access or modify properties via getters/setters
|
|
17
17
|
* 3. Register change observers to react to property updates
|
|
18
18
|
*/
|
|
19
|
-
import {
|
|
19
|
+
import { AppObjectSingletonEntity, } from "../../AppObject";
|
|
20
20
|
import { getSingletonComponent } from "../../AppObject/getSingletonComponent";
|
|
21
21
|
import { MemoizedBoolean } from "../../Entities/MemoizedBoolean";
|
|
22
22
|
/**
|
|
23
23
|
* SingletonEntityExample represents a global entity with a boolean property.
|
|
24
24
|
* As a singleton, only one instance exists in the application.
|
|
25
25
|
*/
|
|
26
|
-
export class SingletonEntityExample extends
|
|
26
|
+
export class SingletonEntityExample extends AppObjectSingletonEntity {
|
|
27
27
|
}
|
|
28
28
|
/** Unique type identifier for this component */
|
|
29
29
|
SingletonEntityExample.type = "SingletonEntityExampleType";
|
|
@@ -57,8 +57,6 @@ class SingletonEntityExampleImp extends SingletonEntityExample {
|
|
|
57
57
|
super(appObject, SingletonEntityExample.type);
|
|
58
58
|
// MemoizedBoolean tracks changes to the boolean value and calls notifyOnChange when updated
|
|
59
59
|
this.memoizedIsAuthoring = new MemoizedBoolean(false, this.notifyOnChange);
|
|
60
|
-
// Register this entity as a singleton so it can be accessed globally
|
|
61
|
-
this.appObjects.registerSingleton(this);
|
|
62
60
|
}
|
|
63
61
|
}
|
|
64
62
|
//# sourceMappingURL=ExampleSingletonEntity.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExampleSingletonEntity.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Entities/ExampleSingletonEntity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"ExampleSingletonEntity.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Entities/ExampleSingletonEntity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAGL,wBAAwB,GACzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEjE;;;GAGG;AACH,MAAM,OAAgB,sBAAuB,SAAQ,wBAAwB;;AAC3E,gDAAgD;AAChC,2BAAI,GAAG,4BAA4B,CAAC;AAMpD;;;;GAIG;AACI,0BAAG,GAAG,CACX,UAAyB,EACW,EAAE,CACtC,qBAAqB,CAAC,sBAAsB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AAGnE;;;;GAIG;AACH,MAAM,UAAU,0BAA0B,CACxC,SAAoB;IAEpB,OAAO,IAAI,yBAAyB,CAAC,SAAS,CAAC,CAAC;AAClD,CAAC;AAED;;;GAGG;AACH,MAAM,yBAA0B,SAAQ,sBAAsB;IAI5D,iDAAiD;IACjD,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC;IACtC,CAAC;IAED,IAAI,aAAa,CAAC,GAAY;QAC5B,IAAI,CAAC,mBAAmB,CAAC,GAAG,GAAG,GAAG,CAAC;IACrC,CAAC;IAED,YAAY,SAAoB;QAC9B,KAAK,CAAC,SAAS,EAAE,sBAAsB,CAAC,IAAI,CAAC,CAAC;QAbhD,4FAA4F;QACpF,wBAAmB,GAAG,IAAI,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;IAa9E,CAAC;CACF","sourcesContent":["/**\r\n * ExampleSingletonEntity.ts\r\n *\r\n * This file demonstrates how to implement a singleton entity in the application.\r\n * Singleton entities are special entities that exist only once in the application\r\n * and can be accessed globally from anywhere.\r\n *\r\n * Key concepts:\r\n * - Singleton entities extend AppObjectEntity like regular entities\r\n * - They register themselves as singletons with appObjects.registerSingleton()\r\n * - They're accessed through a static get() method using getSingletonComponent()\r\n * - There's only one instance of a singleton entity in the entire application\r\n *\r\n * Usage pattern:\r\n * 1. Access the singleton entity using the static get() method\r\n * 2. Access or modify properties via getters/setters\r\n * 3. Register change observers to react to property updates\r\n */\r\n\r\nimport {\r\n AppObject,\r\n AppObjectRepo,\r\n AppObjectSingletonEntity,\r\n} from \"../../AppObject\";\r\nimport { getSingletonComponent } from \"../../AppObject/getSingletonComponent\";\r\nimport { MemoizedBoolean } from \"../../Entities/MemoizedBoolean\";\r\n\r\n/**\r\n * SingletonEntityExample represents a global entity with a boolean property.\r\n * As a singleton, only one instance exists in the application.\r\n */\r\nexport abstract class SingletonEntityExample extends AppObjectSingletonEntity {\r\n /** Unique type identifier for this component */\r\n static readonly type = \"SingletonEntityExampleType\";\r\n\r\n /** Boolean property accessor methods that must be implemented */\r\n abstract get aBoolProperty(): boolean;\r\n abstract set aBoolProperty(val: boolean);\r\n\r\n /**\r\n * Global accessor for the singleton entity\r\n * @param appObjects The AppObjectRepo to search in\r\n * @returns The singleton entity or undefined if not created yet\r\n */\r\n static get = (\r\n appObjects: AppObjectRepo\r\n ): SingletonEntityExample | undefined =>\r\n getSingletonComponent(SingletonEntityExample.type, appObjects);\r\n}\r\n\r\n/**\r\n * Factory function to create a new SingletonEntityExample\r\n * @param appObject The AppObject to attach the entity to\r\n * @returns A new SingletonEntityExample instance\r\n */\r\nexport function makeSingletonEntityExample(\r\n appObject: AppObject\r\n): SingletonEntityExample {\r\n return new SingletonEntityExampleImp(appObject);\r\n}\r\n\r\n/**\r\n * Concrete implementation of SingletonEntityExample\r\n * This private class handles the actual implementation details\r\n */\r\nclass SingletonEntityExampleImp extends SingletonEntityExample {\r\n // MemoizedBoolean tracks changes to the boolean value and calls notifyOnChange when updated\r\n private memoizedIsAuthoring = new MemoizedBoolean(false, this.notifyOnChange);\r\n\r\n // Property accessors that use the memoized value\r\n get aBoolProperty() {\r\n return this.memoizedIsAuthoring.val;\r\n }\r\n\r\n set aBoolProperty(val: boolean) {\r\n this.memoizedIsAuthoring.val = val;\r\n }\r\n\r\n constructor(appObject: AppObject) {\r\n super(appObject, SingletonEntityExample.type);\r\n }\r\n}\r\n"]}
|
|
@@ -54,7 +54,7 @@ export class ExampleFeatureFactory extends DomainFactory {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
export function makeExampleFeatureFactory(appObjects) {
|
|
57
|
-
const appObject = appObjects.getOrCreate("
|
|
57
|
+
const appObject = appObjects.getOrCreate("FeatureName");
|
|
58
58
|
return new ExampleFeatureFactory(appObject);
|
|
59
59
|
}
|
|
60
60
|
//# sourceMappingURL=ExampleFeatureFactory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExampleFeatureFactory.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Factory/ExampleFeatureFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAE3E;;;;;;;;GAQG;AACH,MAAM,OAAO,qBAAsB,SAAQ,aAAa;IAAxD;;QAEC,gBAAW,GAAG,uBAAuB,CAAC;IA6CvC,CAAC;IA3CA;;;;;OAKG;IACH,aAAa;QAEZ,0BAA0B,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;OAKG;IACH,QAAQ;QAEP,0BAA0B,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;OAKG;IACH,QAAQ;QAEP,sBAAsB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;IAED;;;;;OAKG;IACH,UAAU;QAET,gDAAgD;IACjD,CAAC;CACD;AAED,MAAM,UAAU,yBAAyB,CAAC,UAAyB;IAClE,MAAM,SAAS,GAAG,UAAU,CAAC,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"ExampleFeatureFactory.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Factory/ExampleFeatureFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAE3E;;;;;;;;GAQG;AACH,MAAM,OAAO,qBAAsB,SAAQ,aAAa;IAAxD;;QAEC,gBAAW,GAAG,uBAAuB,CAAC;IA6CvC,CAAC;IA3CA;;;;;OAKG;IACH,aAAa;QAEZ,0BAA0B,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;OAKG;IACH,QAAQ;QAEP,0BAA0B,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;OAKG;IACH,QAAQ;QAEP,sBAAsB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;IAED;;;;;OAKG;IACH,UAAU;QAET,gDAAgD;IACjD,CAAC;CACD;AAED,MAAM,UAAU,yBAAyB,CAAC,UAAyB;IAClE,MAAM,SAAS,GAAG,UAAU,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IACxD,OAAO,IAAI,qBAAqB,CAAC,SAAS,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["import { AppObjectRepo } from \"../../AppObject\";\r\nimport { DomainFactory } from \"../../DomainFactories\";\r\nimport { makeSingletonEntityExample } from \"../Entities/ExampleSingletonEntity\";\r\nimport { makeExampleSingletonPM } from \"../PMs/ExampleSingletonPM\";\r\nimport { makeToggleExampleBooleanUC } from \"../UCs/ToggleExampleBooleanUC\";\r\n\r\n/**\r\n * Factory responsible for setting up the Example Feature domain components.\r\n * \r\n * This factory initializes all entities, use cases, and presentation models\r\n * required for the Example Feature functionality. It follows the domain-driven\r\n * design pattern by organizing components into their respective layers.\r\n * \r\n * @extends DomainFactory\r\n */\r\nexport class ExampleFeatureFactory extends DomainFactory\r\n{\r\n\tfactoryName = \"ExampleFeatureFactory\";\r\n\r\n\t/**\r\n\t * Sets up all entities required for the Example Feature.\r\n\t * \r\n\t * Initializes singleton entities that maintain the state and business\r\n\t * logic for the example feature functionality.\r\n\t */\r\n\tsetupEntities(): void\r\n\t{\r\n\t\tmakeSingletonEntityExample(this.appObject);\r\n\t}\r\n\r\n\t/**\r\n\t * Sets up all use cases for the Example Feature.\r\n\t * \r\n\t * Initializes use cases that define the business operations and\r\n\t * workflows available in the example feature.\r\n\t */\r\n\tsetupUCs(): void\r\n\t{\r\n\t\tmakeToggleExampleBooleanUC(this.appObject);\r\n\t}\r\n\r\n\t/**\r\n\t * Sets up all presentation models for the Example Feature.\r\n\t * \r\n\t * Initializes presentation models that handle the view logic and\r\n\t * state management for UI components related to the example feature.\r\n\t */\r\n\tsetupPMs(): void\r\n\t{\r\n\t\tmakeExampleSingletonPM(this.appObject);\r\n\t}\r\n\r\n\t/**\r\n\t * Performs any final setup operations after all components are initialized.\r\n\t * \r\n\t * This method is called after entities, use cases, and presentation models\r\n\t * have been set up. Currently no additional setup is required for this feature.\r\n\t */\r\n\tfinalSetup(): void\r\n\t{\r\n\t\t// No additional setup required for this feature\r\n\t}\r\n}\r\n\r\nexport function makeExampleFeatureFactory(appObjects: AppObjectRepo):ExampleFeatureFactory {\r\n\tconst appObject = appObjects.getOrCreate(\"FeatureName\");\r\n\treturn new ExampleFeatureFactory(appObject);\r\n}"]}
|
|
@@ -65,28 +65,20 @@ class ExamplePMImp extends ExamplePM {
|
|
|
65
65
|
}
|
|
66
66
|
constructor(appObject) {
|
|
67
67
|
super(appObject, ExamplePM.type);
|
|
68
|
+
/** Default view model before any entity data is available */
|
|
69
|
+
this.defaultVM = "";
|
|
68
70
|
/**
|
|
69
71
|
* Handler for entity change events
|
|
70
72
|
* Transforms entity data into a view model and updates views
|
|
71
73
|
*/
|
|
72
|
-
this.
|
|
73
|
-
if (!this.exampleEntity)
|
|
74
|
-
return;
|
|
74
|
+
this.formVM = () => {
|
|
75
75
|
// In this simple case, our view model is just the string property value
|
|
76
76
|
this.doUpdateView(this.exampleEntity.aStringProperty);
|
|
77
77
|
};
|
|
78
|
-
/**
|
|
79
|
-
* Cleanup method called when the PM is being disposed
|
|
80
|
-
* Removes any observers to prevent memory leaks
|
|
81
|
-
*/
|
|
82
|
-
this.dispose = () => {
|
|
83
|
-
super.dispose();
|
|
84
|
-
this.exampleEntity?.removeChangeObserver(this.onEntityChange);
|
|
85
|
-
};
|
|
86
78
|
// Register as an observer of the entity to receive change notifications
|
|
87
|
-
this.
|
|
79
|
+
this.observeEntity(this.exampleEntity);
|
|
88
80
|
// Call the change handler initially to set up the initial view model
|
|
89
|
-
this.
|
|
81
|
+
this.formVM();
|
|
90
82
|
}
|
|
91
83
|
}
|
|
92
84
|
//# sourceMappingURL=ExamplePM.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExamplePM.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/PMs/ExamplePM.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GA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a;QACvB,OAAO,IAAI,CAAC,uBAAuB,CAAgB,aAAa,CAAC,IAAI,CAAC,CAAC;IACzE,CAAC;IAED;;;OAGG;IACH,WAAW,CAAC,CAAS,EAAE,CAAS;QAC9B,OAAO,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC;IAYD,YAAY,SAAoB;QAC9B,KAAK,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;QA9BnC,6DAA6D;QACpD,cAAS,GAAG,EAAE,CAAC;QAkBxB;;;WAGG;QACH,WAAM,GAAG,GAAG,EAAE;YACZ,wEAAwE;YACxE,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;QACxD,CAAC,CAAC;QAMA,wEAAwE;QACxE,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAEvC,qEAAqE;QACrE,IAAI,CAAC,MAAM,EAAE,CAAC;IAChB,CAAC;CACF","sourcesContent":["/**\r\n * ExamplePM.ts\r\n *\r\n * This file demonstrates how to implement a Presentation Manager (PM) component.\r\n * PMs are responsible for transforming entity data into view models (VMs) for the UI.\r\n * They observe entities for changes and update their views when data changes.\r\n *\r\n * Key concepts:\r\n * - PMs extend AppObjectPM<VM> where VM is the view model type\r\n * - They observe entities and transform entity data into view models\r\n * - They notify UI components (views) when view models change\r\n * - Each PM instance is associated with a specific AppObject\r\n *\r\n * Usage pattern:\r\n * 1. Get a PM instance using getById\r\n * 2. Register UI components as views using addView(callback)\r\n * 3. PM will call the view callbacks with updated view models when entities change\r\n * 4. Remove UI components with removeView(callback) when they're unmounted\r\n */\r\n\r\nimport { AppObject, AppObjectPM, AppObjectRepo } from \"../../AppObject\";\r\nimport { ExampleEntity } from \"../Entities/ExampleEntity\";\r\n\r\n/**\r\n * ExamplePM transforms ExampleEntity data into a simple string view model.\r\n * Abstract class provides the interface and static helper methods.\r\n */\r\nexport abstract class ExamplePM extends AppObjectPM<string> {\r\n /** Unique type identifier for this component */\r\n static readonly type = \"ExamplePMType\";\r\n\r\n /**\r\n * Retrieves an ExamplePM by its parent AppObject's ID\r\n * @param id The ID of the parent AppObject\r\n * @param appObjects The AppObjectRepo to search in\r\n * @returns The ExamplePM component or undefined if not found\r\n */\r\n static getById(id: string, appObjects: AppObjectRepo) {\r\n return appObjects.get(id)?.getComponent<ExamplePM>(ExamplePM.type);\r\n }\r\n}\r\n\r\n/**\r\n * Factory function to create a new ExamplePM\r\n * @param appObject The AppObject to attach the PM to\r\n * @returns A new ExamplePM instance\r\n */\r\nexport function makeExamplePM(appObject: AppObject): ExamplePM {\r\n return new ExamplePMImp(appObject);\r\n}\r\n\r\n/**\r\n * Concrete implementation of ExamplePM\r\n * This private class handles the actual implementation details\r\n */\r\nclass ExamplePMImp extends ExamplePM {\r\n /** Default view model before any entity data is available */\r\n readonly defaultVM = \"\";\r\n\r\n /**\r\n * Gets the ExampleEntity from the same AppObject\r\n * Uses getCachedLocalComponent for efficient repeated access\r\n */\r\n private get exampleEntity() {\r\n return this.getCachedLocalComponent<ExampleEntity>(ExampleEntity.type);\r\n }\r\n\r\n /**\r\n * Compares two view models to determine if they're equal\r\n * Used to avoid unnecessary view updates when values haven't changed\r\n */\r\n vmsAreEqual(a: string, b: string): boolean {\r\n return a === b;\r\n }\r\n\r\n /**\r\n * Handler for entity change events\r\n * Transforms entity data into a view model and updates views\r\n */\r\n formVM = () => {\r\n // In this simple case, our view model is just the string property value\r\n this.doUpdateView(this.exampleEntity.aStringProperty);\r\n };\r\n\r\n\r\n constructor(appObject: AppObject) {\r\n super(appObject, ExamplePM.type);\r\n\r\n // Register as an observer of the entity to receive change notifications\r\n this.observeEntity(this.exampleEntity);\r\n\r\n // Call the change handler initially to set up the initial view model\r\n this.formVM();\r\n }\r\n}\r\n"]}
|