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

Method createNode

src/LiteGraphGlobal.ts:484–532  ·  view source on GitHub ↗

* Create a node of a given type with a name. The node is not attached to any graph yet. * @param type full name of the node class. p.e. "math/sin" * @param title a name to distinguish from other nodes * @param options to set options

(
    type: string,
    title?: string,
    options?: Dictionary<unknown>,
  )

Source from the content-addressed store, hash-verified

482 * @param options to set options
483 */
484 createNode(
485 type: string,
486 title?: string,
487 options?: Dictionary<unknown>,
488 ): LGraphNode | null {
489 const base_class = this.registered_node_types[type]
490 if (!base_class) {
491 if (this.debug) console.log(`GraphNode type "${type}" not registered.`)
492 return null
493 }
494
495 title = title || base_class.title || type
496
497 let node = null
498
499 if (this.catch_exceptions) {
500 try {
501 node = new base_class(title)
502 } catch (error) {
503 console.error(error)
504 return null
505 }
506 } else {
507 node = new base_class(title)
508 }
509
510 node.type = type
511
512 if (!node.title && title) node.title = title
513 node.properties ||= {}
514 node.properties_info ||= []
515 node.flags ||= {}
516 // call onresize?
517 node.size ||= node.computeSize()
518 node.pos ||= [this.DEFAULT_POSITION[0], this.DEFAULT_POSITION[1]]
519 node.mode ||= LGraphEventMode.ALWAYS
520
521 // extra options
522 if (options) {
523 for (const i in options) {
524 // @ts-expect-error #577 Requires interface
525 node[i] = options[i]
526 }
527 }
528
529 // callback
530 node.onNodeCreated?.()
531 return node
532 }
533
534 /**
535 * Returns a registered node type with a given name

Callers 10

cloneMethod · 0.80
inner_onMenuAddedMethod · 0.80
#processPrimaryButtonMethod · 0.80
_pasteFromClipboardMethod · 0.80
selectMethod · 0.80
checkNodeTypesMethod · 0.80
convertToSubgraphMethod · 0.80
configureMethod · 0.80
multiCloneFunction · 0.80

Calls 1

computeSizeMethod · 0.65

Tested by

no test coverage detected