Skip to content

Commit e69954d

Browse files
authored
scheduling an update when an instance is unlocked (#833)
* scheduling an update when an instance is unlocked * checking flag dirty while locked
1 parent e6a6530 commit e69954d

2 files changed

Lines changed: 105 additions & 39 deletions

File tree

src/views/component-viewer/component-viewer-main.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ import { componentViewerLogger } from '../../logger';
2323
import type { ScvdGuiInterface } from './model/scvd-gui-interface';
2424
import { perf, parsePerf } from './stats-config';
2525

26-
export type fifoUpdateReason = 'sessionChanged' | 'refreshTimer' | 'stackTrace' | 'stackItemChanged';
26+
export type UpdateReason = 'sessionChanged' | 'refreshTimer' | 'stackTrace' | 'stackItemChanged' | 'unlockingInstance';
2727

2828
export interface ComponentViewerInstancesWrapper {
2929
componentViewerInstance: ComponentViewerInstance;
3030
lockState: boolean;
3131
sessionId: string; // ID of the debug session this instance belongs to, used to clear instances when session changes
32+
dirtyWhileLocked: boolean; // Flag to indicate if an update was attempted while instance was locked, used to trigger an update when instance is unlocked
3233
}
3334

3435
export class ComponentViewer {
@@ -82,9 +83,10 @@ export class ComponentViewer {
8283
}
8384

8485
protected handleLockInstance(node: ScvdGuiInterface): void {
86+
let shouldTriggerUpdate: boolean = false; // Unlocking a node should trigger an update
8587
const instance = this._instances.find((inst) => {
8688
const guiTree = inst.componentViewerInstance.getGuiTree();
87-
if (!guiTree) {
89+
if (!guiTree || guiTree.length === 0) {
8890
return false;
8991
}
9092
// Check if the node belongs to this instance. We only care about parent nodes, as locking/unlocking a child node is not supported,
@@ -94,15 +96,22 @@ export class ComponentViewer {
9496
if (!instance) {
9597
return;
9698
}
99+
if (instance.lockState === true) {
100+
shouldTriggerUpdate = true;
101+
}
97102
instance.lockState = !instance.lockState;
98103
componentViewerLogger.info(`Component Viewer: Instance lock state changed to ${instance.lockState}`);
99104
// If instance is locked, set isLocked flag to true for root nodes
100105
const guiTree = instance.componentViewerInstance.getGuiTree();
101-
if (!guiTree) {
106+
if (!guiTree || guiTree.length === 0) {
102107
return;
103108
}
104109
const rootNode: ScvdGuiInterface = guiTree[0];
105110
rootNode.isLocked = instance.lockState;
111+
if (shouldTriggerUpdate && instance.dirtyWhileLocked) {
112+
this.schedulePendingUpdate('unlockingInstance');
113+
instance.dirtyWhileLocked = false;
114+
}
106115
this._componentViewerTreeDataProvider?.refresh();
107116
}
108117

@@ -143,6 +152,7 @@ export class ComponentViewer {
143152
componentViewerInstance: instance,
144153
lockState: false,
145154
sessionId: session.session.id,
155+
dirtyWhileLocked: false
146156
})));
147157
}
148158

@@ -247,7 +257,7 @@ export class ComponentViewer {
247257
this._activeSession = session;
248258
}
249259

250-
private schedulePendingUpdate(updateReason: fifoUpdateReason): void {
260+
private schedulePendingUpdate(updateReason: UpdateReason): void {
251261
this._pendingUpdate = true;
252262
if (this._pendingUpdateTimer) {
253263
clearTimeout(this._pendingUpdateTimer);
@@ -258,7 +268,7 @@ export class ComponentViewer {
258268
}, ComponentViewer.pendingUpdateDelayMs);
259269
}
260270

261-
private async runUpdate(updateReason: fifoUpdateReason): Promise<void> {
271+
private async runUpdate(updateReason: UpdateReason): Promise<void> {
262272
if (this._runningUpdate) {
263273
return;
264274
}
@@ -293,7 +303,7 @@ export class ComponentViewer {
293303
return true;
294304
}
295305

296-
private async updateInstances(updateReason: fifoUpdateReason): Promise<void> {
306+
private async updateInstances(updateReason: UpdateReason): Promise<void> {
297307
if (!this._activeSession) {
298308
this._componentViewerTreeDataProvider?.clear();
299309
return;
@@ -323,6 +333,8 @@ export class ComponentViewer {
323333
// Check instance's lock state, skip update if locked
324334
if (!instance.lockState) {
325335
await instance.componentViewerInstance.update();
336+
} else {
337+
instance.dirtyWhileLocked = true;
326338
}
327339
const guiTree = instance.componentViewerInstance.getGuiTree();
328340
if (guiTree) {

0 commit comments

Comments
 (0)