Skip to content

Commit

Permalink
sheet: keep record of proxy names, display cell triggering proxy cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
hbbio committed May 27, 2024
1 parent 5cea8dd commit 6c8a7aa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<V, NF>;
}

Expand All @@ -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;
}

Expand Down
18 changes: 15 additions & 3 deletions src/sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export class Sheet {
private _gc: Set<number>;

private _proxies: Graph<number>;
private _proxyNames: Record<number, string>;

/**
* @param equality function comparing a new value with previous value for updates
Expand All @@ -141,29 +142,40 @@ export class Sheet {
this._queue = [];
this._proxies = new Graph();
this._proxies.addNode(0);
this._proxyNames = {};
}

// a Sheet has id 0, proxies > 0
get id() {
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<unknown[]>) {
addProxyDependencies(
id: number,
deps: AnyCellArray<unknown[]>,
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 = [];
}

Expand Down

0 comments on commit 6c8a7aa

Please sign in to comment.