Skip to content

Commit e877de2

Browse files
committed
Add docs to ChangedECInstanceCache
1 parent 582a2a2 commit e877de2

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

packages/changed-elements-react/src/api/ChangedECInstanceCache.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,62 @@ export class ChangedECInstanceCache {
1717
this._cache = new Map<Id64String, ChangedECInstance>();
1818
}
1919

20-
private _getKey(instance: ChangedECInstance): string{
20+
/**
21+
* Creates a key for the ChangedECInstance based on its Id and Class Id
22+
* @param instance ChangedECInstance to create a key for
23+
* @returns Key string for the ChangedECInstance in the cache, formatted as "instanceId:classId"
24+
*/
25+
private _getKey(instance: ChangedECInstance): string {
2126
return `${instance.ECInstanceId}:${instance.ECClassId}`;
2227
}
2328

29+
/**
30+
* Initializes the cache with the given ChangedECInstances
31+
* The cache will be cleared before adding the instances
32+
* @param instances
33+
*/
2434
public initialize(instances: ChangedECInstance[]): void {
2535
this._cache.clear();
2636
for (const instance of instances) {
2737
this._cache.set(this._getKey(instance), instance);
2838
}
2939
}
3040

41+
/**
42+
* Add instance to the cache
43+
* @param instance ChangedECInstance to add to the cache
44+
*/
3145
public add(instance: ChangedECInstance): void {
3246
this._cache.set(this._getKey(instance), instance);
3347
}
3448

49+
/**
50+
* Gets the ChangedECInstance from the cache based on the instanceId and classId
51+
* @param instanceId Id of the instance to get
52+
* @param classId Class Id of the instance to get
53+
* @returns ChangedECInstance if found, undefined otherwise
54+
*/
3555
public get(instanceId: Id64String, classId: Id64String): ChangedECInstance | undefined {
3656
const key = `${instanceId}:${classId}`;
3757
return this._cache.get(key);
3858
}
3959

60+
/**
61+
* Returns whether the cache contains the ChangedECInstance with the given instanceId and classId
62+
* @param instanceId Id of the instance to check
63+
* @param classId Class Id of the instance to check
64+
* @returns true if the cache contains the instance, false otherwise
65+
*/
4066
public has(instanceId: Id64String, classId: Id64String): boolean {
4167
const key = `${instanceId}:${classId}`;
4268
return this._cache.has(key);
4369
}
4470

71+
/**
72+
* Similar to get, but uses the ChangedElementEntry to find the instance
73+
* @param entry ChangedElementEntry to use for finding the instance
74+
* @returns ChangedECInstance if found, undefined otherwise
75+
*/
4576
public getFromEntry(entry: ChangedElementEntry): ChangedECInstance | undefined {
4677
return this.get(entry.id, entry.classId);
4778
}
@@ -62,6 +93,9 @@ export class ChangedECInstanceCache {
6293
return instances;
6394
}
6495

96+
/**
97+
* Clears the cache of all ChangedECInstances
98+
*/
6599
public clear(): void {
66100
this._cache.clear();
67101
}

0 commit comments

Comments
 (0)