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

Method load

src/LGraph.ts:1902–1935  ·  view source on GitHub ↗
(url: string | Blob | URL | File, callback: () => void)

Source from the content-addressed store, hash-verified

1900 }
1901
1902 load(url: string | Blob | URL | File, callback: () => void) {
1903 const that = this
1904
1905 // from file
1906 if (url instanceof Blob || url instanceof File) {
1907 const reader = new FileReader()
1908 reader.addEventListener("load", function (event) {
1909 const result = stringOrEmpty(event.target?.result)
1910 const data = JSON.parse(result)
1911 that.configure(data)
1912 callback?.()
1913 })
1914
1915 reader.readAsText(url)
1916 return
1917 }
1918
1919 // is a string, then an URL
1920 const req = new XMLHttpRequest()
1921 req.open("GET", url, true)
1922 req.send(null)
1923 req.addEventListener("load", function () {
1924 if (req.status !== 200) {
1925 console.error("Error loading graph:", req.status, req.response)
1926 return
1927 }
1928 const data = JSON.parse(req.response)
1929 that.configure(data)
1930 callback?.()
1931 })
1932 req.addEventListener("error", (err) => {
1933 console.error("Error loading graph:", err)
1934 })
1935 }
1936}

Callers

nothing calls this directly

Calls 3

stringOrEmptyFunction · 0.90
addEventListenerMethod · 0.65
configureMethod · 0.45

Tested by

no test coverage detected