From ada0a0de8eaa0e55ada86df12e1936653aa169a8 Mon Sep 17 00:00:00 2001 From: hehoon <100522372+hehoon@users.noreply.github.com> Date: Wed, 21 Jan 2026 12:11:52 +0100 Subject: [PATCH] refactor: move open branch state storage to static scope --- QualityControl/public/object/ObjectTree.class.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/QualityControl/public/object/ObjectTree.class.js b/QualityControl/public/object/ObjectTree.class.js index 5fa9b0869..d08f519c8 100644 --- a/QualityControl/public/object/ObjectTree.class.js +++ b/QualityControl/public/object/ObjectTree.class.js @@ -23,6 +23,12 @@ import { StorageKeysEnum } from '../common/enums/storageKeys.enum.js'; export default class ObjectTree extends Observable { static _indexIncrementCount = 0; + /** + * A shared storage instance for open branch states. + * @type {BrowserStorage} + */ + static _openBranchStateStorage = new BrowserStorage(StorageKeysEnum.OBJECT_TREE_OPEN_BRANCH_STATE); + /** * Instantiate tree with a root node called `name`, empty by default * @param {string} name - root name @@ -32,7 +38,6 @@ export default class ObjectTree extends Observable { super(); this._index = ObjectTree._indexIncrementCount++; this.focusedNode = null; - this.openBranchStateStorage = new BrowserStorage(StorageKeysEnum.OBJECT_TREE_OPEN_BRANCH_STATE); this.initTree(name, parent); } @@ -258,7 +263,7 @@ export default class ObjectTree extends Observable { const session = sessionService.get(); const key = session.personid.toString(); // We traverse the path to reach the parent branch of this node - let branchState = this.openBranchStateStorage.getLocalItem(key) ?? {}; + let branchState = ObjectTree._openBranchStateStorage.getLocalItem(key) ?? {}; for (let i = 0; i < this.path.length - 1; i++) { branchState = branchState[this.path[i]]; if (!branchState) { @@ -299,7 +304,7 @@ export default class ObjectTree extends Observable { } const session = sessionService.get(); const key = session.personid.toString(); - const data = this.openBranchStateStorage.getLocalItem(key) ?? {}; + const data = ObjectTree._openBranchStateStorage.getLocalItem(key) ?? {}; // We traverse the path to reach the parent branch of this node let branchState = data; for (let i = 0; i < this.path.length - 1; i++) { @@ -317,11 +322,11 @@ export default class ObjectTree extends Observable { } if (this.open) { this._markExpandedBranchesRecursive(branchState, this); - this.openBranchStateStorage.setLocalItem(key, data); + ObjectTree._openBranchStateStorage.setLocalItem(key, data); } else if (branchState[this.name]) { // Deleting from `branchState` directly updates the `data` object delete branchState[this.name]; - this.openBranchStateStorage.setLocalItem(key, data); + ObjectTree._openBranchStateStorage.setLocalItem(key, data); } }