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

Method connect

src/subgraph/SubgraphInput.ts:44–130  ·  view source on GitHub ↗
(slot: INodeInputSlot, node: LGraphNode, afterRerouteId?: RerouteId)

Source from the content-addressed store, hash-verified

42 }
43
44 override connect(slot: INodeInputSlot, node: LGraphNode, afterRerouteId?: RerouteId): LLink | undefined {
45 const { subgraph } = this.parent
46
47 // Allow nodes to block connection
48 const inputIndex = node.inputs.indexOf(slot)
49 if (node.onConnectInput?.(inputIndex, this.type, this, this.parent, -1) === false) return
50
51 // if (slot instanceof SubgraphOutput) {
52 // // Subgraph IO nodes have no special handling at present.
53 // return new LLink(
54 // ++subgraph.state.lastLinkId,
55 // this.type,
56 // this.parent.id,
57 // this.parent.slots.indexOf(this),
58 // node.id,
59 // inputIndex,
60 // afterRerouteId,
61 // )
62 // }
63
64 // Disconnect target input, if it is already connected.
65 if (slot.link != null) {
66 subgraph.beforeChange()
67 const link = subgraph.getLink(slot.link)
68 this.parent._disconnectNodeInput(node, slot, link)
69 }
70
71 const inputWidget = node.getWidgetFromSlot(slot)
72 if (inputWidget) {
73 if (!this.matchesWidget(inputWidget)) {
74 console.warn("Target input has invalid widget.", slot, node)
75 return
76 }
77
78 this._widget ??= inputWidget
79 this.events.dispatch("input-connected", { input: slot, widget: inputWidget })
80 }
81
82 const link = new LLink(
83 ++subgraph.state.lastLinkId,
84 slot.type,
85 this.parent.id,
86 this.parent.slots.indexOf(this),
87 node.id,
88 inputIndex,
89 afterRerouteId,
90 )
91
92 // Add to graph links list
93 subgraph._links.set(link.id, link)
94
95 // Set link ID in each slot
96 this.linkIds.push(link.id)
97 slot.link = link.id
98
99 // Reroutes
100 const reroutes = LLink.getReroutes(subgraph, link)
101 for (const reroute of reroutes) {

Callers 10

connectToOutputMethod · 0.45
connectToInputMethod · 0.45
connectToRerouteInputMethod · 0.45
connectByTypeOutputMethod · 0.45
connectByTypeMethod · 0.45

Calls 12

matchesWidgetMethod · 0.95
beforeChangeMethod · 0.80
_disconnectNodeInputMethod · 0.80
getWidgetFromSlotMethod · 0.80
setMethod · 0.80
addMethod · 0.80
getMethod · 0.80
afterChangeMethod · 0.80
getLinkMethod · 0.65
dispatchMethod · 0.65
removeFloatingLinkMethod · 0.65
getReroutesMethod · 0.45

Tested by

no test coverage detected