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

Method clone

src/LGraphNode.ts:861–891  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

859
860 /* Creates a clone of this node */
861 clone(): LGraphNode | null {
862 if (this.type == null) return null
863 const node = LiteGraph.createNode(this.type)
864 if (!node) return null
865
866 // we clone it because serialize returns shared containers
867 const data = LiteGraph.cloneObject(this.serialize())
868 const { inputs, outputs } = data
869
870 // remove links
871 if (inputs) {
872 for (const input of inputs) {
873 input.link = null
874 }
875 }
876
877 if (outputs) {
878 for (const { links } of outputs) {
879 if (links) links.length = 0
880 }
881 }
882
883 // @ts-expect-error Exceptional case: id is removed so that the graph can assign a new one on add.
884 delete data.id
885
886 if (LiteGraph.use_uuids) data.id = LiteGraph.uuidv4()
887
888 node.configure(data)
889
890 return node
891 }
892
893 /**
894 * serialize and stringify

Callers 3

fApplyMultiNodeMethod · 0.45
#processPrimaryButtonMethod · 0.45
copyToClipboardMethod · 0.45

Calls 4

serializeMethod · 0.95
createNodeMethod · 0.80
cloneObjectMethod · 0.80
configureMethod · 0.45

Tested by

no test coverage detected