From 6c8a7aafe9ea1ba33adfa9fad8d2567cf9834a3e Mon Sep 17 00:00:00 2001 From: Henri Binsztok <808274+hbbio@users.noreply.github.com> Date: Mon, 27 May 2024 14:11:04 +0800 Subject: [PATCH] sheet: keep record of proxy names, display cell triggering proxy cycle --- src/proxy.ts | 6 +++--- src/sheet.ts | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/proxy.ts b/src/proxy.ts index f220d8c..db164e1 100644 --- a/src/proxy.ts +++ b/src/proxy.ts @@ -34,7 +34,7 @@ export class SheetProxy { this.working = new Working(sh.working); this.errors = new CellErrors(sh.errors); if (name) this._name = name; - this._id = sh.addProxy(); + this._id = sh.addProxy(name); } // a Sheet has id 0, proxies > 0 @@ -213,7 +213,7 @@ export class SheetProxy { // @ts-expect-error conflict with overloaded definitions const cell = this._sheet.map(dependencies, computeFn, name, this, noFail); this._list.push(cell); - this._sheet.addProxyDependencies(this._id, dependencies); + this._sheet.addProxyDependencies(this._id, dependencies, cell.id); return cell as MapCell; } @@ -239,7 +239,7 @@ export class SheetProxy { noFail ); this._list.push(cell); - this._sheet.addProxyDependencies(this._id, dependencies); + this._sheet.addProxyDependencies(this._id, dependencies, cell.id); return cell; } diff --git a/src/sheet.ts b/src/sheet.ts index e7f6906..a51a353 100644 --- a/src/sheet.ts +++ b/src/sheet.ts @@ -118,6 +118,7 @@ export class Sheet { private _gc: Set; private _proxies: Graph; + private _proxyNames: Record; /** * @param equality function comparing a new value with previous value for updates @@ -141,6 +142,7 @@ export class Sheet { this._queue = []; this._proxies = new Graph(); this._proxies.addNode(0); + this._proxyNames = {}; } // a Sheet has id 0, proxies > 0 @@ -148,22 +150,32 @@ export class Sheet { return 0; } - addProxy() { + addProxy(name?: string) { // keeping 0 as original Sheet this[proxies]++; const id = this[proxies]; this._proxies.addNode(id); + this._proxyNames[id] = name; return id; } addProxyEdge(from: number, to: number) { this._proxies.addEdge(from, to); } - addProxyDependencies(id: number, deps: AnyCellArray) { + addProxyDependencies( + id: number, + deps: AnyCellArray, + cell: number + ) { for (const dep of deps) if (dep._proxy !== id) this.addProxyEdge(dep._proxy, id); if (this._proxies.topologicalSort() === null) - this.debug(undefined, "proxy cycle", { proxy: id, deps }); + this.debug(undefined, "proxy cycle", { + proxy: id, + cell, + name: this._proxyNames[id], + deps + }); this._queue = []; }