From 27fbc2ea7cc329d9dbc77f8d937eaea961e0547a Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Sat, 3 May 2025 08:01:59 +1000 Subject: [PATCH] [API] Rewrite LGraphCanvas.setGraph for subgraph (#1002) Code search showed no usage. Fixes TS type on LGraph. --- src/LGraphCanvas.ts | 22 +++++++++++----------- src/subgraph/Subgraph.ts | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/LGraphCanvas.ts b/src/LGraphCanvas.ts index 6bf139fc8..f27c1449b 100644 --- a/src/LGraphCanvas.ts +++ b/src/LGraphCanvas.ts @@ -1565,22 +1565,22 @@ export class LGraphCanvas { } /** - * assigns a graph, you can reassign graphs to the same canvas - * @param graph + * Assigns a new graph to this canvas. */ - setGraph(graph: LGraph, skip_clear: boolean): void { - if (this.graph == graph) return + setGraph(newGraph: LGraph | Subgraph): void { + const { graph } = this + if (newGraph === graph) return - if (!skip_clear) this.clear() - - if (!graph && this.graph) { - this.graph.detachCanvas(this) - return + const options = { + bubbles: true, + detail: { newGraph, oldGraph: graph }, } - graph.attachCanvas(this) + this.clear() + newGraph.attachCanvas(this) - this.setDirty(true, true) + this.canvas.dispatchEvent(new CustomEvent("litegraph:set-graph", options)) + this.#dirty() } /** diff --git a/src/subgraph/Subgraph.ts b/src/subgraph/Subgraph.ts index a994b8616..784decf30 100644 --- a/src/subgraph/Subgraph.ts +++ b/src/subgraph/Subgraph.ts @@ -30,12 +30,12 @@ export class Subgraph extends LGraph implements BaseLGraph, Serialisable