@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.
- package/README.md +25 -1
- package/dist/cjs/ExampleFeature/Adapters/examplePmAdapter.js +64 -0
- package/dist/cjs/ExampleFeature/Adapters/examplePmAdapter.js.map +1 -0
- package/dist/cjs/ExampleFeature/Adapters/exampleSingletonPmAdapter.js +60 -0
- package/dist/cjs/ExampleFeature/Adapters/exampleSingletonPmAdapter.js.map +1 -0
- package/dist/cjs/ExampleFeature/Adapters/index.js +19 -0
- package/dist/cjs/ExampleFeature/Adapters/index.js.map +1 -0
- package/dist/cjs/ExampleFeature/Controllers/index.js +19 -0
- package/dist/cjs/ExampleFeature/Controllers/index.js.map +1 -0
- package/dist/cjs/ExampleFeature/Controllers/setExampleText.js +48 -0
- package/dist/cjs/ExampleFeature/Controllers/setExampleText.js.map +1 -0
- package/dist/cjs/ExampleFeature/Controllers/toggleExampleBoolean.js +47 -0
- package/dist/cjs/ExampleFeature/Controllers/toggleExampleBoolean.js.map +1 -0
- package/dist/cjs/ExampleFeature/Entities/ExampleEntity.js +90 -0
- package/dist/cjs/ExampleFeature/Entities/ExampleEntity.js.map +1 -0
- package/dist/cjs/ExampleFeature/Entities/ExampleRepo.js +113 -0
- package/dist/cjs/ExampleFeature/Entities/ExampleRepo.js.map +1 -0
- package/dist/cjs/ExampleFeature/Entities/ExampleSingletonEntity.js +69 -0
- package/dist/cjs/ExampleFeature/Entities/ExampleSingletonEntity.js.map +1 -0
- package/dist/cjs/ExampleFeature/Entities/index.js +20 -0
- package/dist/cjs/ExampleFeature/Entities/index.js.map +1 -0
- package/dist/cjs/ExampleFeature/Factory/index.js +18 -0
- package/dist/cjs/ExampleFeature/Factory/index.js.map +1 -0
- package/dist/cjs/ExampleFeature/Factory/setupExampleFeature.js +29 -0
- package/dist/cjs/ExampleFeature/Factory/setupExampleFeature.js.map +1 -0
- package/dist/cjs/ExampleFeature/Mocks/MockEditExampleStringUC.js +47 -0
- package/dist/cjs/ExampleFeature/Mocks/MockEditExampleStringUC.js.map +1 -0
- package/dist/cjs/ExampleFeature/Mocks/MockExamplePM.js +48 -0
- package/dist/cjs/ExampleFeature/Mocks/MockExamplePM.js.map +1 -0
- package/dist/cjs/ExampleFeature/Mocks/MockExampleSingletonPM.js +59 -0
- package/dist/cjs/ExampleFeature/Mocks/MockExampleSingletonPM.js.map +1 -0
- package/dist/cjs/ExampleFeature/Mocks/MockToggleExampleBooleanUC.js +57 -0
- package/dist/cjs/ExampleFeature/Mocks/MockToggleExampleBooleanUC.js.map +1 -0
- package/dist/cjs/ExampleFeature/Mocks/index.js +21 -0
- package/dist/cjs/ExampleFeature/Mocks/index.js.map +1 -0
- package/dist/cjs/ExampleFeature/PMs/ExamplePM.js +97 -0
- package/dist/cjs/ExampleFeature/PMs/ExamplePM.js.map +1 -0
- package/dist/cjs/ExampleFeature/PMs/ExampleSingletonPM.js +102 -0
- package/dist/cjs/ExampleFeature/PMs/ExampleSingletonPM.js.map +1 -0
- package/dist/cjs/ExampleFeature/PMs/index.js +19 -0
- package/dist/cjs/ExampleFeature/PMs/index.js.map +1 -0
- package/dist/cjs/ExampleFeature/UCs/EditExampleStringUC.js +87 -0
- package/dist/cjs/ExampleFeature/UCs/EditExampleStringUC.js.map +1 -0
- package/dist/cjs/ExampleFeature/UCs/ToggleExampleBooleanUC.js +79 -0
- package/dist/cjs/ExampleFeature/UCs/ToggleExampleBooleanUC.js.map +1 -0
- package/dist/cjs/ExampleFeature/UCs/index.js +19 -0
- package/dist/cjs/ExampleFeature/UCs/index.js.map +1 -0
- package/dist/cjs/ExampleFeature/index.js +24 -0
- package/dist/cjs/ExampleFeature/index.js.map +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/ExampleFeature/Adapters/examplePmAdapter.js +61 -0
- package/dist/esm/ExampleFeature/Adapters/examplePmAdapter.js.map +1 -0
- package/dist/esm/ExampleFeature/Adapters/exampleSingletonPmAdapter.js +57 -0
- package/dist/esm/ExampleFeature/Adapters/exampleSingletonPmAdapter.js.map +1 -0
- package/dist/esm/ExampleFeature/Adapters/index.js +3 -0
- package/dist/esm/ExampleFeature/Adapters/index.js.map +1 -0
- package/dist/esm/ExampleFeature/Controllers/index.js +3 -0
- package/dist/esm/ExampleFeature/Controllers/index.js.map +1 -0
- package/dist/esm/ExampleFeature/Controllers/setExampleText.js +45 -0
- package/dist/esm/ExampleFeature/Controllers/setExampleText.js.map +1 -0
- package/dist/esm/ExampleFeature/Controllers/toggleExampleBoolean.js +44 -0
- package/dist/esm/ExampleFeature/Controllers/toggleExampleBoolean.js.map +1 -0
- package/dist/esm/ExampleFeature/Entities/ExampleEntity.js +85 -0
- package/dist/esm/ExampleFeature/Entities/ExampleEntity.js.map +1 -0
- package/dist/esm/ExampleFeature/Entities/ExampleRepo.js +108 -0
- package/dist/esm/ExampleFeature/Entities/ExampleRepo.js.map +1 -0
- package/dist/esm/ExampleFeature/Entities/ExampleSingletonEntity.js +64 -0
- package/dist/esm/ExampleFeature/Entities/ExampleSingletonEntity.js.map +1 -0
- package/dist/esm/ExampleFeature/Entities/index.js +4 -0
- package/dist/esm/ExampleFeature/Entities/index.js.map +1 -0
- package/dist/esm/ExampleFeature/Factory/index.js +2 -0
- package/dist/esm/ExampleFeature/Factory/index.js.map +1 -0
- package/dist/esm/ExampleFeature/Factory/setupExampleFeature.js +26 -0
- package/dist/esm/ExampleFeature/Factory/setupExampleFeature.js.map +1 -0
- package/dist/esm/ExampleFeature/Mocks/MockEditExampleStringUC.js +43 -0
- package/dist/esm/ExampleFeature/Mocks/MockEditExampleStringUC.js.map +1 -0
- package/dist/esm/ExampleFeature/Mocks/MockExamplePM.js +44 -0
- package/dist/esm/ExampleFeature/Mocks/MockExamplePM.js.map +1 -0
- package/dist/esm/ExampleFeature/Mocks/MockExampleSingletonPM.js +54 -0
- package/dist/esm/ExampleFeature/Mocks/MockExampleSingletonPM.js.map +1 -0
- package/dist/esm/ExampleFeature/Mocks/MockToggleExampleBooleanUC.js +52 -0
- package/dist/esm/ExampleFeature/Mocks/MockToggleExampleBooleanUC.js.map +1 -0
- package/dist/esm/ExampleFeature/Mocks/index.js +5 -0
- package/dist/esm/ExampleFeature/Mocks/index.js.map +1 -0
- package/dist/esm/ExampleFeature/PMs/ExamplePM.js +92 -0
- package/dist/esm/ExampleFeature/PMs/ExamplePM.js.map +1 -0
- package/dist/esm/ExampleFeature/PMs/ExampleSingletonPM.js +97 -0
- package/dist/esm/ExampleFeature/PMs/ExampleSingletonPM.js.map +1 -0
- package/dist/esm/ExampleFeature/PMs/index.js +3 -0
- package/dist/esm/ExampleFeature/PMs/index.js.map +1 -0
- package/dist/esm/ExampleFeature/UCs/EditExampleStringUC.js +82 -0
- package/dist/esm/ExampleFeature/UCs/EditExampleStringUC.js.map +1 -0
- package/dist/esm/ExampleFeature/UCs/ToggleExampleBooleanUC.js +74 -0
- package/dist/esm/ExampleFeature/UCs/ToggleExampleBooleanUC.js.map +1 -0
- package/dist/esm/ExampleFeature/UCs/index.js +3 -0
- package/dist/esm/ExampleFeature/UCs/index.js.map +1 -0
- package/dist/esm/ExampleFeature/index.js +8 -0
- package/dist/esm/ExampleFeature/index.js.map +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/types/ExampleFeature/Adapters/examplePmAdapter.d.ts +29 -0
- package/dist/types/ExampleFeature/Adapters/examplePmAdapter.d.ts.map +1 -0
- package/dist/types/ExampleFeature/Adapters/exampleSingletonPmAdapter.d.ts +31 -0
- package/dist/types/ExampleFeature/Adapters/exampleSingletonPmAdapter.d.ts.map +1 -0
- package/dist/types/ExampleFeature/Adapters/index.d.ts +3 -0
- package/dist/types/ExampleFeature/Adapters/index.d.ts.map +1 -0
- package/dist/types/ExampleFeature/Controllers/index.d.ts +3 -0
- package/dist/types/ExampleFeature/Controllers/index.d.ts.map +1 -0
- package/dist/types/ExampleFeature/Controllers/setExampleText.d.ts +35 -0
- package/dist/types/ExampleFeature/Controllers/setExampleText.d.ts.map +1 -0
- package/dist/types/ExampleFeature/Controllers/toggleExampleBoolean.d.ts +34 -0
- package/dist/types/ExampleFeature/Controllers/toggleExampleBoolean.d.ts.map +1 -0
- package/dist/types/ExampleFeature/Entities/ExampleEntity.d.ts +55 -0
- package/dist/types/ExampleFeature/Entities/ExampleEntity.d.ts.map +1 -0
- package/dist/types/ExampleFeature/Entities/ExampleRepo.d.ts +62 -0
- package/dist/types/ExampleFeature/Entities/ExampleRepo.d.ts.map +1 -0
- package/dist/types/ExampleFeature/Entities/ExampleSingletonEntity.d.ts +43 -0
- package/dist/types/ExampleFeature/Entities/ExampleSingletonEntity.d.ts.map +1 -0
- package/dist/types/ExampleFeature/Entities/index.d.ts +4 -0
- package/dist/types/ExampleFeature/Entities/index.d.ts.map +1 -0
- package/dist/types/ExampleFeature/Factory/index.d.ts +2 -0
- package/dist/types/ExampleFeature/Factory/index.d.ts.map +1 -0
- package/dist/types/ExampleFeature/Factory/setupExampleFeature.d.ts +17 -0
- package/dist/types/ExampleFeature/Factory/setupExampleFeature.d.ts.map +1 -0
- package/dist/types/ExampleFeature/Mocks/MockEditExampleStringUC.d.ts +42 -0
- package/dist/types/ExampleFeature/Mocks/MockEditExampleStringUC.d.ts.map +1 -0
- package/dist/types/ExampleFeature/Mocks/MockExamplePM.d.ts +41 -0
- package/dist/types/ExampleFeature/Mocks/MockExamplePM.d.ts.map +1 -0
- package/dist/types/ExampleFeature/Mocks/MockExampleSingletonPM.d.ts +49 -0
- package/dist/types/ExampleFeature/Mocks/MockExampleSingletonPM.d.ts.map +1 -0
- package/dist/types/ExampleFeature/Mocks/MockToggleExampleBooleanUC.d.ts +47 -0
- package/dist/types/ExampleFeature/Mocks/MockToggleExampleBooleanUC.d.ts.map +1 -0
- package/dist/types/ExampleFeature/Mocks/index.d.ts +5 -0
- package/dist/types/ExampleFeature/Mocks/index.d.ts.map +1 -0
- package/dist/types/ExampleFeature/PMs/ExamplePM.d.ts +42 -0
- package/dist/types/ExampleFeature/PMs/ExamplePM.d.ts.map +1 -0
- package/dist/types/ExampleFeature/PMs/ExampleSingletonPM.d.ts +52 -0
- package/dist/types/ExampleFeature/PMs/ExampleSingletonPM.d.ts.map +1 -0
- package/dist/types/ExampleFeature/PMs/index.d.ts +3 -0
- package/dist/types/ExampleFeature/PMs/index.d.ts.map +1 -0
- package/dist/types/ExampleFeature/UCs/EditExampleStringUC.d.ts +52 -0
- package/dist/types/ExampleFeature/UCs/EditExampleStringUC.d.ts.map +1 -0
- package/dist/types/ExampleFeature/UCs/ToggleExampleBooleanUC.d.ts +44 -0
- package/dist/types/ExampleFeature/UCs/ToggleExampleBooleanUC.d.ts.map +1 -0
- package/dist/types/ExampleFeature/UCs/index.d.ts +3 -0
- package/dist/types/ExampleFeature/UCs/index.d.ts.map +1 -0
- package/dist/types/ExampleFeature/index.d.ts +8 -0
- package/dist/types/ExampleFeature/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +6 -4
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExampleRepo.ts
|
|
3
|
+
*
|
|
4
|
+
* This file demonstrates how to implement a repository to manage collections of entities.
|
|
5
|
+
* Repositories are responsible for creating, retrieving, and deleting entities.
|
|
6
|
+
*
|
|
7
|
+
* Key concepts:
|
|
8
|
+
* - Repositories extend AppObjectEntityRepo<T> where T is the entity type
|
|
9
|
+
* - They provide methods to create and delete entities
|
|
10
|
+
* - They manage collections of entities and provide access to them
|
|
11
|
+
* - They can use custom entity factories to create specialized entities
|
|
12
|
+
*
|
|
13
|
+
* Usage pattern:
|
|
14
|
+
* 1. Get or create a repository using getById, get, or addIfMissing
|
|
15
|
+
* 2. Use the repository to create new entities
|
|
16
|
+
* 3. Access entities through the repository's getters
|
|
17
|
+
* 4. Delete entities through the repository when they're no longer needed
|
|
18
|
+
*/
|
|
19
|
+
import { AppObjectEntityRepo } from "../../AppObject";
|
|
20
|
+
import { generateUniqueID } from "../../Utilities/generateUniqueID";
|
|
21
|
+
import { makeExampleEntity } from "./ExampleEntity";
|
|
22
|
+
/**
|
|
23
|
+
* ExampleRepo manages a collection of ExampleEntity instances.
|
|
24
|
+
* Abstract class provides the interface and static helper methods.
|
|
25
|
+
*/
|
|
26
|
+
export class ExampleRepo extends AppObjectEntityRepo {
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves an ExampleRepo component from an AppObject
|
|
29
|
+
* @param appObj The AppObject to get the component from
|
|
30
|
+
* @returns The ExampleRepo component or undefined if not found
|
|
31
|
+
*/
|
|
32
|
+
static get(appObj) {
|
|
33
|
+
return appObj.getComponent(this.type);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Retrieves an ExampleRepo by its parent AppObject's ID
|
|
37
|
+
* @param id The ID of the parent AppObject
|
|
38
|
+
* @param appObjects The AppObjectRepo to search in
|
|
39
|
+
* @returns The ExampleRepo component or undefined if not found
|
|
40
|
+
*/
|
|
41
|
+
static getById(id, appObjects) {
|
|
42
|
+
return appObjects.get(id)?.getComponent(this.type);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Ensures an ExampleRepo exists on the AppObject, creating one if needed
|
|
46
|
+
* @param appObject The AppObject to check/add the component to
|
|
47
|
+
* @returns The existing or newly created ExampleRepo
|
|
48
|
+
*/
|
|
49
|
+
static addIfMissing(appObject) {
|
|
50
|
+
const existing = appObject.getComponent(ExampleRepo.type);
|
|
51
|
+
if (existing) {
|
|
52
|
+
return existing;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return makeExampleRepo(appObject);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** Unique type identifier for this component */
|
|
60
|
+
ExampleRepo.type = "ExampleRepoType";
|
|
61
|
+
/**
|
|
62
|
+
* Factory function to create a new ExampleRepo
|
|
63
|
+
* @param appObject The AppObject to attach the repo to
|
|
64
|
+
* @returns A new ExampleRepo instance
|
|
65
|
+
*/
|
|
66
|
+
export function makeExampleRepo(appObject) {
|
|
67
|
+
return new ExampleRepoImp(appObject);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Concrete implementation of ExampleRepo
|
|
71
|
+
* This private class handles the actual implementation details
|
|
72
|
+
*/
|
|
73
|
+
class ExampleRepoImp extends ExampleRepo {
|
|
74
|
+
/**
|
|
75
|
+
* Deletes an ExampleEntity from the repository by its AppObject ID
|
|
76
|
+
* @param id The ID of the entity's AppObject
|
|
77
|
+
*/
|
|
78
|
+
deleteExampleEntity(id) {
|
|
79
|
+
const entity = this.getForAppObject(id);
|
|
80
|
+
if (!entity)
|
|
81
|
+
return;
|
|
82
|
+
entity.appObject.dispose();
|
|
83
|
+
this.removeForAppObject(id);
|
|
84
|
+
}
|
|
85
|
+
constructor(appObject) {
|
|
86
|
+
super(appObject, ExampleRepo.type);
|
|
87
|
+
/**
|
|
88
|
+
* Creates a new ExampleEntity and adds it to the repository
|
|
89
|
+
* @param id Optional ID for the entity's AppObject (generates one if not provided)
|
|
90
|
+
* @returns The newly created ExampleEntity
|
|
91
|
+
*/
|
|
92
|
+
this.createExampleEntity = (id) => {
|
|
93
|
+
const idToUse = id ?? generateUniqueID();
|
|
94
|
+
const entity = this.exampleEntityFactory(idToUse);
|
|
95
|
+
this.add(entity);
|
|
96
|
+
return entity;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Default factory implementation for creating ExampleEntity instances
|
|
100
|
+
* Can be overridden to create specialized entities
|
|
101
|
+
*/
|
|
102
|
+
this.exampleEntityFactory = (id) => {
|
|
103
|
+
const ao = this.appObjects.getOrCreate(id);
|
|
104
|
+
return makeExampleEntity(ao);
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=ExampleRepo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExampleRepo.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Entities/ExampleRepo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAEL,mBAAmB,EAEpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAiB,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAKnE;;;GAGG;AACH,MAAM,OAAgB,WAAY,SAAQ,mBAAkC;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;;AA9CD,gDAAgD;AAChC,gBAAI,GAAG,iBAAiB,CAAC;AAgD3C;;;;GAIG;AACH,MAAM,UAAU,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,gBAAgB,EAAE,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,iBAAiB,CAAC,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,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExampleSingletonEntity.ts
|
|
3
|
+
*
|
|
4
|
+
* This file demonstrates how to implement a singleton entity in the application.
|
|
5
|
+
* Singleton entities are special entities that exist only once in the application
|
|
6
|
+
* and can be accessed globally from anywhere.
|
|
7
|
+
*
|
|
8
|
+
* Key concepts:
|
|
9
|
+
* - Singleton entities extend AppObjectEntity like regular entities
|
|
10
|
+
* - They register themselves as singletons with appObjects.registerSingleton()
|
|
11
|
+
* - They're accessed through a static get() method using getSingletonComponent()
|
|
12
|
+
* - There's only one instance of a singleton entity in the entire application
|
|
13
|
+
*
|
|
14
|
+
* Usage pattern:
|
|
15
|
+
* 1. Access the singleton entity using the static get() method
|
|
16
|
+
* 2. Access or modify properties via getters/setters
|
|
17
|
+
* 3. Register change observers to react to property updates
|
|
18
|
+
*/
|
|
19
|
+
import { AppObjectEntity } from "../../AppObject";
|
|
20
|
+
import { getSingletonComponent } from "../../AppObject/getSingletonComponent";
|
|
21
|
+
import { MemoizedBoolean } from "../../Entities/MemoizedBoolean";
|
|
22
|
+
/**
|
|
23
|
+
* SingletonEntityExample represents a global entity with a boolean property.
|
|
24
|
+
* As a singleton, only one instance exists in the application.
|
|
25
|
+
*/
|
|
26
|
+
export class SingletonEntityExample extends AppObjectEntity {
|
|
27
|
+
}
|
|
28
|
+
/** Unique type identifier for this component */
|
|
29
|
+
SingletonEntityExample.type = "SingletonEntityExampleType";
|
|
30
|
+
/**
|
|
31
|
+
* Global accessor for the singleton entity
|
|
32
|
+
* @param appObjects The AppObjectRepo to search in
|
|
33
|
+
* @returns The singleton entity or undefined if not created yet
|
|
34
|
+
*/
|
|
35
|
+
SingletonEntityExample.get = (appObjects) => getSingletonComponent(SingletonEntityExample.type, appObjects);
|
|
36
|
+
/**
|
|
37
|
+
* Factory function to create a new SingletonEntityExample
|
|
38
|
+
* @param appObject The AppObject to attach the entity to
|
|
39
|
+
* @returns A new SingletonEntityExample instance
|
|
40
|
+
*/
|
|
41
|
+
export function makeSingletonEntityExample(appObject) {
|
|
42
|
+
return new SingletonEntityExampleImp(appObject);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Concrete implementation of SingletonEntityExample
|
|
46
|
+
* This private class handles the actual implementation details
|
|
47
|
+
*/
|
|
48
|
+
class SingletonEntityExampleImp extends SingletonEntityExample {
|
|
49
|
+
// Property accessors that use the memoized value
|
|
50
|
+
get aBoolProperty() {
|
|
51
|
+
return this.memoizedIsAuthoring.val;
|
|
52
|
+
}
|
|
53
|
+
set aBoolProperty(val) {
|
|
54
|
+
this.memoizedIsAuthoring.val = val;
|
|
55
|
+
}
|
|
56
|
+
constructor(appObject) {
|
|
57
|
+
super(appObject, SingletonEntityExample.type);
|
|
58
|
+
// MemoizedBoolean tracks changes to the boolean value and calls notifyOnChange when updated
|
|
59
|
+
this.memoizedIsAuthoring = new MemoizedBoolean(false, this.notifyOnChange);
|
|
60
|
+
// Register this entity as a singleton so it can be accessed globally
|
|
61
|
+
this.appObjects.registerSingleton(this);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=ExampleSingletonEntity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExampleSingletonEntity.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Entities/ExampleSingletonEntity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAEL,eAAe,EAEhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEjE;;;GAGG;AACH,MAAM,OAAgB,sBAAuB,SAAQ,eAAe;;AAClE,gDAAgD;AAChC,2BAAI,GAAG,4BAA4B,CAAC;AAMpD;;;;GAIG;AACI,0BAAG,GAAG,CACX,UAAyB,EACW,EAAE,CACtC,qBAAqB,CAAC,sBAAsB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AAGnE;;;;GAIG;AACH,MAAM,UAAU,0BAA0B,CACxC,SAAoB;IAEpB,OAAO,IAAI,yBAAyB,CAAC,SAAS,CAAC,CAAC;AAClD,CAAC;AAED;;;GAGG;AACH,MAAM,yBAA0B,SAAQ,sBAAsB;IAI5D,iDAAiD;IACjD,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC;IACtC,CAAC;IAED,IAAI,aAAa,CAAC,GAAY;QAC5B,IAAI,CAAC,mBAAmB,CAAC,GAAG,GAAG,GAAG,CAAC;IACrC,CAAC;IAED,YAAY,SAAoB;QAC9B,KAAK,CAAC,SAAS,EAAE,sBAAsB,CAAC,IAAI,CAAC,CAAC;QAbhD,4FAA4F;QACpF,wBAAmB,GAAG,IAAI,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QAa5E,qEAAqE;QACrE,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;CACF","sourcesContent":["/**\r\n * ExampleSingletonEntity.ts\r\n * \r\n * This file demonstrates how to implement a singleton entity in the application.\r\n * Singleton entities are special entities that exist only once in the application\r\n * and can be accessed globally from anywhere.\r\n * \r\n * Key concepts:\r\n * - Singleton entities extend AppObjectEntity like regular entities\r\n * - They register themselves as singletons with appObjects.registerSingleton()\r\n * - They're accessed through a static get() method using getSingletonComponent()\r\n * - There's only one instance of a singleton entity in the entire application\r\n * \r\n * Usage pattern:\r\n * 1. Access the singleton entity using the static get() method\r\n * 2. Access or modify properties via getters/setters\r\n * 3. Register change observers to react to property updates\r\n */\r\n\r\nimport {\r\n AppObject,\r\n AppObjectEntity,\r\n AppObjectRepo\r\n} from \"../../AppObject\";\r\nimport { getSingletonComponent } from \"../../AppObject/getSingletonComponent\";\r\nimport { MemoizedBoolean } from \"../../Entities/MemoizedBoolean\";\r\n\r\n/**\r\n * SingletonEntityExample represents a global entity with a boolean property.\r\n * As a singleton, only one instance exists in the application.\r\n */\r\nexport abstract class SingletonEntityExample extends AppObjectEntity {\r\n /** Unique type identifier for this component */\r\n static readonly type = \"SingletonEntityExampleType\";\r\n\r\n /** Boolean property accessor methods that must be implemented */\r\n abstract get aBoolProperty(): boolean;\r\n abstract set aBoolProperty(val: boolean);\r\n\r\n /**\r\n * Global accessor for the singleton entity\r\n * @param appObjects The AppObjectRepo to search in\r\n * @returns The singleton entity or undefined if not created yet\r\n */\r\n static get = (\r\n appObjects: AppObjectRepo\r\n ): SingletonEntityExample | undefined =>\r\n getSingletonComponent(SingletonEntityExample.type, appObjects);\r\n}\r\n\r\n/**\r\n * Factory function to create a new SingletonEntityExample\r\n * @param appObject The AppObject to attach the entity to\r\n * @returns A new SingletonEntityExample instance\r\n */\r\nexport function makeSingletonEntityExample(\r\n appObject: AppObject\r\n): SingletonEntityExample {\r\n return new SingletonEntityExampleImp(appObject);\r\n}\r\n\r\n/**\r\n * Concrete implementation of SingletonEntityExample\r\n * This private class handles the actual implementation details\r\n */\r\nclass SingletonEntityExampleImp extends SingletonEntityExample {\r\n // MemoizedBoolean tracks changes to the boolean value and calls notifyOnChange when updated\r\n private memoizedIsAuthoring = new MemoizedBoolean(false, this.notifyOnChange);\r\n \r\n // Property accessors that use the memoized value\r\n get aBoolProperty() {\r\n return this.memoizedIsAuthoring.val;\r\n }\r\n \r\n set aBoolProperty(val: boolean) {\r\n this.memoizedIsAuthoring.val = val;\r\n }\r\n\r\n constructor(appObject: AppObject) {\r\n super(appObject, SingletonEntityExample.type);\r\n // Register this entity as a singleton so it can be accessed globally\r\n this.appObjects.registerSingleton(this);\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Entities/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,0BAA0B,CAAC","sourcesContent":["export * from \"./ExampleEntity\";\r\nexport * from \"./ExampleRepo\";\r\nexport * from \"./ExampleSingletonEntity\";\r\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Factory/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC","sourcesContent":["export * from \"./setupExampleFeature\";"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* setupExampleFeature.ts
|
|
3
|
+
*
|
|
4
|
+
* This file provides a setup function to initialize the ExampleFeature components.
|
|
5
|
+
* It creates a dedicated AppObject for ExampleFeature and adds all required
|
|
6
|
+
* singleton components to it.
|
|
7
|
+
*/
|
|
8
|
+
import { makeSingletonEntityExample } from "../Entities/ExampleSingletonEntity";
|
|
9
|
+
import { makeExampleSingletonPM } from "../PMs/ExampleSingletonPM";
|
|
10
|
+
import { makeToggleExampleBooleanUC } from "../UCs/ToggleExampleBooleanUC";
|
|
11
|
+
/**
|
|
12
|
+
* Sets up the ExampleFeature by creating an AppObject and attaching required components.
|
|
13
|
+
*
|
|
14
|
+
* @param appObjects - Repository of AppObjects to use for creating the feature
|
|
15
|
+
* @returns The singleton entity instance
|
|
16
|
+
*/
|
|
17
|
+
export function setupExampleFeature(appObjects) {
|
|
18
|
+
// Create a dedicated AppObject for ExampleFeature
|
|
19
|
+
const appObject = appObjects.getOrCreate("ExampleFeature");
|
|
20
|
+
// Add singleton components to the AppObject
|
|
21
|
+
const entity = makeSingletonEntityExample(appObject);
|
|
22
|
+
makeExampleSingletonPM(appObject);
|
|
23
|
+
makeToggleExampleBooleanUC(appObject);
|
|
24
|
+
return entity;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=setupExampleFeature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setupExampleFeature.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Factory/setupExampleFeature.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,0BAA0B,EAA0B,MAAM,oCAAoC,CAAC;AACxG,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAE3E;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,UAAyB;IAC3D,kDAAkD;IAClD,MAAM,SAAS,GAAG,UAAU,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;IAE3D,4CAA4C;IAC5C,MAAM,MAAM,GAAG,0BAA0B,CAAC,SAAS,CAAC,CAAC;IACrD,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAClC,0BAA0B,CAAC,SAAS,CAAC,CAAC;IAEtC,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/**\r\n * setupExampleFeature.ts\r\n * \r\n * This file provides a setup function to initialize the ExampleFeature components.\r\n * It creates a dedicated AppObject for ExampleFeature and adds all required\r\n * singleton components to it.\r\n */\r\n\r\nimport { AppObjectRepo } from \"../../AppObject\";\r\nimport { makeSingletonEntityExample, SingletonEntityExample } from \"../Entities/ExampleSingletonEntity\";\r\nimport { makeExampleSingletonPM } from \"../PMs/ExampleSingletonPM\";\r\nimport { makeToggleExampleBooleanUC } from \"../UCs/ToggleExampleBooleanUC\";\r\n\r\n/**\r\n * Sets up the ExampleFeature by creating an AppObject and attaching required components.\r\n * \r\n * @param appObjects - Repository of AppObjects to use for creating the feature\r\n * @returns The singleton entity instance\r\n */\r\nexport function setupExampleFeature(appObjects: AppObjectRepo): SingletonEntityExample {\r\n // Create a dedicated AppObject for ExampleFeature\r\n const appObject = appObjects.getOrCreate(\"ExampleFeature\");\r\n \r\n // Add singleton components to the AppObject\r\n const entity = makeSingletonEntityExample(appObject);\r\n makeExampleSingletonPM(appObject);\r\n makeToggleExampleBooleanUC(appObject);\r\n \r\n return entity;\r\n}"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MockEditExampleStringUC.ts
|
|
3
|
+
*
|
|
4
|
+
* This file demonstrates how to implement a mock UC for testing.
|
|
5
|
+
* Mock UCs extend the real UC classes but override their methods with test implementations.
|
|
6
|
+
* This allows tests to verify that the UC methods are called correctly without
|
|
7
|
+
* actually modifying entities or performing real operations.
|
|
8
|
+
*
|
|
9
|
+
* Key concepts:
|
|
10
|
+
* - Mock UCs extend the real UC classes
|
|
11
|
+
* - They override methods with test implementations (often empty or spy functions)
|
|
12
|
+
* - They're used in unit tests to isolate components from their dependencies
|
|
13
|
+
* - They help verify that methods are called with the correct parameters
|
|
14
|
+
*
|
|
15
|
+
* Usage pattern (in tests):
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // In a test file
|
|
18
|
+
* const mockUC = new MockEditExampleStringUC(appObject);
|
|
19
|
+
* const spy = jest.spyOn(mockUC, 'editExampleString');
|
|
20
|
+
*
|
|
21
|
+
* // Call the function that should use the UC
|
|
22
|
+
* someFunction(appObject);
|
|
23
|
+
*
|
|
24
|
+
* // Verify the UC method was called correctly
|
|
25
|
+
* expect(spy).toHaveBeenCalledWith('expected value');
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
import { EditExampleStringUC } from "../UCs/EditExampleStringUC";
|
|
29
|
+
/**
|
|
30
|
+
* Mock implementation of EditExampleStringUC for testing
|
|
31
|
+
* Provides a no-op implementation of editExampleString that can be spied on in tests
|
|
32
|
+
*/
|
|
33
|
+
export class MockEditExampleStringUC extends EditExampleStringUC {
|
|
34
|
+
constructor(appObject) {
|
|
35
|
+
super(appObject, EditExampleStringUC.type);
|
|
36
|
+
/**
|
|
37
|
+
* Mock implementation that does nothing
|
|
38
|
+
* In tests, this can be replaced with a Jest spy to track calls
|
|
39
|
+
*/
|
|
40
|
+
this.editExampleString = (text) => { };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=MockEditExampleStringUC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MockEditExampleStringUC.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Mocks/MockEditExampleStringUC.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE;;;GAGG;AACH,MAAM,OAAO,uBAAwB,SAAQ,mBAAmB;IAO9D,YAAY,SAAoB;QAC9B,KAAK,CAAC,SAAS,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;QAP7C;;;WAGG;QACH,sBAAiB,GAAG,CAAC,IAAY,EAAQ,EAAE,GAAE,CAAC,CAAC;IAI/C,CAAC;CACF","sourcesContent":["/**\r\n * MockEditExampleStringUC.ts\r\n * \r\n * This file demonstrates how to implement a mock UC for testing.\r\n * Mock UCs extend the real UC classes but override their methods with test implementations.\r\n * This allows tests to verify that the UC methods are called correctly without\r\n * actually modifying entities or performing real operations.\r\n * \r\n * Key concepts:\r\n * - Mock UCs extend the real UC classes\r\n * - They override methods with test implementations (often empty or spy functions)\r\n * - They're used in unit tests to isolate components from their dependencies\r\n * - They help verify that methods are called with the correct parameters\r\n * \r\n * Usage pattern (in tests):\r\n * ```typescript\r\n * // In a test file\r\n * const mockUC = new MockEditExampleStringUC(appObject);\r\n * const spy = jest.spyOn(mockUC, 'editExampleString');\r\n * \r\n * // Call the function that should use the UC\r\n * someFunction(appObject);\r\n * \r\n * // Verify the UC method was called correctly\r\n * expect(spy).toHaveBeenCalledWith('expected value');\r\n * ```\r\n */\r\n\r\nimport { AppObject } from \"../../AppObject\";\r\nimport { EditExampleStringUC } from \"../UCs/EditExampleStringUC\";\r\n\r\n/**\r\n * Mock implementation of EditExampleStringUC for testing\r\n * Provides a no-op implementation of editExampleString that can be spied on in tests\r\n */\r\nexport class MockEditExampleStringUC extends EditExampleStringUC {\r\n /**\r\n * Mock implementation that does nothing\r\n * In tests, this can be replaced with a Jest spy to track calls\r\n */\r\n editExampleString = (text: string): void => {};\r\n\r\n constructor(appObject: AppObject) {\r\n super(appObject, EditExampleStringUC.type);\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MockExamplePM.ts
|
|
3
|
+
*
|
|
4
|
+
* This file demonstrates how to implement a mock PM for testing.
|
|
5
|
+
* Mock PMs extend the real PM classes but override their methods with test implementations.
|
|
6
|
+
* This allows tests to verify PM behavior without depending on real entities.
|
|
7
|
+
*
|
|
8
|
+
* Key concepts:
|
|
9
|
+
* - Mock PMs extend the real PM classes
|
|
10
|
+
* - They override methods with test implementations
|
|
11
|
+
* - They're used in unit tests to isolate components from their dependencies
|
|
12
|
+
* - They help test adapters and other components that use PMs
|
|
13
|
+
*
|
|
14
|
+
* Usage pattern (in tests):
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // In a test file
|
|
17
|
+
* const mockPM = new MockExamplePM(appObject);
|
|
18
|
+
* const addViewSpy = jest.spyOn(mockPM, 'addView');
|
|
19
|
+
*
|
|
20
|
+
* // Test the component that uses the PM
|
|
21
|
+
* adapter.subscribe(id, appObjects, setVM);
|
|
22
|
+
*
|
|
23
|
+
* // Verify the PM method was called correctly
|
|
24
|
+
* expect(addViewSpy).toHaveBeenCalledWith(setVM);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
import { ExamplePM } from "../PMs/ExamplePM";
|
|
28
|
+
/**
|
|
29
|
+
* Mock implementation of ExamplePM for testing
|
|
30
|
+
* Provides simplified implementations of required methods
|
|
31
|
+
*/
|
|
32
|
+
export class MockExamplePM extends ExamplePM {
|
|
33
|
+
constructor(appObject) {
|
|
34
|
+
super(appObject, ExamplePM.type);
|
|
35
|
+
/**
|
|
36
|
+
* Simplified implementation that always returns true
|
|
37
|
+
* This avoids the need to implement real comparison logic in tests
|
|
38
|
+
*/
|
|
39
|
+
this.vmsAreEqual = () => {
|
|
40
|
+
return true;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=MockExamplePM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MockExamplePM.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Mocks/MockExamplePM.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,SAAS;IAS1C,YAAY,SAAoB;QAC9B,KAAK,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;QATnC;;;WAGG;QACH,gBAAW,GAAG,GAAG,EAAE;YACjB,OAAO,IAAI,CAAC;QACd,CAAC,CAAC;IAIF,CAAC;CACF","sourcesContent":["/**\r\n * MockExamplePM.ts\r\n * \r\n * This file demonstrates how to implement a mock PM for testing.\r\n * Mock PMs extend the real PM classes but override their methods with test implementations.\r\n * This allows tests to verify PM behavior without depending on real entities.\r\n * \r\n * Key concepts:\r\n * - Mock PMs extend the real PM classes\r\n * - They override methods with test implementations\r\n * - They're used in unit tests to isolate components from their dependencies\r\n * - They help test adapters and other components that use PMs\r\n * \r\n * Usage pattern (in tests):\r\n * ```typescript\r\n * // In a test file\r\n * const mockPM = new MockExamplePM(appObject);\r\n * const addViewSpy = jest.spyOn(mockPM, 'addView');\r\n * \r\n * // Test the component that uses the PM\r\n * adapter.subscribe(id, appObjects, setVM);\r\n * \r\n * // Verify the PM method was called correctly\r\n * expect(addViewSpy).toHaveBeenCalledWith(setVM);\r\n * ```\r\n */\r\n\r\nimport { AppObject } from \"../../AppObject\";\r\nimport { ExamplePM } from \"../PMs/ExamplePM\";\r\n\r\n/**\r\n * Mock implementation of ExamplePM for testing\r\n * Provides simplified implementations of required methods\r\n */\r\nexport class MockExamplePM extends ExamplePM {\r\n /**\r\n * Simplified implementation that always returns true\r\n * This avoids the need to implement real comparison logic in tests\r\n */\r\n vmsAreEqual = () => {\r\n return true;\r\n };\r\n\r\n constructor(appObject: AppObject) {\r\n super(appObject, ExamplePM.type);\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MockExampleSingletonPM.ts
|
|
3
|
+
*
|
|
4
|
+
* This file demonstrates how to implement a mock singleton PM for testing.
|
|
5
|
+
* Mock singleton PMs extend the real singleton PM classes and provide helper
|
|
6
|
+
* functions to create and access them in tests.
|
|
7
|
+
*
|
|
8
|
+
* Key concepts:
|
|
9
|
+
* - Mock singleton PMs extend the real singleton PM classes
|
|
10
|
+
* - They override methods with test implementations
|
|
11
|
+
* - They include helper functions to create and access them in tests
|
|
12
|
+
* - They're used to test adapters and controllers that depend on singleton PMs
|
|
13
|
+
*
|
|
14
|
+
* Usage pattern (in tests):
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // In a test file
|
|
17
|
+
* const mockPM = makeMockExampleSingletonPM(appObjects);
|
|
18
|
+
* const addViewSpy = jest.spyOn(mockPM, 'addView');
|
|
19
|
+
*
|
|
20
|
+
* // Test the component that uses the singleton PM
|
|
21
|
+
* adapter.subscribe(appObjects, setVM);
|
|
22
|
+
*
|
|
23
|
+
* // Verify the PM method was called correctly
|
|
24
|
+
* expect(addViewSpy).toHaveBeenCalledWith(setVM);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
import { ExampleSingletonPM } from "../PMs/ExampleSingletonPM";
|
|
28
|
+
/**
|
|
29
|
+
* Mock implementation of ExampleSingletonPM for testing
|
|
30
|
+
* Provides simplified implementations of required methods
|
|
31
|
+
*/
|
|
32
|
+
export class MockExampleSingletonPM extends ExampleSingletonPM {
|
|
33
|
+
constructor(appObject) {
|
|
34
|
+
super(appObject, ExampleSingletonPM.type);
|
|
35
|
+
/**
|
|
36
|
+
* Simplified implementation that always returns true
|
|
37
|
+
* This avoids the need to implement real comparison logic in tests
|
|
38
|
+
*/
|
|
39
|
+
this.vmsAreEqual = () => {
|
|
40
|
+
return true;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Helper function to create and register a MockExampleSingletonPM
|
|
46
|
+
* Returns the created mock for use in tests
|
|
47
|
+
*
|
|
48
|
+
* @param appObjects The AppObjectRepo to register the mock with
|
|
49
|
+
* @returns A new MockExampleSingletonPM instance
|
|
50
|
+
*/
|
|
51
|
+
export function makeMockExampleSingletonPM(appObjects) {
|
|
52
|
+
return new MockExampleSingletonPM(appObjects.getOrCreate("MockExampleSingletonPM"));
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=MockExampleSingletonPM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MockExampleSingletonPM.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Mocks/MockExampleSingletonPM.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D;;;GAGG;AACH,MAAM,OAAO,sBAAuB,SAAQ,kBAAkB;IAS5D,YAAY,SAAoB;QAC9B,KAAK,CAAC,SAAS,EAAE,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAT5C;;;WAGG;QACH,gBAAW,GAAG,GAAG,EAAE;YACjB,OAAO,IAAI,CAAC;QACd,CAAC,CAAC;IAIF,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CAAC,UAAyB;IAClE,OAAO,IAAI,sBAAsB,CAC/B,UAAU,CAAC,WAAW,CAAC,wBAAwB,CAAC,CACjD,CAAC;AACJ,CAAC","sourcesContent":["/**\r\n * MockExampleSingletonPM.ts\r\n * \r\n * This file demonstrates how to implement a mock singleton PM for testing.\r\n * Mock singleton PMs extend the real singleton PM classes and provide helper\r\n * functions to create and access them in tests.\r\n * \r\n * Key concepts:\r\n * - Mock singleton PMs extend the real singleton PM classes\r\n * - They override methods with test implementations\r\n * - They include helper functions to create and access them in tests\r\n * - They're used to test adapters and controllers that depend on singleton PMs\r\n * \r\n * Usage pattern (in tests):\r\n * ```typescript\r\n * // In a test file\r\n * const mockPM = makeMockExampleSingletonPM(appObjects);\r\n * const addViewSpy = jest.spyOn(mockPM, 'addView');\r\n * \r\n * // Test the component that uses the singleton PM\r\n * adapter.subscribe(appObjects, setVM);\r\n * \r\n * // Verify the PM method was called correctly\r\n * expect(addViewSpy).toHaveBeenCalledWith(setVM);\r\n * ```\r\n */\r\n\r\nimport { AppObject, AppObjectRepo } from \"../../AppObject\";\r\nimport { ExampleSingletonPM } from \"../PMs/ExampleSingletonPM\";\r\n\r\n/**\r\n * Mock implementation of ExampleSingletonPM for testing\r\n * Provides simplified implementations of required methods\r\n */\r\nexport class MockExampleSingletonPM extends ExampleSingletonPM {\r\n /**\r\n * Simplified implementation that always returns true\r\n * This avoids the need to implement real comparison logic in tests\r\n */\r\n vmsAreEqual = () => {\r\n return true;\r\n };\r\n\r\n constructor(appObject: AppObject) {\r\n super(appObject, ExampleSingletonPM.type);\r\n }\r\n}\r\n\r\n/**\r\n * Helper function to create and register a MockExampleSingletonPM\r\n * Returns the created mock for use in tests\r\n * \r\n * @param appObjects The AppObjectRepo to register the mock with\r\n * @returns A new MockExampleSingletonPM instance\r\n */\r\nexport function makeMockExampleSingletonPM(appObjects: AppObjectRepo) {\r\n return new MockExampleSingletonPM(\r\n appObjects.getOrCreate(\"MockExampleSingletonPM\")\r\n );\r\n}\r\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MockToggleExampleBooleanUC.ts
|
|
3
|
+
*
|
|
4
|
+
* This file demonstrates how to implement a mock singleton UC for testing.
|
|
5
|
+
* Mock singleton UCs extend the real UC classes and provide helper functions
|
|
6
|
+
* to create and register them as singletons for tests.
|
|
7
|
+
*
|
|
8
|
+
* Key concepts:
|
|
9
|
+
* - Mock singleton UCs extend the real UC classes
|
|
10
|
+
* - They override methods with test implementations
|
|
11
|
+
* - They register themselves as singletons just like the real UCs
|
|
12
|
+
* - They include helper functions to create them in tests
|
|
13
|
+
*
|
|
14
|
+
* Usage pattern (in tests):
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // In a test file
|
|
17
|
+
* const mockUC = makeMockToggleExampleBooleanUC(appObject);
|
|
18
|
+
* const spy = jest.spyOn(mockUC, 'toggleExampleBoolean');
|
|
19
|
+
*
|
|
20
|
+
* // Call the function that should use the UC
|
|
21
|
+
* toggleExampleBoolean(appObjects);
|
|
22
|
+
*
|
|
23
|
+
* // Verify the UC method was called correctly
|
|
24
|
+
* expect(spy).toHaveBeenCalled();
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
import { ToggleExampleBooleanUC } from "../UCs/ToggleExampleBooleanUC";
|
|
28
|
+
/**
|
|
29
|
+
* Mock implementation of ToggleExampleBooleanUC for testing
|
|
30
|
+
* Provides a no-op implementation of toggleExampleBoolean that can be spied on in tests
|
|
31
|
+
*/
|
|
32
|
+
export class MockToggleExampleBooleanUC extends ToggleExampleBooleanUC {
|
|
33
|
+
constructor(appObject) {
|
|
34
|
+
super(appObject, ToggleExampleBooleanUC.type);
|
|
35
|
+
/**
|
|
36
|
+
* Mock implementation that does nothing
|
|
37
|
+
* In tests, this can be replaced with a Jest spy to track calls
|
|
38
|
+
*/
|
|
39
|
+
this.toggleExampleBoolean = () => { };
|
|
40
|
+
// Register as a singleton just like the real UC
|
|
41
|
+
this.appObjects.registerSingleton(this);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Helper factory function to create a mock ToggleExampleBooleanUC
|
|
46
|
+
* @param appObject The AppObject to attach the UC to
|
|
47
|
+
* @returns A new MockToggleExampleBooleanUC instance
|
|
48
|
+
*/
|
|
49
|
+
export function makeMockToggleExampleBooleanUC(appObject) {
|
|
50
|
+
return new MockToggleExampleBooleanUC(appObject);
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=MockToggleExampleBooleanUC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MockToggleExampleBooleanUC.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Mocks/MockToggleExampleBooleanUC.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAEvE;;;GAGG;AACH,MAAM,OAAO,0BAA2B,SAAQ,sBAAsB;IAOpE,YAAY,SAAoB;QAC9B,KAAK,CAAC,SAAS,EAAE,sBAAsB,CAAC,IAAI,CAAC,CAAC;QAPhD;;;WAGG;QACH,yBAAoB,GAAG,GAAS,EAAE,GAAE,CAAC,CAAC;QAIpC,gDAAgD;QAChD,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,8BAA8B,CAC5C,SAAoB;IAEpB,OAAO,IAAI,0BAA0B,CAAC,SAAS,CAAC,CAAC;AACnD,CAAC","sourcesContent":["/**\r\n * MockToggleExampleBooleanUC.ts\r\n * \r\n * This file demonstrates how to implement a mock singleton UC for testing.\r\n * Mock singleton UCs extend the real UC classes and provide helper functions\r\n * to create and register them as singletons for tests.\r\n * \r\n * Key concepts:\r\n * - Mock singleton UCs extend the real UC classes\r\n * - They override methods with test implementations\r\n * - They register themselves as singletons just like the real UCs\r\n * - They include helper functions to create them in tests\r\n * \r\n * Usage pattern (in tests):\r\n * ```typescript\r\n * // In a test file\r\n * const mockUC = makeMockToggleExampleBooleanUC(appObject);\r\n * const spy = jest.spyOn(mockUC, 'toggleExampleBoolean');\r\n * \r\n * // Call the function that should use the UC\r\n * toggleExampleBoolean(appObjects);\r\n * \r\n * // Verify the UC method was called correctly\r\n * expect(spy).toHaveBeenCalled();\r\n * ```\r\n */\r\n\r\nimport { AppObject } from \"../../AppObject\";\r\nimport { ToggleExampleBooleanUC } from \"../UCs/ToggleExampleBooleanUC\";\r\n\r\n/**\r\n * Mock implementation of ToggleExampleBooleanUC for testing\r\n * Provides a no-op implementation of toggleExampleBoolean that can be spied on in tests\r\n */\r\nexport class MockToggleExampleBooleanUC extends ToggleExampleBooleanUC {\r\n /**\r\n * Mock implementation that does nothing\r\n * In tests, this can be replaced with a Jest spy to track calls\r\n */\r\n toggleExampleBoolean = (): void => {};\r\n\r\n constructor(appObject: AppObject) {\r\n super(appObject, ToggleExampleBooleanUC.type);\r\n // Register as a singleton just like the real UC\r\n this.appObjects.registerSingleton(this);\r\n }\r\n}\r\n\r\n/**\r\n * Helper factory function to create a mock ToggleExampleBooleanUC\r\n * @param appObject The AppObject to attach the UC to\r\n * @returns A new MockToggleExampleBooleanUC instance\r\n */\r\nexport function makeMockToggleExampleBooleanUC(\r\n appObject: AppObject\r\n): MockToggleExampleBooleanUC {\r\n return new MockToggleExampleBooleanUC(appObject);\r\n}\r\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/Mocks/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC","sourcesContent":["export * from \"./MockEditExampleStringUC\";\r\nexport * from \"./MockExamplePM\";\r\nexport * from \"./MockExampleSingletonPM\";\r\nexport * from \"./MockToggleExampleBooleanUC\";\r\n"]}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExamplePM.ts
|
|
3
|
+
*
|
|
4
|
+
* This file demonstrates how to implement a Presentation Manager (PM) component.
|
|
5
|
+
* PMs are responsible for transforming entity data into view models (VMs) for the UI.
|
|
6
|
+
* They observe entities for changes and update their views when data changes.
|
|
7
|
+
*
|
|
8
|
+
* Key concepts:
|
|
9
|
+
* - PMs extend AppObjectPM<VM> where VM is the view model type
|
|
10
|
+
* - They observe entities and transform entity data into view models
|
|
11
|
+
* - They notify UI components (views) when view models change
|
|
12
|
+
* - Each PM instance is associated with a specific AppObject
|
|
13
|
+
*
|
|
14
|
+
* Usage pattern:
|
|
15
|
+
* 1. Get a PM instance using getById
|
|
16
|
+
* 2. Register UI components as views using addView(callback)
|
|
17
|
+
* 3. PM will call the view callbacks with updated view models when entities change
|
|
18
|
+
* 4. Remove UI components with removeView(callback) when they're unmounted
|
|
19
|
+
*/
|
|
20
|
+
import { AppObjectPM } from "../../AppObject";
|
|
21
|
+
import { ExampleEntity } from "../Entities/ExampleEntity";
|
|
22
|
+
/**
|
|
23
|
+
* ExamplePM transforms ExampleEntity data into a simple string view model.
|
|
24
|
+
* Abstract class provides the interface and static helper methods.
|
|
25
|
+
*/
|
|
26
|
+
export class ExamplePM extends AppObjectPM {
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves an ExamplePM by its parent AppObject's ID
|
|
29
|
+
* @param id The ID of the parent AppObject
|
|
30
|
+
* @param appObjects The AppObjectRepo to search in
|
|
31
|
+
* @returns The ExamplePM component or undefined if not found
|
|
32
|
+
*/
|
|
33
|
+
static getById(id, appObjects) {
|
|
34
|
+
return appObjects.get(id)?.getComponent(ExamplePM.type);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Unique type identifier for this component */
|
|
38
|
+
ExamplePM.type = "ExamplePMType";
|
|
39
|
+
/**
|
|
40
|
+
* Factory function to create a new ExamplePM
|
|
41
|
+
* @param appObject The AppObject to attach the PM to
|
|
42
|
+
* @returns A new ExamplePM instance
|
|
43
|
+
*/
|
|
44
|
+
export function makeExamplePM(appObject) {
|
|
45
|
+
return new ExamplePMImp(appObject);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Concrete implementation of ExamplePM
|
|
49
|
+
* This private class handles the actual implementation details
|
|
50
|
+
*/
|
|
51
|
+
class ExamplePMImp extends ExamplePM {
|
|
52
|
+
/**
|
|
53
|
+
* Gets the ExampleEntity from the same AppObject
|
|
54
|
+
* Uses getCachedLocalComponent for efficient repeated access
|
|
55
|
+
*/
|
|
56
|
+
get exampleEntity() {
|
|
57
|
+
return this.getCachedLocalComponent(ExampleEntity.type);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Compares two view models to determine if they're equal
|
|
61
|
+
* Used to avoid unnecessary view updates when values haven't changed
|
|
62
|
+
*/
|
|
63
|
+
vmsAreEqual(a, b) {
|
|
64
|
+
return a === b;
|
|
65
|
+
}
|
|
66
|
+
constructor(appObject) {
|
|
67
|
+
super(appObject, ExamplePM.type);
|
|
68
|
+
/**
|
|
69
|
+
* Handler for entity change events
|
|
70
|
+
* Transforms entity data into a view model and updates views
|
|
71
|
+
*/
|
|
72
|
+
this.onEntityChange = () => {
|
|
73
|
+
if (!this.exampleEntity)
|
|
74
|
+
return;
|
|
75
|
+
// In this simple case, our view model is just the string property value
|
|
76
|
+
this.doUpdateView(this.exampleEntity.aStringProperty);
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Cleanup method called when the PM is being disposed
|
|
80
|
+
* Removes any observers to prevent memory leaks
|
|
81
|
+
*/
|
|
82
|
+
this.dispose = () => {
|
|
83
|
+
super.dispose();
|
|
84
|
+
this.exampleEntity?.removeChangeObserver(this.onEntityChange);
|
|
85
|
+
};
|
|
86
|
+
// Register as an observer of the entity to receive change notifications
|
|
87
|
+
this.exampleEntity?.addChangeObserver(this.onEntityChange);
|
|
88
|
+
// Call the change handler initially to set up the initial view model
|
|
89
|
+
this.onEntityChange();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=ExamplePM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExamplePM.js","sourceRoot":"","sources":["../../../../src/ExampleFeature/PMs/ExamplePM.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAa,WAAW,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D;;;GAGG;AACH,MAAM,OAAgB,SAAU,SAAQ,WAAmB;IAIzD;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAAC,EAAU,EAAE,UAAyB;QAClD,OAAO,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,YAAY,CAAY,SAAS,CAAC,IAAI,CAAC,CAAC;IACrE,CAAC;;AAXD,gDAAgD;AAChC,cAAI,GAAG,eAAe,CAAC;AAazC;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,SAAoB;IAChD,OAAO,IAAI,YAAY,CAAC,SAAS,CAAC,CAAC;AACrC,CAAC;AAED;;;GAGG;AACH,MAAM,YAAa,SAAQ,SAAS;IAClC;;;OAGG;IACH,IAAY,aAAa;QACvB,OAAO,IAAI,CAAC,uBAAuB,CAAgB,aAAa,CAAC,IAAI,CAAC,CAAC;IACzE,CAAC;IAED;;;OAGG;IACH,WAAW,CAAC,CAAS,EAAE,CAAS;QAC9B,OAAO,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC;IAsBD,YAAY,SAAoB;QAC9B,KAAK,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;QArBnC;;;WAGG;QACH,mBAAc,GAAG,GAAG,EAAE;YACpB,IAAI,CAAC,IAAI,CAAC,aAAa;gBAAE,OAAO;YAEhC,wEAAwE;YACxE,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;QACxD,CAAC,CAAC;QAEF;;;WAGG;QACH,YAAO,GAAG,GAAS,EAAE;YACnB,KAAK,CAAC,OAAO,EAAE,CAAC;YAChB,IAAI,CAAC,aAAa,EAAE,oBAAoB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAChE,CAAC,CAAC;QAKA,wEAAwE;QACxE,IAAI,CAAC,aAAa,EAAE,iBAAiB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAE3D,qEAAqE;QACrE,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;CACF","sourcesContent":["/**\r\n * ExamplePM.ts\r\n * \r\n * This file demonstrates how to implement a Presentation Manager (PM) component.\r\n * PMs are responsible for transforming entity data into view models (VMs) for the UI.\r\n * They observe entities for changes and update their views when data changes.\r\n * \r\n * Key concepts:\r\n * - PMs extend AppObjectPM<VM> where VM is the view model type\r\n * - They observe entities and transform entity data into view models\r\n * - They notify UI components (views) when view models change\r\n * - Each PM instance is associated with a specific AppObject\r\n * \r\n * Usage pattern:\r\n * 1. Get a PM instance using getById\r\n * 2. Register UI components as views using addView(callback)\r\n * 3. PM will call the view callbacks with updated view models when entities change\r\n * 4. Remove UI components with removeView(callback) when they're unmounted\r\n */\r\n\r\nimport { AppObject, AppObjectPM, AppObjectRepo } from \"../../AppObject\";\r\nimport { ExampleEntity } from \"../Entities/ExampleEntity\";\r\n\r\n/**\r\n * ExamplePM transforms ExampleEntity data into a simple string view model.\r\n * Abstract class provides the interface and static helper methods.\r\n */\r\nexport abstract class ExamplePM extends AppObjectPM<string> {\r\n /** Unique type identifier for this component */\r\n static readonly type = \"ExamplePMType\";\r\n\r\n /**\r\n * Retrieves an ExamplePM by its parent AppObject's ID\r\n * @param id The ID of the parent AppObject\r\n * @param appObjects The AppObjectRepo to search in\r\n * @returns The ExamplePM component or undefined if not found\r\n */\r\n static getById(id: string, appObjects: AppObjectRepo) {\r\n return appObjects.get(id)?.getComponent<ExamplePM>(ExamplePM.type);\r\n }\r\n}\r\n\r\n/**\r\n * Factory function to create a new ExamplePM\r\n * @param appObject The AppObject to attach the PM to\r\n * @returns A new ExamplePM instance\r\n */\r\nexport function makeExamplePM(appObject: AppObject): ExamplePM {\r\n return new ExamplePMImp(appObject);\r\n}\r\n\r\n/**\r\n * Concrete implementation of ExamplePM\r\n * This private class handles the actual implementation details\r\n */\r\nclass ExamplePMImp extends ExamplePM {\r\n /**\r\n * Gets the ExampleEntity from the same AppObject\r\n * Uses getCachedLocalComponent for efficient repeated access\r\n */\r\n private get exampleEntity() {\r\n return this.getCachedLocalComponent<ExampleEntity>(ExampleEntity.type);\r\n }\r\n\r\n /**\r\n * Compares two view models to determine if they're equal\r\n * Used to avoid unnecessary view updates when values haven't changed\r\n */\r\n vmsAreEqual(a: string, b: string): boolean {\r\n return a === b;\r\n }\r\n\r\n /**\r\n * Handler for entity change events\r\n * Transforms entity data into a view model and updates views\r\n */\r\n onEntityChange = () => {\r\n if (!this.exampleEntity) return;\r\n\r\n // In this simple case, our view model is just the string property value\r\n this.doUpdateView(this.exampleEntity.aStringProperty);\r\n };\r\n\r\n /**\r\n * Cleanup method called when the PM is being disposed\r\n * Removes any observers to prevent memory leaks\r\n */\r\n dispose = (): void => {\r\n super.dispose();\r\n this.exampleEntity?.removeChangeObserver(this.onEntityChange);\r\n };\r\n\r\n constructor(appObject: AppObject) {\r\n super(appObject, ExamplePM.type);\r\n\r\n // Register as an observer of the entity to receive change notifications\r\n this.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}\r\n"]}
|