@vived/core 1.4.3 → 1.4.5

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 (152) hide show
  1. package/README.md +25 -1
  2. package/dist/cjs/ExampleFeature/Adapters/examplePmAdapter.js +64 -0
  3. package/dist/cjs/ExampleFeature/Adapters/examplePmAdapter.js.map +1 -0
  4. package/dist/cjs/ExampleFeature/Adapters/exampleSingletonPmAdapter.js +60 -0
  5. package/dist/cjs/ExampleFeature/Adapters/exampleSingletonPmAdapter.js.map +1 -0
  6. package/dist/cjs/ExampleFeature/Adapters/index.js +19 -0
  7. package/dist/cjs/ExampleFeature/Adapters/index.js.map +1 -0
  8. package/dist/cjs/ExampleFeature/Controllers/index.js +19 -0
  9. package/dist/cjs/ExampleFeature/Controllers/index.js.map +1 -0
  10. package/dist/cjs/ExampleFeature/Controllers/setExampleText.js +48 -0
  11. package/dist/cjs/ExampleFeature/Controllers/setExampleText.js.map +1 -0
  12. package/dist/cjs/ExampleFeature/Controllers/toggleExampleBoolean.js +47 -0
  13. package/dist/cjs/ExampleFeature/Controllers/toggleExampleBoolean.js.map +1 -0
  14. package/dist/cjs/ExampleFeature/Entities/ExampleEntity.js +90 -0
  15. package/dist/cjs/ExampleFeature/Entities/ExampleEntity.js.map +1 -0
  16. package/dist/cjs/ExampleFeature/Entities/ExampleRepo.js +113 -0
  17. package/dist/cjs/ExampleFeature/Entities/ExampleRepo.js.map +1 -0
  18. package/dist/cjs/ExampleFeature/Entities/ExampleSingletonEntity.js +69 -0
  19. package/dist/cjs/ExampleFeature/Entities/ExampleSingletonEntity.js.map +1 -0
  20. package/dist/cjs/ExampleFeature/Entities/index.js +20 -0
  21. package/dist/cjs/ExampleFeature/Entities/index.js.map +1 -0
  22. package/dist/cjs/ExampleFeature/Factory/index.js +18 -0
  23. package/dist/cjs/ExampleFeature/Factory/index.js.map +1 -0
  24. package/dist/cjs/ExampleFeature/Factory/setupExampleFeature.js +29 -0
  25. package/dist/cjs/ExampleFeature/Factory/setupExampleFeature.js.map +1 -0
  26. package/dist/cjs/ExampleFeature/Mocks/MockEditExampleStringUC.js +47 -0
  27. package/dist/cjs/ExampleFeature/Mocks/MockEditExampleStringUC.js.map +1 -0
  28. package/dist/cjs/ExampleFeature/Mocks/MockExamplePM.js +48 -0
  29. package/dist/cjs/ExampleFeature/Mocks/MockExamplePM.js.map +1 -0
  30. package/dist/cjs/ExampleFeature/Mocks/MockExampleSingletonPM.js +59 -0
  31. package/dist/cjs/ExampleFeature/Mocks/MockExampleSingletonPM.js.map +1 -0
  32. package/dist/cjs/ExampleFeature/Mocks/MockToggleExampleBooleanUC.js +57 -0
  33. package/dist/cjs/ExampleFeature/Mocks/MockToggleExampleBooleanUC.js.map +1 -0
  34. package/dist/cjs/ExampleFeature/Mocks/index.js +21 -0
  35. package/dist/cjs/ExampleFeature/Mocks/index.js.map +1 -0
  36. package/dist/cjs/ExampleFeature/PMs/ExamplePM.js +97 -0
  37. package/dist/cjs/ExampleFeature/PMs/ExamplePM.js.map +1 -0
  38. package/dist/cjs/ExampleFeature/PMs/ExampleSingletonPM.js +102 -0
  39. package/dist/cjs/ExampleFeature/PMs/ExampleSingletonPM.js.map +1 -0
  40. package/dist/cjs/ExampleFeature/PMs/index.js +19 -0
  41. package/dist/cjs/ExampleFeature/PMs/index.js.map +1 -0
  42. package/dist/cjs/ExampleFeature/UCs/EditExampleStringUC.js +87 -0
  43. package/dist/cjs/ExampleFeature/UCs/EditExampleStringUC.js.map +1 -0
  44. package/dist/cjs/ExampleFeature/UCs/ToggleExampleBooleanUC.js +79 -0
  45. package/dist/cjs/ExampleFeature/UCs/ToggleExampleBooleanUC.js.map +1 -0
  46. package/dist/cjs/ExampleFeature/UCs/index.js +19 -0
  47. package/dist/cjs/ExampleFeature/UCs/index.js.map +1 -0
  48. package/dist/cjs/ExampleFeature/index.js +24 -0
  49. package/dist/cjs/ExampleFeature/index.js.map +1 -0
  50. package/dist/cjs/index.js +1 -0
  51. package/dist/cjs/index.js.map +1 -1
  52. package/dist/esm/ExampleFeature/Adapters/examplePmAdapter.js +61 -0
  53. package/dist/esm/ExampleFeature/Adapters/examplePmAdapter.js.map +1 -0
  54. package/dist/esm/ExampleFeature/Adapters/exampleSingletonPmAdapter.js +57 -0
  55. package/dist/esm/ExampleFeature/Adapters/exampleSingletonPmAdapter.js.map +1 -0
  56. package/dist/esm/ExampleFeature/Adapters/index.js +3 -0
  57. package/dist/esm/ExampleFeature/Adapters/index.js.map +1 -0
  58. package/dist/esm/ExampleFeature/Controllers/index.js +3 -0
  59. package/dist/esm/ExampleFeature/Controllers/index.js.map +1 -0
  60. package/dist/esm/ExampleFeature/Controllers/setExampleText.js +45 -0
  61. package/dist/esm/ExampleFeature/Controllers/setExampleText.js.map +1 -0
  62. package/dist/esm/ExampleFeature/Controllers/toggleExampleBoolean.js +44 -0
  63. package/dist/esm/ExampleFeature/Controllers/toggleExampleBoolean.js.map +1 -0
  64. package/dist/esm/ExampleFeature/Entities/ExampleEntity.js +85 -0
  65. package/dist/esm/ExampleFeature/Entities/ExampleEntity.js.map +1 -0
  66. package/dist/esm/ExampleFeature/Entities/ExampleRepo.js +108 -0
  67. package/dist/esm/ExampleFeature/Entities/ExampleRepo.js.map +1 -0
  68. package/dist/esm/ExampleFeature/Entities/ExampleSingletonEntity.js +64 -0
  69. package/dist/esm/ExampleFeature/Entities/ExampleSingletonEntity.js.map +1 -0
  70. package/dist/esm/ExampleFeature/Entities/index.js +4 -0
  71. package/dist/esm/ExampleFeature/Entities/index.js.map +1 -0
  72. package/dist/esm/ExampleFeature/Factory/index.js +2 -0
  73. package/dist/esm/ExampleFeature/Factory/index.js.map +1 -0
  74. package/dist/esm/ExampleFeature/Factory/setupExampleFeature.js +26 -0
  75. package/dist/esm/ExampleFeature/Factory/setupExampleFeature.js.map +1 -0
  76. package/dist/esm/ExampleFeature/Mocks/MockEditExampleStringUC.js +43 -0
  77. package/dist/esm/ExampleFeature/Mocks/MockEditExampleStringUC.js.map +1 -0
  78. package/dist/esm/ExampleFeature/Mocks/MockExamplePM.js +44 -0
  79. package/dist/esm/ExampleFeature/Mocks/MockExamplePM.js.map +1 -0
  80. package/dist/esm/ExampleFeature/Mocks/MockExampleSingletonPM.js +54 -0
  81. package/dist/esm/ExampleFeature/Mocks/MockExampleSingletonPM.js.map +1 -0
  82. package/dist/esm/ExampleFeature/Mocks/MockToggleExampleBooleanUC.js +52 -0
  83. package/dist/esm/ExampleFeature/Mocks/MockToggleExampleBooleanUC.js.map +1 -0
  84. package/dist/esm/ExampleFeature/Mocks/index.js +5 -0
  85. package/dist/esm/ExampleFeature/Mocks/index.js.map +1 -0
  86. package/dist/esm/ExampleFeature/PMs/ExamplePM.js +92 -0
  87. package/dist/esm/ExampleFeature/PMs/ExamplePM.js.map +1 -0
  88. package/dist/esm/ExampleFeature/PMs/ExampleSingletonPM.js +97 -0
  89. package/dist/esm/ExampleFeature/PMs/ExampleSingletonPM.js.map +1 -0
  90. package/dist/esm/ExampleFeature/PMs/index.js +3 -0
  91. package/dist/esm/ExampleFeature/PMs/index.js.map +1 -0
  92. package/dist/esm/ExampleFeature/UCs/EditExampleStringUC.js +82 -0
  93. package/dist/esm/ExampleFeature/UCs/EditExampleStringUC.js.map +1 -0
  94. package/dist/esm/ExampleFeature/UCs/ToggleExampleBooleanUC.js +74 -0
  95. package/dist/esm/ExampleFeature/UCs/ToggleExampleBooleanUC.js.map +1 -0
  96. package/dist/esm/ExampleFeature/UCs/index.js +3 -0
  97. package/dist/esm/ExampleFeature/UCs/index.js.map +1 -0
  98. package/dist/esm/ExampleFeature/index.js +8 -0
  99. package/dist/esm/ExampleFeature/index.js.map +1 -0
  100. package/dist/esm/index.js +1 -0
  101. package/dist/esm/index.js.map +1 -1
  102. package/dist/types/ExampleFeature/Adapters/examplePmAdapter.d.ts +29 -0
  103. package/dist/types/ExampleFeature/Adapters/examplePmAdapter.d.ts.map +1 -0
  104. package/dist/types/ExampleFeature/Adapters/exampleSingletonPmAdapter.d.ts +31 -0
  105. package/dist/types/ExampleFeature/Adapters/exampleSingletonPmAdapter.d.ts.map +1 -0
  106. package/dist/types/ExampleFeature/Adapters/index.d.ts +3 -0
  107. package/dist/types/ExampleFeature/Adapters/index.d.ts.map +1 -0
  108. package/dist/types/ExampleFeature/Controllers/index.d.ts +3 -0
  109. package/dist/types/ExampleFeature/Controllers/index.d.ts.map +1 -0
  110. package/dist/types/ExampleFeature/Controllers/setExampleText.d.ts +35 -0
  111. package/dist/types/ExampleFeature/Controllers/setExampleText.d.ts.map +1 -0
  112. package/dist/types/ExampleFeature/Controllers/toggleExampleBoolean.d.ts +34 -0
  113. package/dist/types/ExampleFeature/Controllers/toggleExampleBoolean.d.ts.map +1 -0
  114. package/dist/types/ExampleFeature/Entities/ExampleEntity.d.ts +55 -0
  115. package/dist/types/ExampleFeature/Entities/ExampleEntity.d.ts.map +1 -0
  116. package/dist/types/ExampleFeature/Entities/ExampleRepo.d.ts +62 -0
  117. package/dist/types/ExampleFeature/Entities/ExampleRepo.d.ts.map +1 -0
  118. package/dist/types/ExampleFeature/Entities/ExampleSingletonEntity.d.ts +43 -0
  119. package/dist/types/ExampleFeature/Entities/ExampleSingletonEntity.d.ts.map +1 -0
  120. package/dist/types/ExampleFeature/Entities/index.d.ts +4 -0
  121. package/dist/types/ExampleFeature/Entities/index.d.ts.map +1 -0
  122. package/dist/types/ExampleFeature/Factory/index.d.ts +2 -0
  123. package/dist/types/ExampleFeature/Factory/index.d.ts.map +1 -0
  124. package/dist/types/ExampleFeature/Factory/setupExampleFeature.d.ts +17 -0
  125. package/dist/types/ExampleFeature/Factory/setupExampleFeature.d.ts.map +1 -0
  126. package/dist/types/ExampleFeature/Mocks/MockEditExampleStringUC.d.ts +42 -0
  127. package/dist/types/ExampleFeature/Mocks/MockEditExampleStringUC.d.ts.map +1 -0
  128. package/dist/types/ExampleFeature/Mocks/MockExamplePM.d.ts +41 -0
  129. package/dist/types/ExampleFeature/Mocks/MockExamplePM.d.ts.map +1 -0
  130. package/dist/types/ExampleFeature/Mocks/MockExampleSingletonPM.d.ts +49 -0
  131. package/dist/types/ExampleFeature/Mocks/MockExampleSingletonPM.d.ts.map +1 -0
  132. package/dist/types/ExampleFeature/Mocks/MockToggleExampleBooleanUC.d.ts +47 -0
  133. package/dist/types/ExampleFeature/Mocks/MockToggleExampleBooleanUC.d.ts.map +1 -0
  134. package/dist/types/ExampleFeature/Mocks/index.d.ts +5 -0
  135. package/dist/types/ExampleFeature/Mocks/index.d.ts.map +1 -0
  136. package/dist/types/ExampleFeature/PMs/ExamplePM.d.ts +42 -0
  137. package/dist/types/ExampleFeature/PMs/ExamplePM.d.ts.map +1 -0
  138. package/dist/types/ExampleFeature/PMs/ExampleSingletonPM.d.ts +52 -0
  139. package/dist/types/ExampleFeature/PMs/ExampleSingletonPM.d.ts.map +1 -0
  140. package/dist/types/ExampleFeature/PMs/index.d.ts +3 -0
  141. package/dist/types/ExampleFeature/PMs/index.d.ts.map +1 -0
  142. package/dist/types/ExampleFeature/UCs/EditExampleStringUC.d.ts +52 -0
  143. package/dist/types/ExampleFeature/UCs/EditExampleStringUC.d.ts.map +1 -0
  144. package/dist/types/ExampleFeature/UCs/ToggleExampleBooleanUC.d.ts +44 -0
  145. package/dist/types/ExampleFeature/UCs/ToggleExampleBooleanUC.d.ts.map +1 -0
  146. package/dist/types/ExampleFeature/UCs/index.d.ts +3 -0
  147. package/dist/types/ExampleFeature/UCs/index.d.ts.map +1 -0
  148. package/dist/types/ExampleFeature/index.d.ts +8 -0
  149. package/dist/types/ExampleFeature/index.d.ts.map +1 -0
  150. package/dist/types/index.d.ts +1 -0
  151. package/dist/types/index.d.ts.map +1 -1
  152. package/package.json +6 -4
package/README.md CHANGED
@@ -55,7 +55,29 @@ The architecture implements a clean separation of concerns through specialized c
55
55
  - UI representation components
56
56
  - Consumes view models and renders UI
57
57
 
58
- ## Example Usage
58
+ ## Example Implementation
59
+
60
+ The package includes a fully implemented `ExampleFeature` that demonstrates the App Object Component architecture. This example demonstrates how to structure your code following the recommended patterns:
61
+
62
+ ### Directory Structure
63
+ - **Entities/** - Domain models for storing and managing state
64
+ - **PMs/** - Presentation Managers that transform data for UI consumption
65
+ - **UCs/** - Use Cases that implement business logic operations
66
+ - **Controllers/** - Simplified API for UI interaction
67
+ - **Adapters/** - Connect UI frameworks to PMs
68
+ - **Mocks/** - Test doubles for unit testing
69
+
70
+ ### Implementation Patterns
71
+ The example demonstrates:
72
+ - Observable entities with memoized properties
73
+ - Presentation managers with view model transformation
74
+ - Use cases that implement business logic
75
+ - Controllers that provide a simple UI-friendly API
76
+ - Component registration and retrieval
77
+ - Singleton component access
78
+ - Test patterns for each component type
79
+
80
+ ### Sample Usage
59
81
 
60
82
  ```typescript
61
83
  // Create a repository and an app object
@@ -93,6 +115,8 @@ class MyPM extends AppObjectPM<{value: number}> {
93
115
  // The architecture enables clean, testable, and maintainable code
94
116
  ```
95
117
 
118
+ Refer to the `ExampleFeature` directory for a complete implementation example that shows the interaction between all component types.
119
+
96
120
  ## Value Objects
97
121
 
98
122
  The package provides immutable value objects for mathematical and graphical operations:
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ /**
3
+ * examplePmAdapter.ts
4
+ *
5
+ * This file demonstrates how to implement a PM Adapter to connect UI components to PMs.
6
+ * PM Adapters provide a standardized way for UI frameworks to subscribe to PM updates.
7
+ * This adapter connects to regular (non-singleton) PMs that require an AppObject ID.
8
+ *
9
+ * Key concepts:
10
+ * - PM Adapters implement the PmAdapter<VM> interface where VM is the view model type
11
+ * - They handle subscribing UI components to PMs and unsubscribing when done
12
+ * - They provide a default view model for initial rendering before data is available
13
+ * - They abstract away the details of finding and connecting to specific PMs
14
+ *
15
+ * Usage pattern (React example):
16
+ * ```typescript
17
+ * // In a React component
18
+ * function MyComponent({ id }) {
19
+ * const viewModel = usePmAdapter(examplePmAdapter, id);
20
+ * return <div>{viewModel}</div>;
21
+ * }
22
+ * ```
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.examplePmAdapter = void 0;
26
+ const ExamplePM_1 = require("../PMs/ExamplePM");
27
+ /**
28
+ * An adapter that connects UI components to ExamplePM instances.
29
+ * Implements PmAdapter<string> because ExamplePM provides string view models.
30
+ */
31
+ exports.examplePmAdapter = {
32
+ // Default view model to use before data is available
33
+ defaultVM: "",
34
+ /**
35
+ * Subscribes a UI component to updates from an ExamplePM
36
+ * @param id The ID of the AppObject containing the PM
37
+ * @param appObjects The application's AppObjectRepo
38
+ * @param setVM Callback function that updates the UI component
39
+ */
40
+ subscribe: (id, appObjects, setVM) => {
41
+ // Return early if no ID is provided
42
+ if (!id)
43
+ return;
44
+ // Find the PM using the provided ID
45
+ const pm = ExamplePM_1.ExamplePM.getById(id, appObjects);
46
+ if (!pm) {
47
+ appObjects.submitWarning("examplePmAdapter", "Unable to find ExamplePM");
48
+ return;
49
+ }
50
+ // Register the UI component's callback to receive updates
51
+ pm.addView(setVM);
52
+ },
53
+ /**
54
+ * Unsubscribes a UI component from updates when it's no longer needed
55
+ * @param id The ID of the AppObject containing the PM
56
+ * @param appObjects The application's AppObjectRepo
57
+ * @param setVM The same callback function that was used to subscribe
58
+ */
59
+ unsubscribe: (id, appObjects, setVM) => {
60
+ // Find the PM and remove the view if it exists
61
+ ExamplePM_1.ExamplePM.getById(id, appObjects)?.removeView(setVM);
62
+ }
63
+ };
64
+ //# sourceMappingURL=examplePmAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"examplePmAdapter.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Adapters/examplePmAdapter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;AAIH,gDAA6C;AAE7C;;;GAGG;AACU,QAAA,gBAAgB,GAAsB;IACjD,qDAAqD;IACrD,SAAS,EAAE,EAAE;IAEb;;;;;OAKG;IACH,SAAS,EAAE,CACT,EAAU,EACV,UAAyB,EACzB,KAA2B,EAC3B,EAAE;QACF,oCAAoC;QACpC,IAAI,CAAC,EAAE;YAAE,OAAO;QAEhB,oCAAoC;QACpC,MAAM,EAAE,GAAG,qBAAS,CAAC,OAAO,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC;QAC7C,IAAI,CAAC,EAAE,EAAE,CAAC;YACR,UAAU,CAAC,aAAa,CAAC,kBAAkB,EAAE,0BAA0B,CAAC,CAAC;YACzE,OAAO;QACT,CAAC;QAED,0DAA0D;QAC1D,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED;;;;;OAKG;IACH,WAAW,EAAE,CACX,EAAU,EACV,UAAyB,EACzB,KAA2B,EAC3B,EAAE;QACF,+CAA+C;QAC/C,qBAAS,CAAC,OAAO,CAAC,EAAE,EAAE,UAAU,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;IACvD,CAAC;CACF,CAAC","sourcesContent":["/**\r\n * examplePmAdapter.ts\r\n * \r\n * This file demonstrates how to implement a PM Adapter to connect UI components to PMs.\r\n * PM Adapters provide a standardized way for UI frameworks to subscribe to PM updates.\r\n * This adapter connects to regular (non-singleton) PMs that require an AppObject ID.\r\n * \r\n * Key concepts:\r\n * - PM Adapters implement the PmAdapter<VM> interface where VM is the view model type\r\n * - They handle subscribing UI components to PMs and unsubscribing when done\r\n * - They provide a default view model for initial rendering before data is available\r\n * - They abstract away the details of finding and connecting to specific PMs\r\n * \r\n * Usage pattern (React example):\r\n * ```typescript\r\n * // In a React component\r\n * function MyComponent({ id }) {\r\n * const viewModel = usePmAdapter(examplePmAdapter, id);\r\n * return <div>{viewModel}</div>;\r\n * }\r\n * ```\r\n */\r\n\r\nimport { AppObjectRepo } from \"../../AppObject\";\r\nimport { PmAdapter } from \"../../Types/PmAdapter\";\r\nimport { ExamplePM } from \"../PMs/ExamplePM\";\r\n\r\n/**\r\n * An adapter that connects UI components to ExamplePM instances.\r\n * Implements PmAdapter<string> because ExamplePM provides string view models.\r\n */\r\nexport const examplePmAdapter: PmAdapter<string> = {\r\n // Default view model to use before data is available\r\n defaultVM: \"\",\r\n \r\n /**\r\n * Subscribes a UI component to updates from an ExamplePM\r\n * @param id The ID of the AppObject containing the PM\r\n * @param appObjects The application's AppObjectRepo\r\n * @param setVM Callback function that updates the UI component\r\n */\r\n subscribe: (\r\n id: string,\r\n appObjects: AppObjectRepo,\r\n setVM: (vm: string) => void\r\n ) => {\r\n // Return early if no ID is provided\r\n if (!id) return;\r\n\r\n // Find the PM using the provided ID\r\n const pm = ExamplePM.getById(id, appObjects);\r\n if (!pm) {\r\n appObjects.submitWarning(\"examplePmAdapter\", \"Unable to find ExamplePM\");\r\n return;\r\n }\r\n \r\n // Register the UI component's callback to receive updates\r\n pm.addView(setVM);\r\n },\r\n \r\n /**\r\n * Unsubscribes a UI component from updates when it's no longer needed\r\n * @param id The ID of the AppObject containing the PM\r\n * @param appObjects The application's AppObjectRepo\r\n * @param setVM The same callback function that was used to subscribe\r\n */\r\n unsubscribe: (\r\n id: string,\r\n appObjects: AppObjectRepo,\r\n setVM: (vm: string) => void\r\n ) => {\r\n // Find the PM and remove the view if it exists\r\n ExamplePM.getById(id, appObjects)?.removeView(setVM);\r\n }\r\n};\r\n"]}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ /**
3
+ * exampleSingletonPmAdapter.ts
4
+ *
5
+ * This file demonstrates how to implement a Singleton PM Adapter to connect UI components
6
+ * to singleton PMs. Singleton PM Adapters provide a standardized way for UI frameworks
7
+ * to subscribe to singleton PM updates without needing to specify an AppObject ID.
8
+ *
9
+ * Key concepts:
10
+ * - Singleton PM Adapters implement the SingletonPmAdapter<VM> interface
11
+ * - They handle subscribing UI components to singleton PMs and unsubscribing when done
12
+ * - They provide a default view model for initial rendering before data is available
13
+ * - They don't require an AppObject ID since they connect to globally accessible singletons
14
+ *
15
+ * Usage pattern (React example):
16
+ * ```typescript
17
+ * // In a React component
18
+ * function MyComponent() {
19
+ * // Note: no ID needed since it's connecting to a singleton
20
+ * const viewModel = useSingletonPmAdapter(exampleSingletonPmAdapter);
21
+ * return <div>{viewModel.aBoolProperty ? "True" : "False"}</div>;
22
+ * }
23
+ * ```
24
+ */
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.exampleSingletonPmAdapter = void 0;
27
+ const ExampleSingletonPM_1 = require("../PMs/ExampleSingletonPM");
28
+ /**
29
+ * An adapter that connects UI components to the ExampleSingletonPM.
30
+ * Implements SingletonPmAdapter<ExampleVM> because ExampleSingletonPM provides ExampleVM view models.
31
+ */
32
+ exports.exampleSingletonPmAdapter = {
33
+ // Default view model to use before data is available
34
+ defaultVM: ExampleSingletonPM_1.defaultSlideNavigationVM,
35
+ /**
36
+ * Subscribes a UI component to updates from the ExampleSingletonPM
37
+ * @param appObjects The application's AppObjectRepo
38
+ * @param setVM Callback function that updates the UI component
39
+ */
40
+ subscribe: (appObjects, setVM) => {
41
+ // Find the singleton PM using its static get method
42
+ const pm = ExampleSingletonPM_1.ExampleSingletonPM.get(appObjects);
43
+ if (!pm) {
44
+ appObjects.submitWarning("exampleSingletonPmAdapter", "Unable to find ExampleSingletonPM");
45
+ return;
46
+ }
47
+ // Register the UI component's callback to receive updates
48
+ pm.addView(setVM);
49
+ },
50
+ /**
51
+ * Unsubscribes a UI component from updates when it's no longer needed
52
+ * @param appObjects The application's AppObjectRepo
53
+ * @param setVM The same callback function that was used to subscribe
54
+ */
55
+ unsubscribe: (appObjects, setVM) => {
56
+ // Find the singleton PM and remove the view if it exists
57
+ ExampleSingletonPM_1.ExampleSingletonPM.get(appObjects)?.removeView(setVM);
58
+ }
59
+ };
60
+ //# sourceMappingURL=exampleSingletonPmAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exampleSingletonPmAdapter.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Adapters/exampleSingletonPmAdapter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAIH,kEAImC;AAEnC;;;GAGG;AACU,QAAA,yBAAyB,GAAkC;IACtE,qDAAqD;IACrD,SAAS,EAAE,6CAAwB;IAEnC;;;;OAIG;IACH,SAAS,EAAE,CAAC,UAAyB,EAAE,KAA8B,EAAE,EAAE;QACvE,oDAAoD;QACpD,MAAM,EAAE,GAAG,uCAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC9C,IAAI,CAAC,EAAE,EAAE,CAAC;YACR,UAAU,CAAC,aAAa,CACtB,2BAA2B,EAC3B,mCAAmC,CACpC,CAAC;YACF,OAAO;QACT,CAAC;QAED,0DAA0D;QAC1D,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED;;;;OAIG;IACH,WAAW,EAAE,CAAC,UAAyB,EAAE,KAA8B,EAAE,EAAE;QACzE,yDAAyD;QACzD,uCAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;IACxD,CAAC;CACF,CAAC","sourcesContent":["/**\r\n * exampleSingletonPmAdapter.ts\r\n * \r\n * This file demonstrates how to implement a Singleton PM Adapter to connect UI components\r\n * to singleton PMs. Singleton PM Adapters provide a standardized way for UI frameworks\r\n * to subscribe to singleton PM updates without needing to specify an AppObject ID.\r\n * \r\n * Key concepts:\r\n * - Singleton PM Adapters implement the SingletonPmAdapter<VM> interface\r\n * - They handle subscribing UI components to singleton PMs and unsubscribing when done\r\n * - They provide a default view model for initial rendering before data is available\r\n * - They don't require an AppObject ID since they connect to globally accessible singletons\r\n * \r\n * Usage pattern (React example):\r\n * ```typescript\r\n * // In a React component\r\n * function MyComponent() {\r\n * // Note: no ID needed since it's connecting to a singleton\r\n * const viewModel = useSingletonPmAdapter(exampleSingletonPmAdapter);\r\n * return <div>{viewModel.aBoolProperty ? \"True\" : \"False\"}</div>;\r\n * }\r\n * ```\r\n */\r\n\r\nimport { AppObjectRepo } from \"../../AppObject\";\r\nimport { SingletonPmAdapter } from \"../../Types/SingletonPmAdapter\";\r\nimport {\r\n defaultSlideNavigationVM,\r\n ExampleSingletonPM,\r\n ExampleVM\r\n} from \"../PMs/ExampleSingletonPM\";\r\n\r\n/**\r\n * An adapter that connects UI components to the ExampleSingletonPM.\r\n * Implements SingletonPmAdapter<ExampleVM> because ExampleSingletonPM provides ExampleVM view models.\r\n */\r\nexport const exampleSingletonPmAdapter: SingletonPmAdapter<ExampleVM> = {\r\n // Default view model to use before data is available\r\n defaultVM: defaultSlideNavigationVM,\r\n \r\n /**\r\n * Subscribes a UI component to updates from the ExampleSingletonPM\r\n * @param appObjects The application's AppObjectRepo\r\n * @param setVM Callback function that updates the UI component\r\n */\r\n subscribe: (appObjects: AppObjectRepo, setVM: (vm: ExampleVM) => void) => {\r\n // Find the singleton PM using its static get method\r\n const pm = ExampleSingletonPM.get(appObjects);\r\n if (!pm) {\r\n appObjects.submitWarning(\r\n \"exampleSingletonPmAdapter\",\r\n \"Unable to find ExampleSingletonPM\"\r\n );\r\n return;\r\n }\r\n \r\n // Register the UI component's callback to receive updates\r\n pm.addView(setVM);\r\n },\r\n \r\n /**\r\n * Unsubscribes a UI component from updates when it's no longer needed\r\n * @param appObjects The application's AppObjectRepo\r\n * @param setVM The same callback function that was used to subscribe\r\n */\r\n unsubscribe: (appObjects: AppObjectRepo, setVM: (vm: ExampleVM) => void) => {\r\n // Find the singleton PM and remove the view if it exists\r\n ExampleSingletonPM.get(appObjects)?.removeView(setVM);\r\n }\r\n};\r\n"]}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./examplePmAdapter"), exports);
18
+ __exportStar(require("./exampleSingletonPmAdapter"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Adapters/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,8DAA4C","sourcesContent":["export * from \"./examplePmAdapter\";\r\nexport * from \"./exampleSingletonPmAdapter\";\r\n"]}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./setExampleText"), exports);
18
+ __exportStar(require("./toggleExampleBoolean"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Controllers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,yDAAuC","sourcesContent":["export * from \"./setExampleText\";\r\nexport * from \"./toggleExampleBoolean\";\r\n"]}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ /**
3
+ * setExampleText.ts
4
+ *
5
+ * This file demonstrates how to implement a Controller function.
6
+ * Controllers are simple functions that provide a simplified API for UI components
7
+ * to interact with Use Cases (UCs). They handle the details of finding the right
8
+ * UC and calling its methods with the appropriate parameters.
9
+ *
10
+ * Key concepts:
11
+ * - Controllers are functions that take parameters from UI components
12
+ * - They find the appropriate UC and call its methods
13
+ * - They handle error cases and provide appropriate feedback
14
+ * - They simplify the API for UI components
15
+ *
16
+ * Usage pattern (React example):
17
+ * ```typescript
18
+ * // In a React component
19
+ * function ExampleTextInput({ id, appObjects }) {
20
+ * const handleChange = (e) => {
21
+ * setExampleText(e.target.value, id, appObjects);
22
+ * };
23
+ * return <input onChange={handleChange} />;
24
+ * }
25
+ * ```
26
+ */
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.setExampleText = setExampleText;
29
+ const EditExampleStringUC_1 = require("../UCs/EditExampleStringUC");
30
+ /**
31
+ * Controller function to update the text of an ExampleEntity
32
+ *
33
+ * @param text The new text to set
34
+ * @param id The ID of the AppObject containing the EditExampleStringUC
35
+ * @param appObjects The application's AppObjectRepo
36
+ */
37
+ function setExampleText(text, id, appObjects) {
38
+ // Find the Use Case using the provided ID
39
+ const uc = EditExampleStringUC_1.EditExampleStringUC.getById(id, appObjects);
40
+ // Handle the case where the UC doesn't exist
41
+ if (!uc) {
42
+ appObjects.submitWarning("setExampleText", "Unable to find EditExampleStringUC");
43
+ return;
44
+ }
45
+ // Call the UC method to perform the operation
46
+ uc.editExampleString(text);
47
+ }
48
+ //# sourceMappingURL=setExampleText.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setExampleText.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Controllers/setExampleText.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;AAYH,wCAmBC;AA5BD,oEAAiE;AAEjE;;;;;;GAMG;AACH,SAAgB,cAAc,CAC5B,IAAY,EACZ,EAAU,EACV,UAAyB;IAEzB,0CAA0C;IAC1C,MAAM,EAAE,GAAG,yCAAmB,CAAC,OAAO,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC;IAEvD,6CAA6C;IAC7C,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,UAAU,CAAC,aAAa,CACtB,gBAAgB,EAChB,oCAAoC,CACrC,CAAC;QACF,OAAO;IACT,CAAC;IAED,8CAA8C;IAC9C,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["/**\r\n * setExampleText.ts\r\n * \r\n * This file demonstrates how to implement a Controller function.\r\n * Controllers are simple functions that provide a simplified API for UI components\r\n * to interact with Use Cases (UCs). They handle the details of finding the right\r\n * UC and calling its methods with the appropriate parameters.\r\n * \r\n * Key concepts:\r\n * - Controllers are functions that take parameters from UI components\r\n * - They find the appropriate UC and call its methods\r\n * - They handle error cases and provide appropriate feedback\r\n * - They simplify the API for UI components\r\n * \r\n * Usage pattern (React example):\r\n * ```typescript\r\n * // In a React component\r\n * function ExampleTextInput({ id, appObjects }) {\r\n * const handleChange = (e) => {\r\n * setExampleText(e.target.value, id, appObjects);\r\n * };\r\n * return <input onChange={handleChange} />;\r\n * }\r\n * ```\r\n */\r\n\r\nimport { AppObjectRepo } from \"../../AppObject\";\r\nimport { EditExampleStringUC } from \"../UCs/EditExampleStringUC\";\r\n\r\n/**\r\n * Controller function to update the text of an ExampleEntity\r\n * \r\n * @param text The new text to set\r\n * @param id The ID of the AppObject containing the EditExampleStringUC\r\n * @param appObjects The application's AppObjectRepo\r\n */\r\nexport function setExampleText(\r\n text: string,\r\n id: string,\r\n appObjects: AppObjectRepo\r\n) {\r\n // Find the Use Case using the provided ID\r\n const uc = EditExampleStringUC.getById(id, appObjects);\r\n \r\n // Handle the case where the UC doesn't exist\r\n if (!uc) {\r\n appObjects.submitWarning(\r\n \"setExampleText\",\r\n \"Unable to find EditExampleStringUC\"\r\n );\r\n return;\r\n }\r\n\r\n // Call the UC method to perform the operation\r\n uc.editExampleString(text);\r\n}\r\n"]}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ /**
3
+ * toggleExampleBoolean.ts
4
+ *
5
+ * This file demonstrates how to implement a Controller function for a singleton UC.
6
+ * This controller provides a simplified API for UI components to interact with
7
+ * the ToggleExampleBooleanUC singleton, handling the details of finding the UC
8
+ * and calling its method.
9
+ *
10
+ * Key concepts:
11
+ * - Controllers for singleton UCs don't need an ID parameter
12
+ * - They access the singleton UC using its static get() method
13
+ * - They handle error cases and provide appropriate feedback
14
+ * - They simplify the API for UI components
15
+ *
16
+ * Usage pattern (React example):
17
+ * ```typescript
18
+ * // In a React component
19
+ * function ToggleButton({ appObjects }) {
20
+ * return (
21
+ * <button onClick={() => toggleExampleBoolean(appObjects)}>
22
+ * Toggle
23
+ * </button>
24
+ * );
25
+ * }
26
+ * ```
27
+ */
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.toggleExampleBoolean = toggleExampleBoolean;
30
+ const ToggleExampleBooleanUC_1 = require("../UCs/ToggleExampleBooleanUC");
31
+ /**
32
+ * Controller function to toggle the boolean property of the SingletonEntityExample
33
+ *
34
+ * @param appObjects The application's AppObjectRepo
35
+ */
36
+ function toggleExampleBoolean(appObjects) {
37
+ // Access the singleton UC using its static get method
38
+ const uc = ToggleExampleBooleanUC_1.ToggleExampleBooleanUC.get(appObjects);
39
+ // Handle the case where the UC doesn't exist yet
40
+ if (!uc) {
41
+ appObjects.submitWarning("toggleExampleBoolean", "Unable to find ToggleExampleBooleanUC");
42
+ return;
43
+ }
44
+ // Call the UC method to perform the operation
45
+ uc.toggleExampleBoolean();
46
+ }
47
+ //# sourceMappingURL=toggleExampleBoolean.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toggleExampleBoolean.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Controllers/toggleExampleBoolean.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;AAUH,oDAeC;AAtBD,0EAAuE;AAEvE;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,UAAyB;IAC5D,sDAAsD;IACtD,MAAM,EAAE,GAAG,+CAAsB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAElD,iDAAiD;IACjD,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,UAAU,CAAC,aAAa,CACtB,sBAAsB,EACtB,uCAAuC,CACxC,CAAC;QACF,OAAO;IACT,CAAC;IAED,8CAA8C;IAC9C,EAAE,CAAC,oBAAoB,EAAE,CAAC;AAC5B,CAAC","sourcesContent":["/**\r\n * toggleExampleBoolean.ts\r\n * \r\n * This file demonstrates how to implement a Controller function for a singleton UC.\r\n * This controller provides a simplified API for UI components to interact with \r\n * the ToggleExampleBooleanUC singleton, handling the details of finding the UC\r\n * and calling its method.\r\n * \r\n * Key concepts:\r\n * - Controllers for singleton UCs don't need an ID parameter\r\n * - They access the singleton UC using its static get() method\r\n * - They handle error cases and provide appropriate feedback\r\n * - They simplify the API for UI components\r\n * \r\n * Usage pattern (React example):\r\n * ```typescript\r\n * // In a React component\r\n * function ToggleButton({ appObjects }) {\r\n * return (\r\n * <button onClick={() => toggleExampleBoolean(appObjects)}>\r\n * Toggle\r\n * </button>\r\n * );\r\n * }\r\n * ```\r\n */\r\n\r\nimport { AppObjectRepo } from \"../../AppObject\";\r\nimport { ToggleExampleBooleanUC } from \"../UCs/ToggleExampleBooleanUC\";\r\n\r\n/**\r\n * Controller function to toggle the boolean property of the SingletonEntityExample\r\n * \r\n * @param appObjects The application's AppObjectRepo\r\n */\r\nexport function toggleExampleBoolean(appObjects: AppObjectRepo) {\r\n // Access the singleton UC using its static get method\r\n const uc = ToggleExampleBooleanUC.get(appObjects);\r\n \r\n // Handle the case where the UC doesn't exist yet\r\n if (!uc) {\r\n appObjects.submitWarning(\r\n \"toggleExampleBoolean\",\r\n \"Unable to find ToggleExampleBooleanUC\"\r\n );\r\n return;\r\n }\r\n\r\n // Call the UC method to perform the operation\r\n uc.toggleExampleBoolean();\r\n}\r\n"]}
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ /**
3
+ * ExampleEntity.ts
4
+ *
5
+ * This file demonstrates how to implement a standard (non-singleton) entity in the application.
6
+ * Entities store and manage data, track state changes, and notify observers when changes occur.
7
+ *
8
+ * Key concepts:
9
+ * - Entity classes extend AppObjectEntity
10
+ * - They provide access to data properties
11
+ * - They use Memoized types (MemoizedString, MemoizedBoolean, etc.) to track changes
12
+ * - They notify observers when properties change
13
+ *
14
+ * Usage pattern:
15
+ * 1. Get or create an entity instance using getById, get, or addIfMissing
16
+ * 2. Access or modify properties via getters/setters
17
+ * 3. Register change observers to react to property updates
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.ExampleEntity = void 0;
21
+ exports.makeExampleEntity = makeExampleEntity;
22
+ const AppObject_1 = require("../../AppObject");
23
+ const MemoizedString_1 = require("../../Entities/MemoizedString");
24
+ /**
25
+ * ExampleEntity represents a basic entity with a string property.
26
+ * Abstract class provides the interface and static helper methods.
27
+ */
28
+ class ExampleEntity extends AppObject_1.AppObjectEntity {
29
+ /**
30
+ * Retrieves an ExampleEntity component from an AppObject
31
+ * @param appObj The AppObject to get the component from
32
+ * @returns The ExampleEntity component or undefined if not found
33
+ */
34
+ static get(appObj) {
35
+ return appObj.getComponent(this.type);
36
+ }
37
+ /**
38
+ * Retrieves an ExampleEntity by its parent AppObject's ID
39
+ * @param id The ID of the parent AppObject
40
+ * @param appObjects The AppObjectRepo to search in
41
+ * @returns The ExampleEntity component or undefined if not found
42
+ */
43
+ static getById(id, appObjects) {
44
+ return appObjects.get(id)?.getComponent(this.type);
45
+ }
46
+ /**
47
+ * Ensures an ExampleEntity exists on the AppObject, creating one if needed
48
+ * @param appObj The AppObject to check/add the component to
49
+ * @returns The existing or newly created ExampleEntity
50
+ */
51
+ static addIfMissing(appObj) {
52
+ const existing = appObj.getComponent(this.type);
53
+ if (existing) {
54
+ return existing;
55
+ }
56
+ else {
57
+ return makeExampleEntity(appObj);
58
+ }
59
+ }
60
+ }
61
+ exports.ExampleEntity = ExampleEntity;
62
+ /** Unique type identifier for this component */
63
+ ExampleEntity.type = "ExampleEntityType";
64
+ /**
65
+ * Factory function to create a new ExampleEntity
66
+ * @param appObject The AppObject to attach the entity to
67
+ * @returns A new ExampleEntity instance
68
+ */
69
+ function makeExampleEntity(appObject) {
70
+ return new ExampleEntityImp(appObject);
71
+ }
72
+ /**
73
+ * Concrete implementation of ExampleEntity
74
+ * This private class handles the actual implementation details
75
+ */
76
+ class ExampleEntityImp extends ExampleEntity {
77
+ // Property accessors that use the memoized value
78
+ get aStringProperty() {
79
+ return this.memoizedIsAuthoring.val;
80
+ }
81
+ set aStringProperty(val) {
82
+ this.memoizedIsAuthoring.val = val;
83
+ }
84
+ constructor(appObject) {
85
+ super(appObject, ExampleEntity.type);
86
+ // MemoizedString tracks changes to the string value and calls notifyOnChange when updated
87
+ this.memoizedIsAuthoring = new MemoizedString_1.MemoizedString("", this.notifyOnChange);
88
+ }
89
+ }
90
+ //# sourceMappingURL=ExampleEntity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExampleEntity.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Entities/ExampleEntity.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AA+DH,8CAIC;AAjED,+CAIyB;AACzB,kEAA+D;AAE/D;;;GAGG;AACH,MAAsB,aAAc,SAAQ,2BAAe;IAQzD;;;;OAIG;IACH,MAAM,CAAC,GAAG,CAAC,MAAiB;QAC1B,OAAO,MAAM,CAAC,YAAY,CAAgB,IAAI,CAAC,IAAI,CAAC,CAAC;IACvD,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CACZ,EAAU,EACV,UAAyB;QAEzB,OAAO,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,YAAY,CAAgB,IAAI,CAAC,IAAI,CAAC,CAAC;IACpE,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,YAAY,CAAC,MAAiB;QACnC,MAAM,QAAQ,GAAG,MAAM,CAAC,YAAY,CAAgB,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/D,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC;QAClB,CAAC;aAAM,CAAC;YACN,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;;AA1CH,sCA2CC;AA1CC,gDAAgD;AAChC,kBAAI,GAAG,mBAAmB,CAAC;AA2C7C;;;;GAIG;AACH,SAAgB,iBAAiB,CAC/B,SAAoB;IAEpB,OAAO,IAAI,gBAAgB,CAAC,SAAS,CAAC,CAAC;AACzC,CAAC;AAED;;;GAGG;AACH,MAAM,gBAAiB,SAAQ,aAAa;IAI1C,iDAAiD;IACjD,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC;IACtC,CAAC;IAED,IAAI,eAAe,CAAC,GAAW;QAC7B,IAAI,CAAC,mBAAmB,CAAC,GAAG,GAAG,GAAG,CAAC;IACrC,CAAC;IAED,YAAY,SAAoB;QAC9B,KAAK,CAAC,SAAS,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC;QAbvC,0FAA0F;QAClF,wBAAmB,GAAG,IAAI,+BAAc,CAAC,EAAE,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;IAa1E,CAAC;CACF","sourcesContent":["/**\r\n * ExampleEntity.ts\r\n * \r\n * This file demonstrates how to implement a standard (non-singleton) entity in the application.\r\n * Entities store and manage data, track state changes, and notify observers when changes occur.\r\n * \r\n * Key concepts:\r\n * - Entity classes extend AppObjectEntity\r\n * - They provide access to data properties\r\n * - They use Memoized types (MemoizedString, MemoizedBoolean, etc.) to track changes\r\n * - They notify observers when properties change\r\n * \r\n * Usage pattern:\r\n * 1. Get or create an entity instance using getById, get, or addIfMissing\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 AppObjectEntity,\r\n AppObjectRepo\r\n} from \"../../AppObject\";\r\nimport { MemoizedString } from \"../../Entities/MemoizedString\";\r\n\r\n/**\r\n * ExampleEntity represents a basic entity with a string property.\r\n * Abstract class provides the interface and static helper methods.\r\n */\r\nexport abstract class ExampleEntity extends AppObjectEntity {\r\n /** Unique type identifier for this component */\r\n static readonly type = \"ExampleEntityType\";\r\n\r\n /** String property accessor methods that must be implemented */\r\n abstract get aStringProperty(): string;\r\n abstract set aStringProperty(val: string);\r\n\r\n /**\r\n * Retrieves an ExampleEntity component from an AppObject\r\n * @param appObj The AppObject to get the component from\r\n * @returns The ExampleEntity component or undefined if not found\r\n */\r\n static get(appObj: AppObject): ExampleEntity | undefined {\r\n return appObj.getComponent<ExampleEntity>(this.type);\r\n }\r\n\r\n /**\r\n * Retrieves an ExampleEntity 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 ExampleEntity component or undefined if not found\r\n */\r\n static getById(\r\n id: string,\r\n appObjects: AppObjectRepo\r\n ): ExampleEntity | undefined {\r\n return appObjects.get(id)?.getComponent<ExampleEntity>(this.type);\r\n }\r\n\r\n /**\r\n * Ensures an ExampleEntity exists on the AppObject, creating one if needed\r\n * @param appObj The AppObject to check/add the component to\r\n * @returns The existing or newly created ExampleEntity\r\n */\r\n static addIfMissing(appObj: AppObject): ExampleEntity {\r\n const existing = appObj.getComponent<ExampleEntity>(this.type);\r\n if (existing) {\r\n return existing;\r\n } else {\r\n return makeExampleEntity(appObj);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Factory function to create a new ExampleEntity\r\n * @param appObject The AppObject to attach the entity to\r\n * @returns A new ExampleEntity instance\r\n */\r\nexport function makeExampleEntity(\r\n appObject: AppObject\r\n): ExampleEntity {\r\n return new ExampleEntityImp(appObject);\r\n}\r\n\r\n/**\r\n * Concrete implementation of ExampleEntity\r\n * This private class handles the actual implementation details\r\n */\r\nclass ExampleEntityImp extends ExampleEntity {\r\n // MemoizedString tracks changes to the string value and calls notifyOnChange when updated\r\n private memoizedIsAuthoring = new MemoizedString(\"\", this.notifyOnChange);\r\n \r\n // Property accessors that use the memoized value\r\n get aStringProperty() {\r\n return this.memoizedIsAuthoring.val;\r\n }\r\n \r\n set aStringProperty(val: string) {\r\n this.memoizedIsAuthoring.val = val;\r\n }\r\n\r\n constructor(appObject: AppObject) {\r\n super(appObject, ExampleEntity.type);\r\n }\r\n}\r\n"]}
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ /**
3
+ * ExampleRepo.ts
4
+ *
5
+ * This file demonstrates how to implement a repository to manage collections of entities.
6
+ * Repositories are responsible for creating, retrieving, and deleting entities.
7
+ *
8
+ * Key concepts:
9
+ * - Repositories extend AppObjectEntityRepo<T> where T is the entity type
10
+ * - They provide methods to create and delete entities
11
+ * - They manage collections of entities and provide access to them
12
+ * - They can use custom entity factories to create specialized entities
13
+ *
14
+ * Usage pattern:
15
+ * 1. Get or create a repository using getById, get, or addIfMissing
16
+ * 2. Use the repository to create new entities
17
+ * 3. Access entities through the repository's getters
18
+ * 4. Delete entities through the repository when they're no longer needed
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.ExampleRepo = void 0;
22
+ exports.makeExampleRepo = makeExampleRepo;
23
+ const AppObject_1 = require("../../AppObject");
24
+ const generateUniqueID_1 = require("../../Utilities/generateUniqueID");
25
+ const ExampleEntity_1 = require("./ExampleEntity");
26
+ /**
27
+ * ExampleRepo manages a collection of ExampleEntity instances.
28
+ * Abstract class provides the interface and static helper methods.
29
+ */
30
+ class ExampleRepo extends AppObject_1.AppObjectEntityRepo {
31
+ /**
32
+ * Retrieves an ExampleRepo component from an AppObject
33
+ * @param appObj The AppObject to get the component from
34
+ * @returns The ExampleRepo component or undefined if not found
35
+ */
36
+ static get(appObj) {
37
+ return appObj.getComponent(this.type);
38
+ }
39
+ /**
40
+ * Retrieves an ExampleRepo by its parent AppObject's ID
41
+ * @param id The ID of the parent AppObject
42
+ * @param appObjects The AppObjectRepo to search in
43
+ * @returns The ExampleRepo component or undefined if not found
44
+ */
45
+ static getById(id, appObjects) {
46
+ return appObjects.get(id)?.getComponent(this.type);
47
+ }
48
+ /**
49
+ * Ensures an ExampleRepo exists on the AppObject, creating one if needed
50
+ * @param appObject The AppObject to check/add the component to
51
+ * @returns The existing or newly created ExampleRepo
52
+ */
53
+ static addIfMissing(appObject) {
54
+ const existing = appObject.getComponent(ExampleRepo.type);
55
+ if (existing) {
56
+ return existing;
57
+ }
58
+ else {
59
+ return makeExampleRepo(appObject);
60
+ }
61
+ }
62
+ }
63
+ exports.ExampleRepo = ExampleRepo;
64
+ /** Unique type identifier for this component */
65
+ ExampleRepo.type = "ExampleRepoType";
66
+ /**
67
+ * Factory function to create a new ExampleRepo
68
+ * @param appObject The AppObject to attach the repo to
69
+ * @returns A new ExampleRepo instance
70
+ */
71
+ function makeExampleRepo(appObject) {
72
+ return new ExampleRepoImp(appObject);
73
+ }
74
+ /**
75
+ * Concrete implementation of ExampleRepo
76
+ * This private class handles the actual implementation details
77
+ */
78
+ class ExampleRepoImp extends ExampleRepo {
79
+ /**
80
+ * Deletes an ExampleEntity from the repository by its AppObject ID
81
+ * @param id The ID of the entity's AppObject
82
+ */
83
+ deleteExampleEntity(id) {
84
+ const entity = this.getForAppObject(id);
85
+ if (!entity)
86
+ return;
87
+ entity.appObject.dispose();
88
+ this.removeForAppObject(id);
89
+ }
90
+ constructor(appObject) {
91
+ super(appObject, ExampleRepo.type);
92
+ /**
93
+ * Creates a new ExampleEntity and adds it to the repository
94
+ * @param id Optional ID for the entity's AppObject (generates one if not provided)
95
+ * @returns The newly created ExampleEntity
96
+ */
97
+ this.createExampleEntity = (id) => {
98
+ const idToUse = id ?? (0, generateUniqueID_1.generateUniqueID)();
99
+ const entity = this.exampleEntityFactory(idToUse);
100
+ this.add(entity);
101
+ return entity;
102
+ };
103
+ /**
104
+ * Default factory implementation for creating ExampleEntity instances
105
+ * Can be overridden to create specialized entities
106
+ */
107
+ this.exampleEntityFactory = (id) => {
108
+ const ao = this.appObjects.getOrCreate(id);
109
+ return (0, ExampleEntity_1.makeExampleEntity)(ao);
110
+ };
111
+ }
112
+ }
113
+ //# sourceMappingURL=ExampleRepo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExampleRepo.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Entities/ExampleRepo.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAwEH,0CAEC;AAxED,+CAIyB;AACzB,uEAAoE;AACpE,mDAAmE;AAKnE;;;GAGG;AACH,MAAsB,WAAY,SAAQ,+BAAkC;IAa1E;;;;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;;AA/CH,kCAgDC;AA/CC,gDAAgD;AAChC,gBAAI,GAAG,iBAAiB,CAAC;AAgD3C;;;;GAIG;AACH,SAAgB,eAAe,CAAC,SAAoB;IAClD,OAAO,IAAI,cAAc,CAAC,SAAS,CAAC,CAAC;AACvC,CAAC;AAED;;;GAGG;AACH,MAAM,cAAe,SAAQ,WAAW;IAatC;;;OAGG;IACH,mBAAmB,CAAC,EAAU;QAC5B,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;QACxC,IAAI,CAAC,MAAM;YAAE,OAAO;QAEpB,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QAC3B,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC;IAC9B,CAAC;IAWD,YAAY,SAAoB;QAC9B,KAAK,CAAC,SAAS,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;QAlCrC;;;;WAIG;QACH,wBAAmB,GAAG,CAAC,EAAsB,EAAiB,EAAE;YAC9D,MAAM,OAAO,GAAG,EAAE,IAAI,IAAA,mCAAgB,GAAE,CAAC;YACzC,MAAM,MAAM,GAAG,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;YAClD,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACjB,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC;QAcF;;;WAGG;QACH,yBAAoB,GAAG,CAAC,EAAU,EAAiB,EAAE;YACnD,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;YAC3C,OAAO,IAAA,iCAAiB,EAAC,EAAE,CAAC,CAAC;QAC/B,CAAC,CAAC;IAIF,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 {\r\n AppObject,\r\n AppObjectEntityRepo,\r\n AppObjectRepo\r\n} from \"../../AppObject\";\r\nimport { generateUniqueID } from \"../../Utilities/generateUniqueID\";\r\nimport { ExampleEntity, makeExampleEntity } from \"./ExampleEntity\";\r\n\r\n/** Type definition for a factory function that creates ExampleEntity instances */\r\nexport type ExampleEntityFactory = (id: string) => 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 /** Factory function used to create new entities */\r\n abstract exampleEntityFactory: ExampleEntityFactory;\r\n\r\n /** Creates a new entity with an optional ID */\r\n abstract createExampleEntity(id?: string): ExampleEntity;\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 * Creates a new ExampleEntity and adds it to the repository\r\n * @param id Optional ID for the entity's AppObject (generates one if not provided)\r\n * @returns The newly created ExampleEntity\r\n */\r\n createExampleEntity = (id: string | undefined): ExampleEntity => {\r\n const idToUse = id ?? generateUniqueID();\r\n const entity = this.exampleEntityFactory(idToUse);\r\n this.add(entity);\r\n return entity;\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.getForAppObject(id);\r\n if (!entity) return;\r\n\r\n entity.appObject.dispose();\r\n this.removeForAppObject(id);\r\n }\r\n\r\n /**\r\n * Default factory implementation for creating ExampleEntity instances\r\n * Can be overridden to create specialized entities\r\n */\r\n exampleEntityFactory = (id: string): ExampleEntity => {\r\n const ao = this.appObjects.getOrCreate(id);\r\n return makeExampleEntity(ao);\r\n };\r\n\r\n constructor(appObject: AppObject) {\r\n super(appObject, ExampleRepo.type);\r\n }\r\n}\r\n"]}
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ /**
3
+ * ExampleSingletonEntity.ts
4
+ *
5
+ * This file demonstrates how to implement a singleton entity in the application.
6
+ * Singleton entities are special entities that exist only once in the application
7
+ * and can be accessed globally from anywhere.
8
+ *
9
+ * Key concepts:
10
+ * - Singleton entities extend AppObjectEntity like regular entities
11
+ * - They register themselves as singletons with appObjects.registerSingleton()
12
+ * - They're accessed through a static get() method using getSingletonComponent()
13
+ * - There's only one instance of a singleton entity in the entire application
14
+ *
15
+ * Usage pattern:
16
+ * 1. Access the singleton entity using the static get() method
17
+ * 2. Access or modify properties via getters/setters
18
+ * 3. Register change observers to react to property updates
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.SingletonEntityExample = void 0;
22
+ exports.makeSingletonEntityExample = makeSingletonEntityExample;
23
+ const AppObject_1 = require("../../AppObject");
24
+ const getSingletonComponent_1 = require("../../AppObject/getSingletonComponent");
25
+ const MemoizedBoolean_1 = require("../../Entities/MemoizedBoolean");
26
+ /**
27
+ * SingletonEntityExample represents a global entity with a boolean property.
28
+ * As a singleton, only one instance exists in the application.
29
+ */
30
+ class SingletonEntityExample extends AppObject_1.AppObjectEntity {
31
+ }
32
+ exports.SingletonEntityExample = SingletonEntityExample;
33
+ /** Unique type identifier for this component */
34
+ SingletonEntityExample.type = "SingletonEntityExampleType";
35
+ /**
36
+ * Global accessor for the singleton entity
37
+ * @param appObjects The AppObjectRepo to search in
38
+ * @returns The singleton entity or undefined if not created yet
39
+ */
40
+ SingletonEntityExample.get = (appObjects) => (0, getSingletonComponent_1.getSingletonComponent)(SingletonEntityExample.type, appObjects);
41
+ /**
42
+ * Factory function to create a new SingletonEntityExample
43
+ * @param appObject The AppObject to attach the entity to
44
+ * @returns A new SingletonEntityExample instance
45
+ */
46
+ function makeSingletonEntityExample(appObject) {
47
+ return new SingletonEntityExampleImp(appObject);
48
+ }
49
+ /**
50
+ * Concrete implementation of SingletonEntityExample
51
+ * This private class handles the actual implementation details
52
+ */
53
+ class SingletonEntityExampleImp extends SingletonEntityExample {
54
+ // Property accessors that use the memoized value
55
+ get aBoolProperty() {
56
+ return this.memoizedIsAuthoring.val;
57
+ }
58
+ set aBoolProperty(val) {
59
+ this.memoizedIsAuthoring.val = val;
60
+ }
61
+ constructor(appObject) {
62
+ super(appObject, SingletonEntityExample.type);
63
+ // MemoizedBoolean tracks changes to the boolean value and calls notifyOnChange when updated
64
+ this.memoizedIsAuthoring = new MemoizedBoolean_1.MemoizedBoolean(false, this.notifyOnChange);
65
+ // Register this entity as a singleton so it can be accessed globally
66
+ this.appObjects.registerSingleton(this);
67
+ }
68
+ }
69
+ //# sourceMappingURL=ExampleSingletonEntity.js.map