Skip to content

Commit ada0a0d

Browse files
committed
refactor: move open branch state storage to static scope
1 parent b1dc4c2 commit ada0a0d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

QualityControl/public/object/ObjectTree.class.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ import { StorageKeysEnum } from '../common/enums/storageKeys.enum.js';
2323
export default class ObjectTree extends Observable {
2424
static _indexIncrementCount = 0;
2525

26+
/**
27+
* A shared storage instance for open branch states.
28+
* @type {BrowserStorage}
29+
*/
30+
static _openBranchStateStorage = new BrowserStorage(StorageKeysEnum.OBJECT_TREE_OPEN_BRANCH_STATE);
31+
2632
/**
2733
* Instantiate tree with a root node called `name`, empty by default
2834
* @param {string} name - root name
@@ -32,7 +38,6 @@ export default class ObjectTree extends Observable {
3238
super();
3339
this._index = ObjectTree._indexIncrementCount++;
3440
this.focusedNode = null;
35-
this.openBranchStateStorage = new BrowserStorage(StorageKeysEnum.OBJECT_TREE_OPEN_BRANCH_STATE);
3641
this.initTree(name, parent);
3742
}
3843

@@ -258,7 +263,7 @@ export default class ObjectTree extends Observable {
258263
const session = sessionService.get();
259264
const key = session.personid.toString();
260265
// We traverse the path to reach the parent branch of this node
261-
let branchState = this.openBranchStateStorage.getLocalItem(key) ?? {};
266+
let branchState = ObjectTree._openBranchStateStorage.getLocalItem(key) ?? {};
262267
for (let i = 0; i < this.path.length - 1; i++) {
263268
branchState = branchState[this.path[i]];
264269
if (!branchState) {
@@ -299,7 +304,7 @@ export default class ObjectTree extends Observable {
299304
}
300305
const session = sessionService.get();
301306
const key = session.personid.toString();
302-
const data = this.openBranchStateStorage.getLocalItem(key) ?? {};
307+
const data = ObjectTree._openBranchStateStorage.getLocalItem(key) ?? {};
303308
// We traverse the path to reach the parent branch of this node
304309
let branchState = data;
305310
for (let i = 0; i < this.path.length - 1; i++) {
@@ -317,11 +322,11 @@ export default class ObjectTree extends Observable {
317322
}
318323
if (this.open) {
319324
this._markExpandedBranchesRecursive(branchState, this);
320-
this.openBranchStateStorage.setLocalItem(key, data);
325+
ObjectTree._openBranchStateStorage.setLocalItem(key, data);
321326
} else if (branchState[this.name]) {
322327
// Deleting from `branchState` directly updates the `data` object
323328
delete branchState[this.name];
324-
this.openBranchStateStorage.setLocalItem(key, data);
329+
ObjectTree._openBranchStateStorage.setLocalItem(key, data);
325330
}
326331
}
327332

0 commit comments

Comments
 (0)