|
3 | 3 | * @author Marten Lohstroh <[email protected]> |
4 | 4 | */ |
5 | 5 |
|
| 6 | +import { DebugLogger } from "util"; |
6 | 7 | import {Reaction} from "./reaction"; |
7 | 8 | import type {Sortable, Variable} from "./types"; |
8 | | -import {Log} from "./util"; |
| 9 | +import {GraphDebugLogger, Log} from "./util"; |
| 10 | + |
| 11 | + |
| 12 | +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/no-explicit-any |
| 13 | +const debugLoggerDecorator = (target: any, context: ClassMethodDecoratorContext) => { |
| 14 | + if (context.kind === "method") { |
| 15 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 16 | + return function (this: any, ...args: unknown[]): any { |
| 17 | + console.log(`${context.name.toString()} is called.`); |
| 18 | + console.log(`Tracestack: ${(new Error()).stack}`); |
| 19 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access |
| 20 | + return target.call(this, ...args); |
| 21 | + } |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +declare global { |
| 26 | + var graphDebugLogger: GraphDebugLogger | undefined; |
| 27 | + var recording: boolean; |
| 28 | +} |
| 29 | + |
| 30 | +const debugHelper = (): void => { |
| 31 | + if (globalThis.recording) { return; } |
| 32 | + globalThis.recording = true; |
| 33 | + if (globalThis.graphDebugLogger == null) { |
| 34 | + return |
| 35 | + } |
| 36 | + |
| 37 | + const err = new Error(); |
| 38 | + console.log(err.stack); |
| 39 | + const debuglogger = globalThis.graphDebugLogger; |
| 40 | + debuglogger.capture(err); |
| 41 | + globalThis.recording = false; |
| 42 | +}; |
9 | 43 |
|
10 | 44 | /** |
11 | 45 | * A generic precedence graph. |
@@ -53,6 +87,7 @@ export class PrecedenceGraph<T> { |
53 | 87 | * @param node |
54 | 88 | */ |
55 | 89 | addNode(node: T): void { |
| 90 | + debugHelper(); |
56 | 91 | if (!this.adjacencyMap.has(node)) { |
57 | 92 | this.adjacencyMap.set(node, new Set()); |
58 | 93 | } |
@@ -143,6 +178,8 @@ export class PrecedenceGraph<T> { |
143 | 178 | * @param downstream The node at which the directed edge ends. |
144 | 179 | */ |
145 | 180 | addEdge(upstream: T, downstream: T): void { |
| 181 | + debugHelper(); |
| 182 | + console.log("!"); |
146 | 183 | const deps = this.adjacencyMap.get(downstream); |
147 | 184 | if (deps == null) { |
148 | 185 | this.adjacencyMap.set(downstream, new Set([upstream])); |
|
0 commit comments