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

Method remove

src/LGraph.ts:868–955  ·  view source on GitHub ↗

* Removes a node from the graph * @param node the instance of the node

(node: LGraphNode | LGraphGroup)

Source from the content-addressed store, hash-verified

866 * @param node the instance of the node
867 */
868 remove(node: LGraphNode | LGraphGroup): void {
869 // LEGACY: This was changed from constructor === LiteGraph.LGraphGroup
870 if (node instanceof LGraphGroup) {
871 this.canvasAction(c => c.deselect(node))
872
873 const index = this._groups.indexOf(node)
874 if (index != -1) {
875 this._groups.splice(index, 1)
876 }
877 node.graph = undefined
878 this._version++
879 this.setDirtyCanvas(true, true)
880 this.change()
881 return
882 }
883
884 // not found
885 if (this._nodes_by_id[node.id] == null) {
886 console.warn("LiteGraph: node not found", node)
887 return
888 }
889 // cannot be removed
890 if (node.ignore_remove) {
891 console.warn("LiteGraph: node cannot be removed", node)
892 return
893 }
894
895 // sure? - almost sure is wrong
896 this.beforeChange()
897
898 const { inputs, outputs } = node
899
900 // disconnect inputs
901 if (inputs) {
902 for (const [i, slot] of inputs.entries()) {
903 if (slot.link != null) node.disconnectInput(i, true)
904 }
905 }
906
907 // disconnect outputs
908 if (outputs) {
909 for (const [i, slot] of outputs.entries()) {
910 if (slot.links?.length) node.disconnectOutput(i)
911 }
912 }
913
914 // Floating links
915 for (const link of this.floatingLinks.values()) {
916 if (link.origin_id === node.id || link.target_id === node.id) {
917 this.removeFloatingLink(link)
918 }
919 }
920
921 // callback
922 node.onRemoved?.()
923
924 node.graph = null
925 this._version++

Callers 15

convertToSubgraphMethod · 0.95
LGraph.test.tsFile · 0.45
closeMethod · 0.45
onShowPropertyEditorMethod · 0.45
setValueMethod · 0.45
processMouseDownMethod · 0.45
deleteSelectedMethod · 0.45
closeMethod · 0.45
changeSelectionMethod · 0.45
createPanelMethod · 0.45

Calls 12

canvasActionMethod · 0.95
setDirtyCanvasMethod · 0.95
changeMethod · 0.95
beforeChangeMethod · 0.95
removeFloatingLinkMethod · 0.95
afterChangeMethod · 0.95
updateExecutionOrderMethod · 0.95
deselectMethod · 0.80
disconnectInputMethod · 0.80
disconnectOutputMethod · 0.80
onRemovedMethod · 0.80
checkPanelsMethod · 0.80

Tested by

no test coverage detected