@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.
Files changed (97) hide show
  1. package/dist/cjs/AppObject/AppObjectComponent.js +8 -10
  2. package/dist/cjs/AppObject/AppObjectComponent.js.map +1 -1
  3. package/dist/cjs/AppObject/AppObjectEntityRepo.js +113 -11
  4. package/dist/cjs/AppObject/AppObjectEntityRepo.js.map +1 -1
  5. package/dist/cjs/AppObject/AppObjectPM.js +106 -6
  6. package/dist/cjs/AppObject/AppObjectPM.js.map +1 -1
  7. package/dist/cjs/AppObject/AppObjectRepo.js +4 -1
  8. package/dist/cjs/AppObject/AppObjectRepo.js.map +1 -1
  9. package/dist/cjs/AppObject/AppObjectSingletonEntity.js +40 -0
  10. package/dist/cjs/AppObject/AppObjectSingletonEntity.js.map +1 -0
  11. package/dist/cjs/AppObject/AppObjectSingletonEntityRepo.js +54 -0
  12. package/dist/cjs/AppObject/AppObjectSingletonEntityRepo.js.map +1 -0
  13. package/dist/cjs/AppObject/AppObjectSingletonPM.js +69 -0
  14. package/dist/cjs/AppObject/AppObjectSingletonPM.js.map +1 -0
  15. package/dist/cjs/AppObject/AppObjectSingletonUC.js +60 -0
  16. package/dist/cjs/AppObject/AppObjectSingletonUC.js.map +1 -0
  17. package/dist/cjs/AppObject/index.js +4 -0
  18. package/dist/cjs/AppObject/index.js.map +1 -1
  19. package/dist/cjs/Entities/ObserverList.js +6 -0
  20. package/dist/cjs/Entities/ObserverList.js.map +1 -1
  21. package/dist/cjs/ExampleFeature/Entities/ExampleRepo.js +10 -22
  22. package/dist/cjs/ExampleFeature/Entities/ExampleRepo.js.map +1 -1
  23. package/dist/cjs/ExampleFeature/Entities/ExampleSingletonEntity.js +1 -3
  24. package/dist/cjs/ExampleFeature/Entities/ExampleSingletonEntity.js.map +1 -1
  25. package/dist/cjs/ExampleFeature/Factory/ExampleFeatureFactory.js +1 -1
  26. package/dist/cjs/ExampleFeature/Factory/ExampleFeatureFactory.js.map +1 -1
  27. package/dist/cjs/ExampleFeature/PMs/ExamplePM.js +5 -13
  28. package/dist/cjs/ExampleFeature/PMs/ExamplePM.js.map +1 -1
  29. package/dist/cjs/ExampleFeature/PMs/ExampleSingletonPM.js +8 -12
  30. package/dist/cjs/ExampleFeature/PMs/ExampleSingletonPM.js.map +1 -1
  31. package/dist/cjs/ExampleFeature/UCs/EditExampleStringUC.js +0 -4
  32. package/dist/cjs/ExampleFeature/UCs/EditExampleStringUC.js.map +1 -1
  33. package/dist/cjs/ExampleFeature/UCs/ToggleExampleBooleanUC.js +2 -8
  34. package/dist/cjs/ExampleFeature/UCs/ToggleExampleBooleanUC.js.map +1 -1
  35. package/dist/esm/AppObject/AppObjectComponent.js +8 -10
  36. package/dist/esm/AppObject/AppObjectComponent.js.map +1 -1
  37. package/dist/esm/AppObject/AppObjectEntityRepo.js +113 -11
  38. package/dist/esm/AppObject/AppObjectEntityRepo.js.map +1 -1
  39. package/dist/esm/AppObject/AppObjectPM.js +107 -7
  40. package/dist/esm/AppObject/AppObjectPM.js.map +1 -1
  41. package/dist/esm/AppObject/AppObjectRepo.js +4 -1
  42. package/dist/esm/AppObject/AppObjectRepo.js.map +1 -1
  43. package/dist/esm/AppObject/AppObjectSingletonEntity.js +36 -0
  44. package/dist/esm/AppObject/AppObjectSingletonEntity.js.map +1 -0
  45. package/dist/esm/AppObject/AppObjectSingletonEntityRepo.js +50 -0
  46. package/dist/esm/AppObject/AppObjectSingletonEntityRepo.js.map +1 -0
  47. package/dist/esm/AppObject/AppObjectSingletonPM.js +65 -0
  48. package/dist/esm/AppObject/AppObjectSingletonPM.js.map +1 -0
  49. package/dist/esm/AppObject/AppObjectSingletonUC.js +56 -0
  50. package/dist/esm/AppObject/AppObjectSingletonUC.js.map +1 -0
  51. package/dist/esm/AppObject/index.js +4 -0
  52. package/dist/esm/AppObject/index.js.map +1 -1
  53. package/dist/esm/Entities/ObserverList.js +6 -0
  54. package/dist/esm/Entities/ObserverList.js.map +1 -1
  55. package/dist/esm/ExampleFeature/Entities/ExampleRepo.js +10 -22
  56. package/dist/esm/ExampleFeature/Entities/ExampleRepo.js.map +1 -1
  57. package/dist/esm/ExampleFeature/Entities/ExampleSingletonEntity.js +2 -4
  58. package/dist/esm/ExampleFeature/Entities/ExampleSingletonEntity.js.map +1 -1
  59. package/dist/esm/ExampleFeature/Factory/ExampleFeatureFactory.js +1 -1
  60. package/dist/esm/ExampleFeature/Factory/ExampleFeatureFactory.js.map +1 -1
  61. package/dist/esm/ExampleFeature/PMs/ExamplePM.js +5 -13
  62. package/dist/esm/ExampleFeature/PMs/ExamplePM.js.map +1 -1
  63. package/dist/esm/ExampleFeature/PMs/ExampleSingletonPM.js +9 -13
  64. package/dist/esm/ExampleFeature/PMs/ExampleSingletonPM.js.map +1 -1
  65. package/dist/esm/ExampleFeature/UCs/EditExampleStringUC.js +0 -4
  66. package/dist/esm/ExampleFeature/UCs/EditExampleStringUC.js.map +1 -1
  67. package/dist/esm/ExampleFeature/UCs/ToggleExampleBooleanUC.js +3 -9
  68. package/dist/esm/ExampleFeature/UCs/ToggleExampleBooleanUC.js.map +1 -1
  69. package/dist/types/AppObject/AppObjectComponent.d.ts +6 -4
  70. package/dist/types/AppObject/AppObjectComponent.d.ts.map +1 -1
  71. package/dist/types/AppObject/AppObjectEntityRepo.d.ts +80 -7
  72. package/dist/types/AppObject/AppObjectEntityRepo.d.ts.map +1 -1
  73. package/dist/types/AppObject/AppObjectPM.d.ts +82 -2
  74. package/dist/types/AppObject/AppObjectPM.d.ts.map +1 -1
  75. package/dist/types/AppObject/AppObjectRepo.d.ts +6 -0
  76. package/dist/types/AppObject/AppObjectRepo.d.ts.map +1 -1
  77. package/dist/types/AppObject/AppObjectSingletonEntity.d.ts +31 -0
  78. package/dist/types/AppObject/AppObjectSingletonEntity.d.ts.map +1 -0
  79. package/dist/types/AppObject/AppObjectSingletonEntityRepo.d.ts +46 -0
  80. package/dist/types/AppObject/AppObjectSingletonEntityRepo.d.ts.map +1 -0
  81. package/dist/types/AppObject/AppObjectSingletonPM.d.ts +60 -0
  82. package/dist/types/AppObject/AppObjectSingletonPM.d.ts.map +1 -0
  83. package/dist/types/AppObject/AppObjectSingletonUC.d.ts +51 -0
  84. package/dist/types/AppObject/AppObjectSingletonUC.d.ts.map +1 -0
  85. package/dist/types/AppObject/index.d.ts +4 -0
  86. package/dist/types/AppObject/index.d.ts.map +1 -1
  87. package/dist/types/Entities/ObserverList.d.ts +4 -0
  88. package/dist/types/Entities/ObserverList.d.ts.map +1 -1
  89. package/dist/types/ExampleFeature/Entities/ExampleRepo.d.ts +1 -5
  90. package/dist/types/ExampleFeature/Entities/ExampleRepo.d.ts.map +1 -1
  91. package/dist/types/ExampleFeature/Entities/ExampleSingletonEntity.d.ts +2 -2
  92. package/dist/types/ExampleFeature/Entities/ExampleSingletonEntity.d.ts.map +1 -1
  93. package/dist/types/ExampleFeature/PMs/ExampleSingletonPM.d.ts +4 -4
  94. package/dist/types/ExampleFeature/PMs/ExampleSingletonPM.d.ts.map +1 -1
  95. package/dist/types/ExampleFeature/UCs/ToggleExampleBooleanUC.d.ts +2 -2
  96. package/dist/types/ExampleFeature/UCs/ToggleExampleBooleanUC.d.ts.map +1 -1
  97. package/package.json +2 -2
@@ -6,10 +6,10 @@
6
6
  * accessed globally. They transform data from singleton entities into view models.
7
7
  *
8
8
  * Key concepts:
9
- * - Singleton PMs extend AppObjectPM<VM> like regular PMs
10
- * - They register themselves as singletons with appObjects.registerSingleton()
9
+ * - Singleton PMs extend AppObjectSingletonPM<VM> which handles singleton registration automatically
11
10
  * - They're accessed through a static get() method using getSingletonComponent()
12
11
  * - They typically observe singleton entities and provide data to multiple UI components
12
+ * - They use formVM() to transform entity data into view models
13
13
  *
14
14
  * Usage pattern:
15
15
  * 1. Access the singleton PM using the static get() method
@@ -17,14 +17,14 @@
17
17
  * 3. PM will call the view callbacks with updated view models when entities change
18
18
  * 4. Remove UI components with removeView(callback) when they're unmounted
19
19
  */
20
- import { AppObjectPM, } from "../../AppObject";
20
+ import { AppObjectSingletonPM, } from "../../AppObject";
21
21
  import { getSingletonComponent } from "../../AppObject/getSingletonComponent";
22
22
  import { SingletonEntityExample } from "../Entities/ExampleSingletonEntity";
23
23
  /**
24
24
  * ExampleSingletonPM transforms SingletonEntityExample data into an ExampleVM.
25
25
  * As a singleton, only one instance exists in the application.
26
26
  */
27
- export class ExampleSingletonPM extends AppObjectPM {
27
+ export class ExampleSingletonPM extends AppObjectSingletonPM {
28
28
  }
29
29
  /** Unique type identifier for this component */
30
30
  ExampleSingletonPM.type = "ExampleSingletonPMType";
@@ -39,7 +39,7 @@ ExampleSingletonPM.get = (appObjects) => getSingletonComponent(ExampleSingletonP
39
39
  * UI components can use this initially or when the PM is not found
40
40
  */
41
41
  export const defaultSlideNavigationVM = {
42
- aBoolProperty: true
42
+ aBoolProperty: true,
43
43
  };
44
44
  /**
45
45
  * Factory function to create a new ExampleSingletonPM
@@ -73,12 +73,10 @@ class ExampleSingletonPMImp extends ExampleSingletonPM {
73
73
  constructor(appObject) {
74
74
  super(appObject, ExampleSingletonPM.type);
75
75
  /**
76
- * Handler for entity change events
77
76
  * Transforms entity data into a view model and updates views
77
+ * Called automatically when observed entities change
78
78
  */
79
- this.onEntityChange = () => {
80
- if (!this.exampleEntity)
81
- return;
79
+ this.formVM = () => {
82
80
  // Extract the boolean property from the entity
83
81
  const aBoolProperty = this.exampleEntity.aBoolProperty;
84
82
  // Create a view model with the extracted data
@@ -87,11 +85,9 @@ class ExampleSingletonPMImp extends ExampleSingletonPM {
87
85
  this.doUpdateView(vm);
88
86
  };
89
87
  // Register as an observer of the entity to receive change notifications
90
- this.exampleEntity?.addChangeObserver(this.onEntityChange);
88
+ this.observeEntity(this.exampleEntity);
91
89
  // Call the change handler initially to set up the initial view model
92
- this.onEntityChange();
93
- // Register this PM as a singleton so it can be accessed globally
94
- this.appObjects.registerSingleton(this);
90
+ this.formVM();
95
91
  }
96
92
  }
97
93
  //# sourceMappingURL=ExampleSingletonPM.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ExampleSingletonPM.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/PMs/ExampleSingletonPM.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAEL,WAAW,GAEZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAS5E;;;GAGG;AACH,MAAM,OAAgB,kBAAmB,SAAQ,WAAsB;;AACrE,gDAAgD;AAChC,uBAAI,GAAG,wBAAwB,CAAC;AAEhD;;;;GAIG;AACI,sBAAG,GAAG,CAAC,UAAyB,EAAkC,EAAE,CACzE,qBAAqB,CAAC,kBAAkB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AAG/D;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAc;IACjD,aAAa,EAAE,IAAI;CACpB,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CACpC,SAAoB;IAEpB,OAAO,IAAI,qBAAqB,CAAC,SAAS,CAAC,CAAC;AAC9C,CAAC;AAED;;;GAGG;AACH,MAAM,qBAAsB,SAAQ,kBAAkB;IACpD;;;OAGG;IACH,IAAY,aAAa;QACvB,OAAO,IAAI,CAAC,kBAAkB,CAC5B,sBAAsB,CAAC,IAAI,CAC5B,CAAC;IACJ,CAAC;IAmBD;;;OAGG;IACH,WAAW,CAAC,CAAY,EAAE,CAAY;QACpC,IAAI,CAAC,CAAC,aAAa,KAAK,CAAC,CAAC,aAAa;YAAE,OAAO,KAAK,CAAC;QACtD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,YAAY,SAAoB;QAC9B,KAAK,CAAC,SAAS,EAAE,kBAAkB,CAAC,IAAI,CAAC,CAAC;QA3B5C;;;WAGG;QACH,mBAAc,GAAG,GAAG,EAAE;YACpB,IAAI,CAAC,IAAI,CAAC,aAAa;gBAAE,OAAO;YAEhC,+CAA+C;YAC/C,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC;YAEvD,8CAA8C;YAC9C,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,CAAC;YAE7B,sDAAsD;YACtD,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;QACxB,CAAC,CAAC;QAcA,wEAAwE;QACxE,IAAI,CAAC,aAAa,EAAE,iBAAiB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAE3D,qEAAqE;QACrE,IAAI,CAAC,cAAc,EAAE,CAAC;QAEtB,iEAAiE;QACjE,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;CACF","sourcesContent":["/**\r\n * ExampleSingletonPM.ts\r\n * \r\n * This file demonstrates how to implement a Singleton Presentation Manager (PM).\r\n * Singleton PMs are special PMs that exist only once in the application and can be\r\n * accessed globally. They transform data from singleton entities into view models.\r\n * \r\n * Key concepts:\r\n * - Singleton PMs extend AppObjectPM<VM> like regular PMs\r\n * - They register themselves as singletons with appObjects.registerSingleton()\r\n * - They're accessed through a static get() method using getSingletonComponent()\r\n * - They typically observe singleton entities and provide data to multiple UI components\r\n * \r\n * Usage pattern:\r\n * 1. Access the singleton PM using the static get() method\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 {\r\n AppObject,\r\n AppObjectPM,\r\n AppObjectRepo,\r\n} from \"../../AppObject\";\r\nimport { getSingletonComponent } from \"../../AppObject/getSingletonComponent\";\r\nimport { SingletonEntityExample } from \"../Entities/ExampleSingletonEntity\";\r\n\r\n/**\r\n * Interface defining the structure of the view model provided by ExampleSingletonPM\r\n */\r\nexport interface ExampleVM {\r\n aBoolProperty: boolean;\r\n}\r\n\r\n/**\r\n * ExampleSingletonPM transforms SingletonEntityExample data into an ExampleVM.\r\n * As a singleton, only one instance exists in the application.\r\n */\r\nexport abstract class ExampleSingletonPM extends AppObjectPM<ExampleVM> {\r\n /** Unique type identifier for this component */\r\n static readonly type = \"ExampleSingletonPMType\";\r\n\r\n /**\r\n * Global accessor for the singleton PM\r\n * @param appObjects The AppObjectRepo to search in\r\n * @returns The singleton PM or undefined if not created yet\r\n */\r\n static get = (appObjects: AppObjectRepo): ExampleSingletonPM | undefined =>\r\n getSingletonComponent(ExampleSingletonPM.type, appObjects);\r\n}\r\n\r\n/**\r\n * Default view model used when no data is available\r\n * UI components can use this initially or when the PM is not found\r\n */\r\nexport const defaultSlideNavigationVM: ExampleVM = {\r\n aBoolProperty: true\r\n};\r\n\r\n/**\r\n * Factory function to create a new ExampleSingletonPM\r\n * @param appObject The AppObject to attach the PM to\r\n * @returns A new ExampleSingletonPM instance\r\n */\r\nexport function makeExampleSingletonPM(\r\n appObject: AppObject\r\n): ExampleSingletonPM {\r\n return new ExampleSingletonPMImp(appObject);\r\n}\r\n\r\n/**\r\n * Concrete implementation of ExampleSingletonPM\r\n * This private class handles the actual implementation details\r\n */\r\nclass ExampleSingletonPMImp extends ExampleSingletonPM {\r\n /**\r\n * Gets the SingletonEntityExample from the application\r\n * Uses getCachedSingleton for efficient repeated access\r\n */\r\n private get exampleEntity() {\r\n return this.getCachedSingleton<SingletonEntityExample>(\r\n SingletonEntityExample.type\r\n );\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 onEntityChange = () => {\r\n if (!this.exampleEntity) return;\r\n\r\n // Extract the boolean property from the entity\r\n const aBoolProperty = this.exampleEntity.aBoolProperty;\r\n\r\n // Create a view model with the extracted data\r\n const vm = { aBoolProperty };\r\n\r\n // Update all registered views with the new view model\r\n this.doUpdateView(vm);\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: ExampleVM, b: ExampleVM): boolean {\r\n if (a.aBoolProperty !== b.aBoolProperty) return false;\r\n return true;\r\n }\r\n\r\n constructor(appObject: AppObject) {\r\n super(appObject, ExampleSingletonPM.type);\r\n\r\n // Register as an observer of the entity to receive change notifications\r\n this.exampleEntity?.addChangeObserver(this.onEntityChange);\r\n \r\n // Call the change handler initially to set up the initial view model\r\n this.onEntityChange();\r\n \r\n // Register this PM as a singleton so it can be accessed globally\r\n this.appObjects.registerSingleton(this);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"ExampleSingletonPM.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/PMs/ExampleSingletonPM.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAGL,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAS5E;;;GAGG;AACH,MAAM,OAAgB,kBAAmB,SAAQ,oBAA+B;;AAC9E,gDAAgD;AAChC,uBAAI,GAAG,wBAAwB,CAAC;AAEhD;;;;GAIG;AACI,sBAAG,GAAG,CAAC,UAAyB,EAAkC,EAAE,CACzE,qBAAqB,CAAC,kBAAkB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AAG/D;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAc;IACjD,aAAa,EAAE,IAAI;CACpB,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CACpC,SAAoB;IAEpB,OAAO,IAAI,qBAAqB,CAAC,SAAS,CAAC,CAAC;AAC9C,CAAC;AAED;;;GAGG;AACH,MAAM,qBAAsB,SAAQ,kBAAkB;IACpD;;;OAGG;IACH,IAAY,aAAa;QACvB,OAAO,IAAI,CAAC,kBAAkB,CAC5B,sBAAsB,CAAC,IAAI,CAC5B,CAAC;IACJ,CAAC;IAiBD;;;OAGG;IACH,WAAW,CAAC,CAAY,EAAE,CAAY;QACpC,IAAI,CAAC,CAAC,aAAa,KAAK,CAAC,CAAC,aAAa;YAAE,OAAO,KAAK,CAAC;QACtD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,YAAY,SAAoB;QAC9B,KAAK,CAAC,SAAS,EAAE,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAzB5C;;;WAGG;QACH,WAAM,GAAG,GAAG,EAAE;YACZ,+CAA+C;YAC/C,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC;YAEvD,8CAA8C;YAC9C,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,CAAC;YAE7B,sDAAsD;YACtD,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;QACxB,CAAC,CAAC;QAcA,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 * ExampleSingletonPM.ts\r\n *\r\n * This file demonstrates how to implement a Singleton Presentation Manager (PM).\r\n * Singleton PMs are special PMs that exist only once in the application and can be\r\n * accessed globally. They transform data from singleton entities into view models.\r\n *\r\n * Key concepts:\r\n * - Singleton PMs extend AppObjectSingletonPM<VM> which handles singleton registration automatically\r\n * - They're accessed through a static get() method using getSingletonComponent()\r\n * - They typically observe singleton entities and provide data to multiple UI components\r\n * - They use formVM() to transform entity data into view models\r\n *\r\n * Usage pattern:\r\n * 1. Access the singleton PM using the static get() method\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 {\r\n AppObject,\r\n AppObjectRepo,\r\n AppObjectSingletonPM,\r\n} from \"../../AppObject\";\r\nimport { getSingletonComponent } from \"../../AppObject/getSingletonComponent\";\r\nimport { SingletonEntityExample } from \"../Entities/ExampleSingletonEntity\";\r\n\r\n/**\r\n * Interface defining the structure of the view model provided by ExampleSingletonPM\r\n */\r\nexport interface ExampleVM {\r\n aBoolProperty: boolean;\r\n}\r\n\r\n/**\r\n * ExampleSingletonPM transforms SingletonEntityExample data into an ExampleVM.\r\n * As a singleton, only one instance exists in the application.\r\n */\r\nexport abstract class ExampleSingletonPM extends AppObjectSingletonPM<ExampleVM> {\r\n /** Unique type identifier for this component */\r\n static readonly type = \"ExampleSingletonPMType\";\r\n\r\n /**\r\n * Global accessor for the singleton PM\r\n * @param appObjects The AppObjectRepo to search in\r\n * @returns The singleton PM or undefined if not created yet\r\n */\r\n static get = (appObjects: AppObjectRepo): ExampleSingletonPM | undefined =>\r\n getSingletonComponent(ExampleSingletonPM.type, appObjects);\r\n}\r\n\r\n/**\r\n * Default view model used when no data is available\r\n * UI components can use this initially or when the PM is not found\r\n */\r\nexport const defaultSlideNavigationVM: ExampleVM = {\r\n aBoolProperty: true,\r\n};\r\n\r\n/**\r\n * Factory function to create a new ExampleSingletonPM\r\n * @param appObject The AppObject to attach the PM to\r\n * @returns A new ExampleSingletonPM instance\r\n */\r\nexport function makeExampleSingletonPM(\r\n appObject: AppObject\r\n): ExampleSingletonPM {\r\n return new ExampleSingletonPMImp(appObject);\r\n}\r\n\r\n/**\r\n * Concrete implementation of ExampleSingletonPM\r\n * This private class handles the actual implementation details\r\n */\r\nclass ExampleSingletonPMImp extends ExampleSingletonPM {\r\n /**\r\n * Gets the SingletonEntityExample from the application\r\n * Uses getCachedSingleton for efficient repeated access\r\n */\r\n private get exampleEntity() {\r\n return this.getCachedSingleton<SingletonEntityExample>(\r\n SingletonEntityExample.type\r\n );\r\n }\r\n\r\n /**\r\n * Transforms entity data into a view model and updates views\r\n * Called automatically when observed entities change\r\n */\r\n formVM = () => {\r\n // Extract the boolean property from the entity\r\n const aBoolProperty = this.exampleEntity.aBoolProperty;\r\n\r\n // Create a view model with the extracted data\r\n const vm = { aBoolProperty };\r\n\r\n // Update all registered views with the new view model\r\n this.doUpdateView(vm);\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: ExampleVM, b: ExampleVM): boolean {\r\n if (a.aBoolProperty !== b.aBoolProperty) return false;\r\n return true;\r\n }\r\n\r\n constructor(appObject: AppObject) {\r\n super(appObject, ExampleSingletonPM.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"]}
@@ -70,10 +70,6 @@ class EditSlideTextUCImp extends EditExampleStringUC {
70
70
  * @param text The new string value to set
71
71
  */
72
72
  this.editExampleString = (text) => {
73
- if (!this.exampleEntity) {
74
- this.warn("Unable to find AppState");
75
- return;
76
- }
77
73
  // Update the entity property, which will trigger PM updates and UI refreshes
78
74
  this.exampleEntity.aStringProperty = text;
79
75
  };
@@ -1 +1 @@
1
- {"version":3,"file":"EditExampleStringUC.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/UCs/EditExampleStringUC.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAA4B,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D;;;GAGG;AACH,MAAM,OAAgB,mBAAoB,SAAQ,WAAW;IAU3D;;;;OAIG;IACH,MAAM,CAAC,GAAG,CAAC,MAAiB;QAC1B,OAAO,MAAM,CAAC,YAAY,CAAsB,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7D,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CACZ,EAAU,EACV,UAAyB;QAEzB,OAAO,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,YAAY,CAAsB,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1E,CAAC;;AA7BD,gDAAgD;AAChC,wBAAI,GAAG,yBAAyB,CAAC;AA+BnD;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,SAAoB;IACtD,OAAO,IAAI,kBAAkB,CAAC,SAAS,CAAC,CAAC;AAC3C,CAAC;AAED;;;GAGG;AACH,MAAM,kBAAmB,SAAQ,mBAAmB;IAClD;;;OAGG;IACH,IAAY,aAAa;QACvB,OAAO,IAAI,CAAC,uBAAuB,CAAgB,aAAa,CAAC,IAAI,CAAC,CAAC;IACzE,CAAC;IAgBD,YAAY,SAAoB;QAC9B,KAAK,CAAC,SAAS,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;QAf7C;;;WAGG;QACH,sBAAiB,GAAG,CAAC,IAAY,EAAE,EAAE;YACnC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;gBACxB,IAAI,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;gBACrC,OAAO;YACT,CAAC;YAED,6EAA6E;YAC7E,IAAI,CAAC,aAAa,CAAC,eAAe,GAAG,IAAI,CAAC;QAC5C,CAAC,CAAC;IAIF,CAAC;CACF","sourcesContent":["/**\r\n * EditExampleStringUC.ts\r\n * \r\n * This file demonstrates how to implement a Use Case (UC) component.\r\n * UCs handle business logic and operations that modify entities.\r\n * They encapsulate specific actions that can be performed in the application.\r\n * \r\n * Key concepts:\r\n * - UCs extend AppObjectUC and provide methods for specific operations\r\n * - They implement business logic for modifying entities\r\n * - They validate inputs and handle errors\r\n * - Each UC instance is associated with a specific AppObject\r\n * \r\n * Usage pattern:\r\n * 1. Get a UC instance using getById or get\r\n * 2. Call the UC's methods to perform operations\r\n * 3. The UC will update entities, which will trigger PM updates and UI refreshes\r\n */\r\n\r\nimport { AppObject, AppObjectRepo, AppObjectUC } from \"../../AppObject\";\r\nimport { ExampleEntity } from \"../Entities/ExampleEntity\";\r\n\r\n/**\r\n * EditExampleStringUC provides functionality to update the string property of an ExampleEntity.\r\n * Abstract class provides the interface and static helper methods.\r\n */\r\nexport abstract class EditExampleStringUC extends AppObjectUC {\r\n /** Unique type identifier for this component */\r\n static readonly type = \"EditExampleStringUCType\";\r\n\r\n /**\r\n * Updates the string property of the associated ExampleEntity\r\n * @param text The new string value to set\r\n */\r\n abstract editExampleString(text: string): void;\r\n\r\n /**\r\n * Retrieves an EditExampleStringUC component from an AppObject\r\n * @param appObj The AppObject to get the component from\r\n * @returns The EditExampleStringUC component or undefined if not found\r\n */\r\n static get(appObj: AppObject): EditExampleStringUC | undefined {\r\n return appObj.getComponent<EditExampleStringUC>(this.type);\r\n }\r\n\r\n /**\r\n * Retrieves an EditExampleStringUC 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 EditExampleStringUC component or undefined if not found\r\n */\r\n static getById(\r\n id: string,\r\n appObjects: AppObjectRepo\r\n ): EditExampleStringUC | undefined {\r\n return appObjects.get(id)?.getComponent<EditExampleStringUC>(this.type);\r\n }\r\n}\r\n\r\n/**\r\n * Factory function to create a new EditExampleStringUC\r\n * @param appObject The AppObject to attach the UC to\r\n * @returns A new EditExampleStringUC instance\r\n */\r\nexport function makeEditSlideTextUC(appObject: AppObject): EditExampleStringUC {\r\n return new EditSlideTextUCImp(appObject);\r\n}\r\n\r\n/**\r\n * Concrete implementation of EditExampleStringUC\r\n * This private class handles the actual implementation details\r\n */\r\nclass EditSlideTextUCImp extends EditExampleStringUC {\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 * Implements the editExampleString method to update the entity's string property\r\n * @param text The new string value to set\r\n */\r\n editExampleString = (text: string) => {\r\n if (!this.exampleEntity) {\r\n this.warn(\"Unable to find AppState\");\r\n return;\r\n }\r\n\r\n // Update the entity property, which will trigger PM updates and UI refreshes\r\n this.exampleEntity.aStringProperty = text;\r\n };\r\n\r\n constructor(appObject: AppObject) {\r\n super(appObject, EditExampleStringUC.type);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"EditExampleStringUC.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/UCs/EditExampleStringUC.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAA4B,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D;;;GAGG;AACH,MAAM,OAAgB,mBAAoB,SAAQ,WAAW;IAU3D;;;;OAIG;IACH,MAAM,CAAC,GAAG,CAAC,MAAiB;QAC1B,OAAO,MAAM,CAAC,YAAY,CAAsB,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7D,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CACZ,EAAU,EACV,UAAyB;QAEzB,OAAO,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,YAAY,CAAsB,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1E,CAAC;;AA7BD,gDAAgD;AAChC,wBAAI,GAAG,yBAAyB,CAAC;AA+BnD;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,SAAoB;IACtD,OAAO,IAAI,kBAAkB,CAAC,SAAS,CAAC,CAAC;AAC3C,CAAC;AAED;;;GAGG;AACH,MAAM,kBAAmB,SAAQ,mBAAmB;IAClD;;;OAGG;IACH,IAAY,aAAa;QACvB,OAAO,IAAI,CAAC,uBAAuB,CAAgB,aAAa,CAAC,IAAI,CAAC,CAAC;IACzE,CAAC;IAYD,YAAY,SAAoB;QAC9B,KAAK,CAAC,SAAS,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;QAX7C;;;WAGG;QACH,sBAAiB,GAAG,CAAC,IAAY,EAAE,EAAE;YAEnC,6EAA6E;YAC7E,IAAI,CAAC,aAAa,CAAC,eAAe,GAAG,IAAI,CAAC;QAC5C,CAAC,CAAC;IAIF,CAAC;CACF","sourcesContent":["/**\r\n * EditExampleStringUC.ts\r\n * \r\n * This file demonstrates how to implement a Use Case (UC) component.\r\n * UCs handle business logic and operations that modify entities.\r\n * They encapsulate specific actions that can be performed in the application.\r\n * \r\n * Key concepts:\r\n * - UCs extend AppObjectUC and provide methods for specific operations\r\n * - They implement business logic for modifying entities\r\n * - They validate inputs and handle errors\r\n * - Each UC instance is associated with a specific AppObject\r\n * \r\n * Usage pattern:\r\n * 1. Get a UC instance using getById or get\r\n * 2. Call the UC's methods to perform operations\r\n * 3. The UC will update entities, which will trigger PM updates and UI refreshes\r\n */\r\n\r\nimport { AppObject, AppObjectRepo, AppObjectUC } from \"../../AppObject\";\r\nimport { ExampleEntity } from \"../Entities/ExampleEntity\";\r\n\r\n/**\r\n * EditExampleStringUC provides functionality to update the string property of an ExampleEntity.\r\n * Abstract class provides the interface and static helper methods.\r\n */\r\nexport abstract class EditExampleStringUC extends AppObjectUC {\r\n /** Unique type identifier for this component */\r\n static readonly type = \"EditExampleStringUCType\";\r\n\r\n /**\r\n * Updates the string property of the associated ExampleEntity\r\n * @param text The new string value to set\r\n */\r\n abstract editExampleString(text: string): void;\r\n\r\n /**\r\n * Retrieves an EditExampleStringUC component from an AppObject\r\n * @param appObj The AppObject to get the component from\r\n * @returns The EditExampleStringUC component or undefined if not found\r\n */\r\n static get(appObj: AppObject): EditExampleStringUC | undefined {\r\n return appObj.getComponent<EditExampleStringUC>(this.type);\r\n }\r\n\r\n /**\r\n * Retrieves an EditExampleStringUC 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 EditExampleStringUC component or undefined if not found\r\n */\r\n static getById(\r\n id: string,\r\n appObjects: AppObjectRepo\r\n ): EditExampleStringUC | undefined {\r\n return appObjects.get(id)?.getComponent<EditExampleStringUC>(this.type);\r\n }\r\n}\r\n\r\n/**\r\n * Factory function to create a new EditExampleStringUC\r\n * @param appObject The AppObject to attach the UC to\r\n * @returns A new EditExampleStringUC instance\r\n */\r\nexport function makeEditSlideTextUC(appObject: AppObject): EditExampleStringUC {\r\n return new EditSlideTextUCImp(appObject);\r\n}\r\n\r\n/**\r\n * Concrete implementation of EditExampleStringUC\r\n * This private class handles the actual implementation details\r\n */\r\nclass EditSlideTextUCImp extends EditExampleStringUC {\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 * Implements the editExampleString method to update the entity's string property\r\n * @param text The new string value to set\r\n */\r\n editExampleString = (text: string) => {\r\n\r\n // Update the entity property, which will trigger PM updates and UI refreshes\r\n this.exampleEntity.aStringProperty = text;\r\n };\r\n\r\n constructor(appObject: AppObject) {\r\n super(appObject, EditExampleStringUC.type);\r\n }\r\n}\r\n"]}
@@ -16,14 +16,14 @@
16
16
  * 2. Call the UC's methods to perform operations
17
17
  * 3. The UC will update entities, which will trigger PM updates and UI refreshes
18
18
  */
19
- import { AppObjectUC } from "../../AppObject";
19
+ import { AppObjectSingletonUC, } from "../../AppObject";
20
20
  import { getSingletonComponent } from "../../AppObject/getSingletonComponent";
21
21
  import { SingletonEntityExample } from "../Entities/ExampleSingletonEntity";
22
22
  /**
23
23
  * ToggleExampleBooleanUC provides functionality to toggle the boolean property
24
24
  * of the SingletonEntityExample. As a singleton, only one instance exists in the application.
25
25
  */
26
- export class ToggleExampleBooleanUC extends AppObjectUC {
26
+ export class ToggleExampleBooleanUC extends AppObjectSingletonUC {
27
27
  }
28
28
  /** Unique type identifier for this component */
29
29
  ToggleExampleBooleanUC.type = "ToggleExampleBooleanUCType";
@@ -59,16 +59,10 @@ class ToggleExampleBooleanUCImp extends ToggleExampleBooleanUC {
59
59
  * Implements the toggleExampleBoolean method to invert the entity's boolean property
60
60
  */
61
61
  this.toggleExampleBoolean = () => {
62
- if (!this.singletonEntityExample) {
63
- this.warn("Unable to find SingletonEntityExample");
64
- return;
65
- }
66
62
  // Toggle the boolean property by inverting its current value
67
63
  this.singletonEntityExample.aBoolProperty =
68
- !this.singletonEntityExample?.aBoolProperty;
64
+ !this.singletonEntityExample.aBoolProperty;
69
65
  };
70
- // Register this UC as a singleton so it can be accessed globally
71
- this.appObjects.registerSingleton(this);
72
66
  }
73
67
  }
74
68
  //# sourceMappingURL=ToggleExampleBooleanUC.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ToggleExampleBooleanUC.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/UCs/ToggleExampleBooleanUC.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAGL,WAAW,EACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAE5E;;;GAGG;AACH,MAAM,OAAgB,sBAAuB,SAAQ,WAAW;;AAC9D,gDAAgD;AAChC,2BAAI,GAAG,4BAA4B,CAAC;AAOpD;;;;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;IAC5D;;;OAGG;IACH,IAAY,sBAAsB;QAChC,OAAO,IAAI,CAAC,kBAAkB,CAC5B,sBAAsB,CAAC,IAAI,CAC5B,CAAC;IACJ,CAAC;IAgBD,YAAY,SAAoB;QAC9B,KAAK,CAAC,SAAS,EAAE,sBAAsB,CAAC,IAAI,CAAC,CAAC;QAfhD;;WAEG;QACH,yBAAoB,GAAG,GAAG,EAAE;YAC1B,IAAI,CAAC,IAAI,CAAC,sBAAsB,EAAE,CAAC;gBACjC,IAAI,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;gBACnD,OAAO;YACT,CAAC;YAED,6DAA6D;YAC7D,IAAI,CAAC,sBAAsB,CAAC,aAAa;gBACvC,CAAC,IAAI,CAAC,sBAAsB,EAAE,aAAa,CAAC;QAChD,CAAC,CAAC;QAIA,iEAAiE;QACjE,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;CACF","sourcesContent":["/**\r\n * ToggleExampleBooleanUC.ts\r\n * \r\n * This file demonstrates how to implement a Singleton Use Case (UC) component.\r\n * Singleton UCs are special UCs that exist only once in the application and can be\r\n * accessed globally. They handle business logic and operations that modify singleton entities.\r\n * \r\n * Key concepts:\r\n * - Singleton UCs extend AppObjectUC like regular UCs\r\n * - They register themselves as singletons with appObjects.registerSingleton()\r\n * - They're accessed through a static get() method using getSingletonComponent()\r\n * - They typically operate on singleton entities\r\n * \r\n * Usage pattern:\r\n * 1. Access the singleton UC using the static get() method\r\n * 2. Call the UC's methods to perform operations\r\n * 3. The UC will update entities, which will trigger PM updates and UI refreshes\r\n */\r\n\r\nimport {\r\n AppObject,\r\n AppObjectRepo,\r\n AppObjectUC\r\n} from \"../../AppObject\";\r\nimport { getSingletonComponent } from \"../../AppObject/getSingletonComponent\";\r\nimport { SingletonEntityExample } from \"../Entities/ExampleSingletonEntity\";\r\n\r\n/**\r\n * ToggleExampleBooleanUC provides functionality to toggle the boolean property\r\n * of the SingletonEntityExample. As a singleton, only one instance exists in the application.\r\n */\r\nexport abstract class ToggleExampleBooleanUC extends AppObjectUC {\r\n /** Unique type identifier for this component */\r\n static readonly type = \"ToggleExampleBooleanUCType\";\r\n\r\n /**\r\n * Toggles the boolean property of the SingletonEntityExample\r\n */\r\n abstract toggleExampleBoolean(): void;\r\n\r\n /**\r\n * Global accessor for the singleton UC\r\n * @param appObjects The AppObjectRepo to search in\r\n * @returns The singleton UC or undefined if not created yet\r\n */\r\n static get = (\r\n appObjects: AppObjectRepo\r\n ): ToggleExampleBooleanUC | undefined =>\r\n getSingletonComponent(ToggleExampleBooleanUC.type, appObjects);\r\n}\r\n\r\n/**\r\n * Factory function to create a new ToggleExampleBooleanUC\r\n * @param appObject The AppObject to attach the UC to\r\n * @returns A new ToggleExampleBooleanUC instance\r\n */\r\nexport function makeToggleExampleBooleanUC(\r\n appObject: AppObject\r\n): ToggleExampleBooleanUC {\r\n return new ToggleExampleBooleanUCImp(appObject);\r\n}\r\n\r\n/**\r\n * Concrete implementation of ToggleExampleBooleanUC\r\n * This private class handles the actual implementation details\r\n */\r\nclass ToggleExampleBooleanUCImp extends ToggleExampleBooleanUC {\r\n /**\r\n * Gets the SingletonEntityExample from the application\r\n * Uses getCachedSingleton for efficient repeated access\r\n */\r\n private get singletonEntityExample() {\r\n return this.getCachedSingleton<SingletonEntityExample>(\r\n SingletonEntityExample.type\r\n );\r\n }\r\n\r\n /**\r\n * Implements the toggleExampleBoolean method to invert the entity's boolean property\r\n */\r\n toggleExampleBoolean = () => {\r\n if (!this.singletonEntityExample) {\r\n this.warn(\"Unable to find SingletonEntityExample\");\r\n return;\r\n }\r\n\r\n // Toggle the boolean property by inverting its current value\r\n this.singletonEntityExample.aBoolProperty =\r\n !this.singletonEntityExample?.aBoolProperty;\r\n };\r\n\r\n constructor(appObject: AppObject) {\r\n super(appObject, ToggleExampleBooleanUC.type);\r\n // Register this UC as a singleton so it can be accessed globally\r\n this.appObjects.registerSingleton(this);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"ToggleExampleBooleanUC.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/UCs/ToggleExampleBooleanUC.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAGL,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAE5E;;;GAGG;AACH,MAAM,OAAgB,sBAAuB,SAAQ,oBAAoB;;AACvE,gDAAgD;AAChC,2BAAI,GAAG,4BAA4B,CAAC;AAOpD;;;;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;IAC5D;;;OAGG;IACH,IAAY,sBAAsB;QAChC,OAAO,IAAI,CAAC,kBAAkB,CAC5B,sBAAsB,CAAC,IAAI,CAC5B,CAAC;IACJ,CAAC;IAWD,YAAY,SAAoB;QAC9B,KAAK,CAAC,SAAS,EAAE,sBAAsB,CAAC,IAAI,CAAC,CAAC;QAVhD;;WAEG;QACH,yBAAoB,GAAG,GAAG,EAAE;YAC1B,6DAA6D;YAC7D,IAAI,CAAC,sBAAsB,CAAC,aAAa;gBACvC,CAAC,IAAI,CAAC,sBAAsB,CAAC,aAAa,CAAC;QAC/C,CAAC,CAAC;IAIF,CAAC;CACF","sourcesContent":["/**\r\n * ToggleExampleBooleanUC.ts\r\n *\r\n * This file demonstrates how to implement a Singleton Use Case (UC) component.\r\n * Singleton UCs are special UCs that exist only once in the application and can be\r\n * accessed globally. They handle business logic and operations that modify singleton entities.\r\n *\r\n * Key concepts:\r\n * - Singleton UCs extend AppObjectUC like regular UCs\r\n * - They register themselves as singletons with appObjects.registerSingleton()\r\n * - They're accessed through a static get() method using getSingletonComponent()\r\n * - They typically operate on singleton entities\r\n *\r\n * Usage pattern:\r\n * 1. Access the singleton UC using the static get() method\r\n * 2. Call the UC's methods to perform operations\r\n * 3. The UC will update entities, which will trigger PM updates and UI refreshes\r\n */\r\n\r\nimport {\r\n AppObject,\r\n AppObjectRepo,\r\n AppObjectSingletonUC,\r\n} from \"../../AppObject\";\r\nimport { getSingletonComponent } from \"../../AppObject/getSingletonComponent\";\r\nimport { SingletonEntityExample } from \"../Entities/ExampleSingletonEntity\";\r\n\r\n/**\r\n * ToggleExampleBooleanUC provides functionality to toggle the boolean property\r\n * of the SingletonEntityExample. As a singleton, only one instance exists in the application.\r\n */\r\nexport abstract class ToggleExampleBooleanUC extends AppObjectSingletonUC {\r\n /** Unique type identifier for this component */\r\n static readonly type = \"ToggleExampleBooleanUCType\";\r\n\r\n /**\r\n * Toggles the boolean property of the SingletonEntityExample\r\n */\r\n abstract toggleExampleBoolean(): void;\r\n\r\n /**\r\n * Global accessor for the singleton UC\r\n * @param appObjects The AppObjectRepo to search in\r\n * @returns The singleton UC or undefined if not created yet\r\n */\r\n static get = (\r\n appObjects: AppObjectRepo\r\n ): ToggleExampleBooleanUC | undefined =>\r\n getSingletonComponent(ToggleExampleBooleanUC.type, appObjects);\r\n}\r\n\r\n/**\r\n * Factory function to create a new ToggleExampleBooleanUC\r\n * @param appObject The AppObject to attach the UC to\r\n * @returns A new ToggleExampleBooleanUC instance\r\n */\r\nexport function makeToggleExampleBooleanUC(\r\n appObject: AppObject\r\n): ToggleExampleBooleanUC {\r\n return new ToggleExampleBooleanUCImp(appObject);\r\n}\r\n\r\n/**\r\n * Concrete implementation of ToggleExampleBooleanUC\r\n * This private class handles the actual implementation details\r\n */\r\nclass ToggleExampleBooleanUCImp extends ToggleExampleBooleanUC {\r\n /**\r\n * Gets the SingletonEntityExample from the application\r\n * Uses getCachedSingleton for efficient repeated access\r\n */\r\n private get singletonEntityExample() {\r\n return this.getCachedSingleton<SingletonEntityExample>(\r\n SingletonEntityExample.type\r\n );\r\n }\r\n\r\n /**\r\n * Implements the toggleExampleBoolean method to invert the entity's boolean property\r\n */\r\n toggleExampleBoolean = () => {\r\n // Toggle the boolean property by inverting its current value\r\n this.singletonEntityExample.aBoolProperty =\r\n !this.singletonEntityExample.aBoolProperty;\r\n };\r\n\r\n constructor(appObject: AppObject) {\r\n super(appObject, ToggleExampleBooleanUC.type);\r\n }\r\n}\r\n"]}
@@ -49,17 +49,19 @@ export declare class AppObjectComponent {
49
49
  * Results are cached for better performance in repeated calls
50
50
  *
51
51
  * @param type The component type identifier to look up
52
- * @returns The singleton component cast to type T, or undefined if not found
52
+ * @returns The singleton component cast to type T
53
+ * @throws Error if the component is not found
53
54
  */
54
- getCachedSingleton<T extends AppObjectComponent>(type: string): T | undefined;
55
+ getCachedSingleton<T extends AppObjectComponent>(type: string): T;
55
56
  /**
56
57
  * Retrieves a component from the same AppObject as this component
57
58
  * Results are cached for better performance in repeated calls
58
59
  *
59
60
  * @param type The component type identifier to look up
60
- * @returns The component cast to type T, or undefined if not found
61
+ * @returns The component cast to type T
62
+ * @throws Error if the component is not found
61
63
  */
62
- getCachedLocalComponent<T extends AppObjectComponent>(type: string): T | undefined;
64
+ getCachedLocalComponent<T extends AppObjectComponent>(type: string): T;
63
65
  /**
64
66
  * Retrieves a singleton component from the repository with customizable logging
65
67
  * Unlike getCachedSingleton, results are not cached
@@ -1 +1 @@
1
- {"version":3,"file":"AppObjectComponent.d.ts","sourceRoot":"","sources":["../../../src/AppObject/AppObjectComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;GAGG;AACH,oBAAY,sBAAsB;IAChC,2CAA2C;IAC3C,MAAM,WAAW;IAEjB,oDAAoD;IACpD,EAAE,yBAAyB;IAE3B,+DAA+D;IAC/D,EAAE,aAAa;IAEf,8CAA8C;IAC9C,UAAU,eAAe;IAEzB,sEAAsE;IACtE,IAAI,SAAS;IAEb,yEAAyE;IACzE,OAAO,YAAY;CACpB;AAED;;;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AyB;IAE3B,+DAA+D;IAC/D,EAAE,aAAa;IAEf,8CAA8C;IAC9C,UAAU,eAAe;IAEzB,sEAAsE;IACtE,IAAI,SAAS;IAEb,yEAAyE;IACzE,OAAO,YAAY;CACpB;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,kBAAkB;IAC7B,0CAA0C;IAC1C,QAAQ,CAAC,aAAa,EAAE,sBAAsB,CACb;IAEjC,yDAAyD;IACzD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,yDAAyD;IACzD,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAE9B;;;OAGG;IACH,IAAI,UAAU,IAAI,aAAa,CAE9B;IAED,qDAAqD;IACrD,OAAO,CAAC,gBAAgB,CAAyC;IAEjE;;;;;;;OAOG;IACH,kBAAkB,CAAC,CAAC,SAAS,kBAAkB,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC;IAYjE;;;;;;;OAOG;IACH,uBAAuB,CAAC,CAAC,SAAS,kBAAkB,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC;IAatE;;;;;;;OAOG;IACH,YAAY,CAAC,CAAC,SAAS,kBAAkB,EACvC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,KAAK,GAAG,MAAM,GAAG,OAAgB,GACzC,CAAC,GAAG,SAAS;IAqBhB;;;OAGG;IACH,OAAO;IAMP;;;;;OAKG;IACH,GAAG,CAAC,OAAO,EAAE,MAAM;IAInB;;;;;OAKG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM;IAIpB;;;;;OAKG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM;IAIrB;;;;;OAKG;gBACS,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM;CAK/C"}
@@ -1,3 +1,4 @@
1
+ import { AppObject } from "./AppObject";
1
2
  import { AppObjectEntity } from "./AppObjectEntity";
2
3
  /**
3
4
  * A repository for managing collections of AppObjectEntity instances.
@@ -6,20 +7,32 @@ import { AppObjectEntity } from "./AppObjectEntity";
6
7
  * entities that are associated with specific AppObjects. It implements the observer
7
8
  * pattern to notify listeners when entities are added or removed.
8
9
  *
10
+ * Derived classes should override the `entityFactory` method to provide custom
11
+ * entity creation logic for the `create` method.
12
+ *
9
13
  * @template T - The type of entities managed by this repository, must extend AppObjectEntity
10
14
  * @extends AppObjectEntity
11
15
  *
12
16
  * @example
13
17
  * ```typescript
14
- * // Create a repository for player entities
15
- * const playerRepo = new AppObjectEntityRepo<PlayerEntity>();
18
+ * // Create a custom repository with entity factory
19
+ * class PlayerRepo extends AppObjectEntityRepo<PlayerEntity> {
20
+ * entityFactory(id: string): PlayerEntity {
21
+ * const appObject = makeAppObject(id, this.appObjects);
22
+ * return new PlayerEntity(appObject);
23
+ * }
24
+ * }
25
+ *
26
+ * const playerRepo = new PlayerRepo(repoAppObject);
16
27
  *
17
- * // Add a new player
18
- * const player = new PlayerEntity(appObject);
19
- * playerRepo.add(player);
28
+ * // Create a new player with auto-generated ID
29
+ * const player = playerRepo.create();
20
30
  *
21
- * // Get a player by its AppObject ID
22
- * const retrievedPlayer = playerRepo.getForAppObject("player1");
31
+ * // Create a new player with specific ID
32
+ * const specificPlayer = playerRepo.create("player1");
33
+ *
34
+ * // Get a player by its ID
35
+ * const retrievedPlayer = playerRepo.getById("player1");
23
36
  * ```
24
37
  */
25
38
  export declare class AppObjectEntityRepo<T extends AppObjectEntity> extends AppObjectEntity {
@@ -50,11 +63,19 @@ export declare class AppObjectEntityRepo<T extends AppObjectEntity> extends AppO
50
63
  * @param {(removedEntity: T) => void} observer - The callback function to remove
51
64
  */
52
65
  removeEntityRemovedObserver: (observer: (removedEntity: T) => void) => void;
66
+ /**
67
+ * Checks if an entity exists for the given ID.
68
+ *
69
+ * @param {string} id - The ID of the AppObject
70
+ * @returns {boolean} True if an entity exists for the given ID, false otherwise
71
+ */
72
+ has: (id: string) => boolean;
53
73
  /**
54
74
  * Checks if an entity exists for the given AppObject ID.
55
75
  *
56
76
  * @param {string} appObjectID - The ID of the AppObject
57
77
  * @returns {boolean} True if an entity exists for the given AppObject ID, false otherwise
78
+ * @deprecated Use has instead
58
79
  */
59
80
  hasForAppObject: (appObjectID: string) => boolean;
60
81
  /**
@@ -66,19 +87,64 @@ export declare class AppObjectEntityRepo<T extends AppObjectEntity> extends AppO
66
87
  * @param {T} entity - The entity to add
67
88
  */
68
89
  add(entity: T): void;
90
+ /**
91
+ * Creates a new entity with the specified or auto-generated ID and adds it to the repository.
92
+ *
93
+ * This method uses the `entityFactory` method to create the entity instance.
94
+ * If no ID is provided, a unique ID is generated automatically.
95
+ *
96
+ * @param {string} [id] - Optional ID for the entity. If not provided, a unique ID is generated.
97
+ * @returns {T} The newly created entity
98
+ */
99
+ create(id?: string): T;
100
+ /**
101
+ * Factory method for creating entity instances.
102
+ *
103
+ * This method must be overridden in derived classes to provide custom entity creation logic.
104
+ * It is called by the `create` method to instantiate new entities.
105
+ *
106
+ * @param {string} id - The ID to use for the new entity
107
+ * @returns {T} A new entity instance
108
+ * @throws {Error} If not overridden in derived class
109
+ */
110
+ entityFactory(appObject: AppObject): T;
111
+ /**
112
+ * Removes the entity associated with the specified ID.
113
+ *
114
+ * Notifies all registered observers after the entity is removed.
115
+ *
116
+ * @param {string} id - The ID of the AppObject whose entity should be removed
117
+ */
118
+ removeById: (id: string) => void;
69
119
  /**
70
120
  * Removes the entity associated with the specified AppObject ID.
71
121
  *
72
122
  * Notifies all registered observers after the entity is removed.
73
123
  *
74
124
  * @param {string} id - The ID of the AppObject whose entity should be removed
125
+ * @deprecated Use removeById instead
75
126
  */
76
127
  removeForAppObject: (id: string) => void;
128
+ /**
129
+ * Removes all entities from the repository.
130
+ *
131
+ * Unsubscribes from all entity change observers and notifies all registered
132
+ * removal observers for each entity before clearing the repository.
133
+ */
134
+ deleteAll: () => void;
135
+ /**
136
+ * Gets the entity associated with the specified ID.
137
+ *
138
+ * @param {string} id - The ID of the AppObject
139
+ * @returns {T | undefined} The entity if found, undefined otherwise
140
+ */
141
+ getById: (id: string) => T | undefined;
77
142
  /**
78
143
  * Gets the entity associated with the specified AppObject ID.
79
144
  *
80
145
  * @param {string} appObjectID - The ID of the AppObject
81
146
  * @returns {T | undefined} The entity if found, undefined otherwise
147
+ * @deprecated Use getById instead
82
148
  */
83
149
  getForAppObject: (appObjectID: string) => T | undefined;
84
150
  /**
@@ -87,5 +153,12 @@ export declare class AppObjectEntityRepo<T extends AppObjectEntity> extends AppO
87
153
  * @returns {T[]} An array of all entities
88
154
  */
89
155
  getAll: () => T[];
156
+ /**
157
+ * Gets an entity by ID, or creates it if it doesn't exist.
158
+ *
159
+ * @param {string} id - The ID of the entity to get or create
160
+ * @returns {T} The existing or newly created entity
161
+ */
162
+ getOrCreate: (id: string) => T;
90
163
  }
91
164
  //# sourceMappingURL=AppObjectEntityRepo.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AppObjectEntityRepo.d.ts","sourceRoot":"","sources":["../../../src/AppObject/AppObjectEntityRepo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,mBAAmB,CAC9B,CAAC,SAAS,eAAe,CACzB,SAAQ,eAAe;IACvB,OAAO,CAAC,YAAY,CAAwB;IAE5C,OAAO,CAAC,sBAAsB,CAAyB;IACvD;;;;OAIG;IACH,sBAAsB,GAAI,UAAU,CAAC,WAAW,EAAE,CAAC,KAAK,IAAI,UAE1D;IAEF;;;;OAIG;IACH,yBAAyB,GAAI,UAAU,CAAC,WAAW,EAAE,CAAC,KAAK,IAAI,KAAG,IAAI,CAEpE;IAEF,OAAO,CAAC,wBAAwB,CAAyB;IACzD;;;;OAIG;IACH,wBAAwB,GAAI,UAAU,CAAC,aAAa,EAAE,CAAC,KAAK,IAAI,UAE9D;IAEF;;;;OAIG;IACH,2BAA2B,GACzB,UAAU,CAAC,aAAa,EAAE,CAAC,KAAK,IAAI,KACnC,IAAI,CAEL;IAE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;IACH,GAAG,CAAC,MAAM,EAAE,CAAC;IAYb;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC;IAQtB;;;;;;;;;OASG;IACH,aAAa,CAAC,SAAS,EAAE,SAAS,GAAG,CAAC;IAKtC;;;;;;OAMG;IACH,UAAU,GAAI,IAAI,MAAM,UAQtB;IAEF;;;;;;;OAOG;IACH,kBAAkB,GAAI,IAAI,MAAM,UAE9B;IAEF;;;;;OAKG;IACH,SAAS,aAUP;IAEF;;;;;OAKG;IACH,OAAO,GAAI,IAAI,MAAM,KAAG,CAAC,GAAG,SAAS,CAEnC;IAEF;;;;;;OAMG;IACH,eAAe,GAAI,aAAa,MAAM,KAAG,CAAC,GAAG,SAAS,CAEpD;IAEF;;;;OAIG;IACH,MAAM,QAAO,CAAC,EAAE,CAEd;IAEF;;;;;OAKG;IACH,WAAW,GAAI,IAAI,MAAM,KAAG,CAAC,CAM3B;CACH"}
@@ -1,4 +1,5 @@
1
1
  import { AppObjectComponent, AppObjectComponentType } from "./AppObjectComponent";
2
+ import { AppObjectEntity } from "./AppObjectEntity";
2
3
  /**
3
4
  * Presentation Manager (PM) component that transforms application state into view models
4
5
  *
@@ -28,13 +29,28 @@ export declare abstract class AppObjectPM<T> extends AppObjectComponent {
28
29
  abstract vmsAreEqual(a: T, b: T): boolean;
29
30
  /** The most recently generated view model */
30
31
  private _lastVM?;
32
+ /**
33
+ * Optional default view model to return when no view model has been generated yet.
34
+ * If set, this value will be returned by the `lastVM` getter before any view model
35
+ * has been created via `doUpdateView`.
36
+ *
37
+ * This is useful for providing initial state to views without requiring immediate
38
+ * view model generation.
39
+ */
40
+ defaultVM?: T;
31
41
  /**
32
42
  * Gets the most recently generated view model
33
- * @returns The last view model or undefined if none has been generated
43
+ * @returns The last view model, or `defaultVM` if no view model has been generated yet,
44
+ * or undefined if neither exists
34
45
  */
35
46
  get lastVM(): T | undefined;
36
47
  /** List of view update functions to notify when the view model changes */
37
- private observerList;
48
+ private views;
49
+ /**
50
+ * List of entities being observed by this PM.
51
+ * Used for automatic cleanup during disposal.
52
+ */
53
+ private observedEntities;
38
54
  /**
39
55
  * Registers a view update function to be called when the view model changes
40
56
  * If a view model already exists, the provided function is called immediately with that model
@@ -42,6 +58,64 @@ export declare abstract class AppObjectPM<T> extends AppObjectComponent {
42
58
  * @param updateView Function to call with updated view models
43
59
  */
44
60
  addView(updateView: (vm: T) => void): void;
61
+ /**
62
+ * Called when an observed entity changes.
63
+ * If views are registered, this method calls `formVM()` to regenerate the view model.
64
+ *
65
+ * This method is automatically invoked when entities registered via `observeEntity()`
66
+ * notify their observers. It implements lazy evaluation - view models are only
67
+ * formed when there are views to receive them.
68
+ */
69
+ onEntityChanged(): void;
70
+ /**
71
+ * Forms and updates the view model based on current entity state.
72
+ *
73
+ * Override this method in derived classes to:
74
+ * 1. Read data from observed entities
75
+ * 2. Transform the data into a view model
76
+ * 3. Call `doUpdateView(vm)` with the new view model
77
+ *
78
+ * This method is only called when at least one view has been registered,
79
+ * implementing lazy evaluation to avoid unnecessary computation.
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * formVM(): void {
84
+ * const entity = this.getCachedLocalComponent<MyEntity>(MyEntity.type);
85
+ * if (entity) {
86
+ * this.doUpdateView({
87
+ * displayName: entity.name,
88
+ * isActive: entity.active
89
+ * });
90
+ * }
91
+ * }
92
+ * ```
93
+ */
94
+ formVM(): void;
95
+ onViewAdded(): void;
96
+ /**
97
+ * Registers an entity to be observed for changes.
98
+ *
99
+ * When the entity notifies of changes (via `notifyOnChange()`), this PM will
100
+ * automatically call `onEntityChanged()`, which in turn calls `formVM()` if
101
+ * views are registered.
102
+ *
103
+ * The entity observer is automatically cleaned up when this PM is disposed.
104
+ *
105
+ * @param entity The entity to observe for changes
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * constructor(appObj: AppObject) {
110
+ * super(appObj, MyPM.type);
111
+ * const entity = appObj.getComponent<MyEntity>(MyEntity.type);
112
+ * if (entity) {
113
+ * this.observeEntity(entity);
114
+ * }
115
+ * }
116
+ * ```
117
+ */
118
+ protected observeEntity(entity: AppObjectEntity): void;
45
119
  /**
46
120
  * Unregisters a previously added view update function
47
121
  *
@@ -60,6 +134,12 @@ export declare abstract class AppObjectPM<T> extends AppObjectComponent {
60
134
  doUpdateView(vm: T): void;
61
135
  /**
62
136
  * Cleans up resources and detaches this PM from its parent AppObject
137
+ *
138
+ * This method:
139
+ * 1. Removes change observers from all observed entities
140
+ * 2. Clears all view observers
141
+ * 3. Removes this component from its parent AppObject if still attached
142
+ * 4. Calls the parent class dispose method
63
143
  */
64
144
  dispose(): void;
65
145
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AppObjectPM.d.ts","sourceRoot":"","sources":["../../../src/AppObject/AppObjectPM.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAElF;;;;;;;;;;;;;;GAcG;AACH,8BAAsB,WAAW,CAAC,CAAC,CAAE,SAAQ,kBAAkB;IAC7D,0DAA0D;IAC1D,QAAQ,CAAC,aAAa,6BAA6B;IAEnD;;;;;;;OAOG;IACH,QAAQ,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO;IAEzC,6CAA6C;IAC7C,OAAO,CAAC,OAAO,CAAC,CAAI;IAEpB;;;OAGG;IACH,IAAI,MAAM,IAAI,CAAC,GAAG,SAAS,CAE1B;IAED,0EAA0E;IAC1E,OAAO,CAAC,YAAY,CAAyB;IAE7C;;;;;OAKG;IACH,OAAO,CAAC,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,IAAI,GAAG,IAAI;IAS1C;;;;OAIG;IACH,UAAU,CAAC,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,IAAI,GAAG,IAAI;IAI7C;;;;;;;;OAQG;IACH,YAAY,CAAC,EAAE,EAAE,CAAC;IAUlB;;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,OAAO;CAaR"}
@@ -84,6 +84,12 @@ export declare abstract class AppObjectRepo extends ObservableEntity {
84
84
  * @param {AppObjectComponent} component - The component to register as a singleton
85
85
  */
86
86
  abstract registerSingleton(component: AppObjectComponent): void;
87
+ /**
88
+ * Unregisters a singleton component from the repository.
89
+ *
90
+ * @param {string} type - The type of the singleton to unregister
91
+ */
92
+ abstract unregisterSingleton(type: string): void;
87
93
  /**
88
94
  * Checks if a singleton component of the specified type exists.
89
95
  *
@@ -1 +1 @@
1
- {"version":3,"file":"AppObjectRepo.d.ts","sourceRoot":"","sources":["../../../src/AppObject/AppObjectRepo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAgB,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAiB,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;;;;;;GAQG;AACH,8BAAsB,aAAc,SAAQ,gBAAgB;IAC1D;;;;;OAKG;IACH,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO;IAE1C;;;;OAIG;IACH,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAExC;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAE1C;;;;;OAKG;IACH,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;IAExD;;;;;OAKG;IACH,QAAQ,CAAC,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS;IAEpD;;;;OAIG;IACH,QAAQ,CAAC,MAAM,IAAI,SAAS,EAAE;IAE9B;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAEzD;;;;;OAKG;IACH,QAAQ,CAAC,aAAa,CAAC,MAAM,EAAE,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EAAE,CACxC,QAAQ,EAAE,CAAC,WAAW,EAAE,SAAS,KAAK,IAAI,KACvC,IAAI,CAAC;CACX;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,aAAa,CAEjD"}
@@ -0,0 +1,31 @@
1
+ import { AppObject } from "./AppObject";
2
+ import { AppObjectEntity } from "./AppObjectEntity";
3
+ /**
4
+ * Singleton entity component that manages application state
5
+ *
6
+ * AppObjectSingletonEntity extends AppObjectEntity and automatically registers itself
7
+ * as a singleton in the AppObjectRepo upon construction. This ensures only one instance
8
+ * of this entity type exists across the entire application.
9
+ *
10
+ * Use this class when you need an entity that should have only one instance globally,
11
+ * such as application-wide configuration or shared state managers.
12
+ */
13
+ export declare class AppObjectSingletonEntity extends AppObjectEntity {
14
+ /**
15
+ * Creates a new singleton entity component and attaches it to the specified AppObject
16
+ * Automatically registers itself as a singleton in the AppObjectRepo
17
+ *
18
+ * @param appObject The parent AppObject this component will be attached to
19
+ * @param type The unique type identifier for this component
20
+ */
21
+ constructor(appObject: AppObject, type: string);
22
+ /**
23
+ * Cleans up resources and unregisters the singleton
24
+ *
25
+ * This method:
26
+ * 1. Unregisters itself from the singleton registry
27
+ * 2. Calls the parent class dispose method
28
+ */
29
+ dispose(): void;
30
+ }
31
+ //# sourceMappingURL=AppObjectSingletonEntity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AppObjectSingletonEntity.d.ts","sourceRoot":"","sources":["../../../src/AppObject/AppObjectSingletonEntity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;;;;;;GASG;AACH,qBAAa,wBAAyB,SAAQ,eAAe;IAC3D;;;;;;OAMG;gBACS,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM;IAM9C;;;;;;OAMG;IACH,OAAO;CAIR"}
@@ -0,0 +1,46 @@
1
+ import { AppObject } from "./AppObject";
2
+ import { AppObjectEntity } from "./AppObjectEntity";
3
+ import { AppObjectEntityRepo } from "./AppObjectEntityRepo";
4
+ /**
5
+ * A singleton repository for managing collections of AppObjectEntity instances.
6
+ *
7
+ * This generic class extends AppObjectEntityRepo and automatically registers itself
8
+ * as a singleton in the AppObjectRepo upon construction. This ensures only one instance
9
+ * of this repository type exists across the entire application.
10
+ *
11
+ * Use this class when you need a centralized repository that should have only one instance
12
+ * globally, such as application-wide entity collections or shared resource managers.
13
+ *
14
+ * @template T - The type of entities managed by this repository, must extend AppObjectEntity
15
+ * @extends AppObjectEntityRepo
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * // Create a singleton repository for player entities
20
+ * class PlayerRepo extends AppObjectSingletonEntityRepo<PlayerEntity> {
21
+ * static type = "playerRepo";
22
+ * constructor(appObject: AppObject) {
23
+ * super(appObject, PlayerRepo.type);
24
+ * }
25
+ * }
26
+ * ```
27
+ */
28
+ export declare class AppObjectSingletonEntityRepo<T extends AppObjectEntity> extends AppObjectEntityRepo<T> {
29
+ /**
30
+ * Creates a new singleton entity repository component and attaches it to the specified AppObject
31
+ * Automatically registers itself as a singleton in the AppObjectRepo
32
+ *
33
+ * @param appObject The parent AppObject this component will be attached to
34
+ * @param type The unique type identifier for this component
35
+ */
36
+ constructor(appObject: AppObject, type: string);
37
+ /**
38
+ * Cleans up resources and unregisters the singleton
39
+ *
40
+ * This method:
41
+ * 1. Unregisters itself from the singleton registry
42
+ * 2. Calls the parent class dispose method
43
+ */
44
+ dispose(): void;
45
+ }
46
+ //# sourceMappingURL=AppObjectSingletonEntityRepo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AppObjectSingletonEntityRepo.d.ts","sourceRoot":"","sources":["../../../src/AppObject/AppObjectSingletonEntityRepo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,4BAA4B,CACvC,CAAC,SAAS,eAAe,CACzB,SAAQ,mBAAmB,CAAC,CAAC,CAAC;IAC9B;;;;;;OAMG;gBACS,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM;IAM9C;;;;;;OAMG;IACH,OAAO;CAIR"}