mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-29 02:32:18 +00:00
[API] Rewrite LGraphCanvas.setGraph for subgraph (#1002)
Code search showed no usage. Fixes TS type on LGraph.
This commit is contained in:
@@ -1565,22 +1565,22 @@ export class LGraphCanvas {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* assigns a graph, you can reassign graphs to the same canvas
|
* Assigns a new graph to this canvas.
|
||||||
* @param graph
|
|
||||||
*/
|
*/
|
||||||
setGraph(graph: LGraph, skip_clear: boolean): void {
|
setGraph(newGraph: LGraph | Subgraph): void {
|
||||||
if (this.graph == graph) return
|
const { graph } = this
|
||||||
|
if (newGraph === graph) return
|
||||||
|
|
||||||
if (!skip_clear) this.clear()
|
const options = {
|
||||||
|
bubbles: true,
|
||||||
if (!graph && this.graph) {
|
detail: { newGraph, oldGraph: graph },
|
||||||
this.graph.detachCanvas(this)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
graph.attachCanvas(this)
|
this.clear()
|
||||||
|
newGraph.attachCanvas(this)
|
||||||
|
|
||||||
this.setDirty(true, true)
|
this.canvas.dispatchEvent(new CustomEvent("litegraph:set-graph", options))
|
||||||
|
this.#dirty()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -30,12 +30,12 @@ export class Subgraph extends LGraph implements BaseLGraph, Serialisable<Exporte
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
get pathToRootGraph(): readonly [LGraph, ...GraphOrSubgraph[]] {
|
get pathToRootGraph(): readonly [LGraph, ...Subgraph[]] {
|
||||||
return [...this.parents, this]
|
return [...this.parents, this]
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
readonly parents: readonly [LGraph, ...GraphOrSubgraph[]],
|
readonly parents: readonly [LGraph, ...Subgraph[]],
|
||||||
data: ExportedSubgraph,
|
data: ExportedSubgraph,
|
||||||
) {
|
) {
|
||||||
if (!parents.length) throw new Error("Subgraph must have at least one parent")
|
if (!parents.length) throw new Error("Subgraph must have at least one parent")
|
||||||
|
|||||||
Reference in New Issue
Block a user