MCPcopy Create free account
hub / github.com/Comfy-Org/litegraph.js / constructor

Method constructor

src/subgraph/SubgraphNode.ts:47–114  ·  view source on GitHub ↗
(
    /** The (sub)graph that contains this subgraph instance. */
    override readonly graph: GraphOrSubgraph,
    /** The definition of this subgraph; how its nodes are configured, etc. */
    readonly subgraph: Subgraph,
    instanceData: ExportedSubgraphInstance,
  )

Source from the content-addressed store, hash-verified

45 #eventAbortController = new AbortController()
46
47 constructor(
48 /** The (sub)graph that contains this subgraph instance. */
49 override readonly graph: GraphOrSubgraph,
50 /** The definition of this subgraph; how its nodes are configured, etc. */
51 readonly subgraph: Subgraph,
52 instanceData: ExportedSubgraphInstance,
53 ) {
54 super(subgraph.name, subgraph.id)
55
56 // Update this node when the subgraph input / output slots are changed
57 const subgraphEvents = this.subgraph.events
58 const { signal } = this.#eventAbortController
59
60 subgraphEvents.addEventListener("input-added", (e) => {
61 const subgraphInput = e.detail.input
62 const { name, type } = subgraphInput
63 if (this.inputs.some(i => i.name == name))
64 return
65 const input = this.addInput(name, type)
66
67 this.#addSubgraphInputListeners(subgraphInput, input)
68 }, { signal })
69
70 subgraphEvents.addEventListener("removing-input", (e) => {
71 const widget = e.detail.input._widget
72 if (widget) this.ensureWidgetRemoved(widget)
73
74 this.removeInput(e.detail.index)
75 this.setDirtyCanvas(true, true)
76 }, { signal })
77
78 subgraphEvents.addEventListener("output-added", (e) => {
79 const { name, type } = e.detail.output
80 this.addOutput(name, type)
81 }, { signal })
82
83 subgraphEvents.addEventListener("removing-output", (e) => {
84 this.removeOutput(e.detail.index)
85 this.setDirtyCanvas(true, true)
86 }, { signal })
87
88 subgraphEvents.addEventListener("renaming-input", (e) => {
89 const { index, newName } = e.detail
90 const input = this.inputs.at(index)
91 if (!input) throw new Error("Subgraph input not found")
92
93 input.label = newName
94 }, { signal })
95
96 subgraphEvents.addEventListener("renaming-output", (e) => {
97 const { index, newName } = e.detail
98 const output = this.outputs.at(index)
99 if (!output) throw new Error("Subgraph output not found")
100
101 output.label = newName
102 }, { signal })
103
104 this.type = subgraph.id

Callers

nothing calls this directly

Calls 10

addInputMethod · 0.95
ensureWidgetRemovedMethod · 0.95
configureMethod · 0.95
addTitleButtonMethod · 0.80
addEventListenerMethod · 0.65
removeInputMethod · 0.45
setDirtyCanvasMethod · 0.45
addOutputMethod · 0.45
removeOutputMethod · 0.45

Tested by

no test coverage detected