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

Method configure

src/LGraphNode.ts:721–809  ·  view source on GitHub ↗

* configure a node from an object containing the serialized info

(info: ISerialisedNode)

Source from the content-addressed store, hash-verified

719 * configure a node from an object containing the serialized info
720 */
721 configure(info: ISerialisedNode): void {
722 if (this.graph) {
723 this.graph._version++
724 }
725 for (const j in info) {
726 if (j == "properties") {
727 // i don't want to clone properties, I want to reuse the old container
728 for (const k in info.properties) {
729 this.properties[k] = info.properties[k]
730 this.onPropertyChanged?.(k, info.properties[k])
731 }
732 continue
733 }
734
735 // @ts-expect-error #594
736 if (info[j] == null) {
737 continue
738 // @ts-expect-error #594
739 } else if (typeof info[j] == "object") {
740 // @ts-expect-error #594
741 if (this[j]?.configure) {
742 // @ts-expect-error #594
743 this[j]?.configure(info[j])
744 } else {
745 // @ts-expect-error #594
746 this[j] = LiteGraph.cloneObject(info[j], this[j])
747 }
748 } else {
749 // value
750 // @ts-expect-error #594
751 this[j] = info[j]
752 }
753 }
754
755 if (!info.title) {
756 this.title = this.constructor.title
757 }
758
759 this.inputs ??= []
760 this.inputs = this.inputs.map(input => toClass(NodeInputSlot, input, this))
761 for (const [i, input] of this.inputs.entries()) {
762 const link = this.graph && input.link != null
763 ? this.graph._links.get(input.link)
764 : null
765 this.onConnectionsChange?.(NodeSlotType.INPUT, i, true, link, input)
766 this.onInputAdded?.(input)
767 }
768
769 this.outputs ??= []
770 this.outputs = this.outputs.map(output => toClass(NodeOutputSlot, output, this))
771 for (const [i, output] of this.outputs.entries()) {
772 if (!output.links) continue
773
774 for (const linkId of output.links) {
775 const link = this.graph
776 ? this.graph._links.get(linkId)
777 : null
778 this.onConnectionsChange?.(NodeSlotType.OUTPUT, i, true, link, output)

Callers 1

cloneMethod · 0.45

Calls 4

toClassFunction · 0.90
cloneObjectMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected