From 3a657a2d5ddb22e20b9af9c79ebc088238833ba1 Mon Sep 17 00:00:00 2001 From: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> Date: Sun, 9 Aug 2026 15:57:25 +0300 Subject: [PATCH] dedupe evaluation logic in Workspace --- src/workspace.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/workspace.ts b/src/workspace.ts index 08198f8..c6bb6a1 100644 --- a/src/workspace.ts +++ b/src/workspace.ts @@ -32,8 +32,7 @@ export class Workspace { constructor(private engine: SumEngine, private sheets: () => SheetSource[]) {} - /** Evaluate a sheet as the user's active/open document — refs resolve live. */ - evaluateSheet(sheetId: string, text: string): LineResult[] { + private doEvaluate(sheetId: string, text: string): LineResult[] { this.resolving.add(sheetId); try { return this.engine.evaluateDocument(text, (sheet, key) => this.resolveXRef(sheet, key)); @@ -42,6 +41,11 @@ export class Workspace { } } + /** Evaluate a sheet as the user's active/open document — refs resolve live. */ + evaluateSheet(sheetId: string, text: string): LineResult[] { + return this.doEvaluate(sheetId, text); + } + getCachedResults(sheet: SheetSource): LineResult[] { return this.exportsFor(sheet).results; } @@ -145,13 +149,7 @@ export class Workspace { private exportsFor(sheet: SheetSource): SheetExports { const cached = this.cache.get(sheet.id); if (cached) return cached; - this.resolving.add(sheet.id); - let results: LineResult[]; - try { - results = this.engine.evaluateDocument(sheet.text, (s, k) => this.resolveXRef(s, k)); - } finally { - this.resolving.delete(sheet.id); - } + const results = this.doEvaluate(sheet.id, sheet.text); const vars = new Map(); for (const r of results) { if (r.assign && r.value) vars.set(r.assign, r.value);