refactor: add deactivate() and prepareForSave() to ChangeTracker

- deactivate(): unified freeze step combining captureCanvasState() +
  store(), called when a workflow goes inactive
- prepareForSave(): save-path API that flushes canvas state only for the
  active workflow (no-op for inactive, whose state was frozen by deactivate)
This commit is contained in:
jaeone94
2026-04-02 10:33:06 +09:00
parent 517f7a3d8b
commit fa16f3de74

View File

@@ -91,6 +91,26 @@ export class ChangeTracker {
this.subgraphState = { navigation }
}
/**
* Freeze this tracker's state before the workflow goes inactive.
* Captures the final canvas state + viewport/outputs.
* Called exactly once when switching away from this workflow.
*/
deactivate() {
this.captureCanvasState()
this.store()
}
/**
* Ensure activeState is up-to-date for persistence.
* Active workflow: flushes canvas → activeState.
* Inactive workflow: no-op (activeState was frozen by deactivate()).
*/
prepareForSave() {
const isActive = useWorkflowStore().activeWorkflow?.changeTracker === this
if (isActive) this.captureCanvasState()
}
restore() {
if (this.ds) {
app.canvas.ds.scale = this.ds.scale