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

Method triggerSlot

src/LGraphNode.ts:1354–1409  ·  view source on GitHub ↗

* Triggers a slot event in this node: cycle output slots and launch execute/action on connected nodes * @param slot the index of the output slot * @param link_id [optional] in case you want to trigger and specific output link in a slot

(
    slot: number,
    param: unknown,
    link_id: number | null,
    options?: { action_call?: any },
  )

Source from the content-addressed store, hash-verified

1352 * @param link_id [optional] in case you want to trigger and specific output link in a slot
1353 */
1354 triggerSlot(
1355 slot: number,
1356 param: unknown,
1357 link_id: number | null,
1358 options?: { action_call?: any },
1359 ): void {
1360 options = options || {}
1361 if (!this.outputs) return
1362
1363 if (slot == null) {
1364 console.error("slot must be a number")
1365 return
1366 }
1367
1368 if (typeof slot !== "number")
1369 console.warn("slot must be a number, use node.trigger('name') if you want to use a string")
1370
1371 const output = this.outputs[slot]
1372 if (!output) return
1373
1374 const links = output.links
1375 if (!links || !links.length) return
1376
1377 if (!this.graph) throw new NullGraphError()
1378 this.graph._last_trigger_time = LiteGraph.getTime()
1379
1380 // for every link attached here
1381 for (const id of links) {
1382 // to skip links
1383 if (link_id != null && link_id != id) continue
1384
1385 const link_info = this.graph._links.get(id)
1386 // not connected
1387 if (!link_info) continue
1388
1389 link_info._last_time = LiteGraph.getTime()
1390 const node = this.graph.getNodeById(link_info.target_id)
1391 // node not found?
1392 if (!node) continue
1393
1394 if (node.mode === LGraphEventMode.ON_TRIGGER) {
1395 // generate unique trigger ID if not present
1396 if (!options.action_call)
1397 options.action_call = `${this.id}_trigg_${Math.floor(Math.random() * 9999)}`
1398 // -- wrapping node.onExecute(param); --
1399 node.doExecute?.(param, options)
1400 } else if (node.onAction) {
1401 // generate unique action ID if not present
1402 if (!options.action_call)
1403 options.action_call = `${this.id}_act_${Math.floor(Math.random() * 9999)}`
1404 // pass the action name
1405 const target_connection = node.inputs[link_info.target_slot]
1406 node.actionDo(target_connection.name, param, options)
1407 }
1408 }
1409 }
1410
1411 /**

Callers 2

onAfterExecuteNodeMethod · 0.95
triggerMethod · 0.95

Calls 5

getMethod · 0.80
doExecuteMethod · 0.80
actionDoMethod · 0.80
getNodeByIdMethod · 0.65
getTimeMethod · 0.45

Tested by

no test coverage detected