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

Method configure

src/LGraph.ts:1714–1891  ·  view source on GitHub ↗

* Configure a graph from a JSON string * @param data The deserialised object to configure this graph from * @param keep_old If `true`, the graph will not be cleared prior to * adding the configuration.

(
    data: ISerialisedGraph | SerialisableGraph,
    keep_old?: boolean,
  )

Source from the content-addressed store, hash-verified

1712 * adding the configuration.
1713 */
1714 configure(
1715 data: ISerialisedGraph | SerialisableGraph,
1716 keep_old?: boolean,
1717 ): boolean | undefined {
1718 const options: LGraphEventMap["configuring"] = {
1719 data,
1720 clearGraph: !keep_old,
1721 }
1722 const mayContinue = this.events.dispatch("configuring", options)
1723 if (!mayContinue) return
1724
1725 try {
1726 // TODO: Finish typing configure()
1727 if (!data) return
1728 if (options.clearGraph) this.clear()
1729
1730 this._configureBase(data)
1731
1732 let reroutes: SerialisableReroute[] | undefined
1733
1734 // TODO: Determine whether this should this fall back to 0.4.
1735 if (data.version === 0.4) {
1736 const { extra } = data
1737 // Deprecated - old schema version, links are arrays
1738 if (Array.isArray(data.links)) {
1739 for (const linkData of data.links) {
1740 const link = LLink.createFromArray(linkData)
1741 this._links.set(link.id, link)
1742 }
1743 }
1744 // #region `extra` embeds for v0.4
1745
1746 // LLink parentIds
1747 if (Array.isArray(extra?.linkExtensions)) {
1748 for (const linkEx of extra.linkExtensions) {
1749 const link = this._links.get(linkEx.id)
1750 if (link) link.parentId = linkEx.parentId
1751 }
1752 }
1753
1754 // Reroutes
1755 reroutes = extra?.reroutes
1756
1757 // #endregion `extra` embeds for v0.4
1758 } else {
1759 // New schema - one version so far, no check required.
1760
1761 // State
1762 if (data.state) {
1763 const { lastGroupId, lastLinkId, lastNodeId, lastRerouteId } = data.state
1764 const { state } = this
1765 if (lastGroupId != null) state.lastGroupId = lastGroupId
1766 if (lastLinkId != null) state.lastLinkId = lastLinkId
1767 if (lastNodeId != null) state.lastNodeId = lastNodeId
1768 if (lastRerouteId != null) state.lastRerouteId = lastRerouteId
1769 }
1770
1771 // Links

Callers 4

constructorMethod · 0.95
checkNodeTypesMethod · 0.45
convertToSubgraphMethod · 0.45
loadMethod · 0.45

Calls 15

clearMethod · 0.95
_configureBaseMethod · 0.95
setRerouteMethod · 0.95
createSubgraphMethod · 0.95
addMethod · 0.95
getNodeByIdMethod · 0.95
addFloatingLinkMethod · 0.95
configureMethod · 0.95
updateExecutionOrderMethod · 0.95
setDirtyCanvasMethod · 0.95
createFromArrayMethod · 0.80
setMethod · 0.80

Tested by

no test coverage detected