mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-11 01:02:01 +03:00
dedupe evaluation logic in Workspace
This commit is contained in:
parent
edfa55e4dc
commit
3a657a2d5d
1 changed files with 7 additions and 9 deletions
|
|
@ -32,8 +32,7 @@ export class Workspace {
|
||||||
|
|
||||||
constructor(private engine: SumEngine, private sheets: () => SheetSource[]) {}
|
constructor(private engine: SumEngine, private sheets: () => SheetSource[]) {}
|
||||||
|
|
||||||
/** Evaluate a sheet as the user's active/open document — refs resolve live. */
|
private doEvaluate(sheetId: string, text: string): LineResult[] {
|
||||||
evaluateSheet(sheetId: string, text: string): LineResult[] {
|
|
||||||
this.resolving.add(sheetId);
|
this.resolving.add(sheetId);
|
||||||
try {
|
try {
|
||||||
return this.engine.evaluateDocument(text, (sheet, key) => this.resolveXRef(sheet, key));
|
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[] {
|
getCachedResults(sheet: SheetSource): LineResult[] {
|
||||||
return this.exportsFor(sheet).results;
|
return this.exportsFor(sheet).results;
|
||||||
}
|
}
|
||||||
|
|
@ -145,13 +149,7 @@ export class Workspace {
|
||||||
private exportsFor(sheet: SheetSource): SheetExports {
|
private exportsFor(sheet: SheetSource): SheetExports {
|
||||||
const cached = this.cache.get(sheet.id);
|
const cached = this.cache.get(sheet.id);
|
||||||
if (cached) return cached;
|
if (cached) return cached;
|
||||||
this.resolving.add(sheet.id);
|
const results = this.doEvaluate(sheet.id, sheet.text);
|
||||||
let results: LineResult[];
|
|
||||||
try {
|
|
||||||
results = this.engine.evaluateDocument(sheet.text, (s, k) => this.resolveXRef(s, k));
|
|
||||||
} finally {
|
|
||||||
this.resolving.delete(sheet.id);
|
|
||||||
}
|
|
||||||
const vars = new Map<string, Value>();
|
const vars = new Map<string, Value>();
|
||||||
for (const r of results) {
|
for (const r of results) {
|
||||||
if (r.assign && r.value) vars.set(r.assign, r.value);
|
if (r.assign && r.value) vars.set(r.assign, r.value);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue