mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 11:11:53 +00:00
Remove unnecessary copy of litegraph objects
This commit is contained in:
@@ -772,7 +772,8 @@ export class ComfyApp {
|
|||||||
// Register the subgraph - adds type wrapper for Litegraph's `createNode` factory
|
// Register the subgraph - adds type wrapper for Litegraph's `createNode` factory
|
||||||
this.graph.events.addEventListener('subgraph-created', (e) => {
|
this.graph.events.addEventListener('subgraph-created', (e) => {
|
||||||
try {
|
try {
|
||||||
useSubgraphService().registerNewSubgraph(e.detail)
|
const { subgraph, data } = e.detail
|
||||||
|
useSubgraphService().registerNewSubgraph(subgraph, data)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to register subgraph', err)
|
console.error('Failed to register subgraph', err)
|
||||||
useToastStore().add({
|
useToastStore().add({
|
||||||
|
|||||||
@@ -12,9 +12,6 @@ import { useNodeDefStore } from '@/stores/nodeDefStore'
|
|||||||
import { useLitegraphService } from './litegraphService'
|
import { useLitegraphService } from './litegraphService'
|
||||||
|
|
||||||
export const useSubgraphService = () => {
|
export const useSubgraphService = () => {
|
||||||
/** @todo Move to store */
|
|
||||||
const subgraphs = new Map<string, Subgraph>()
|
|
||||||
|
|
||||||
/** Loads a single subgraph definition and registers it with the node def store */
|
/** Loads a single subgraph definition and registers it with the node def store */
|
||||||
const deserialiseSubgraph = (
|
const deserialiseSubgraph = (
|
||||||
subgraph: Subgraph,
|
subgraph: Subgraph,
|
||||||
@@ -63,7 +60,7 @@ export const useSubgraphService = () => {
|
|||||||
|
|
||||||
for (const subgraphData of graphData.definitions.subgraphs) {
|
for (const subgraphData of graphData.definitions.subgraphs) {
|
||||||
const subgraph =
|
const subgraph =
|
||||||
subgraphs.get(subgraphData.id) ??
|
comfyApp.graph.subgraphs.get(subgraphData.id) ??
|
||||||
comfyApp.graph.createSubgraph(subgraphData as ExportedSubgraph)
|
comfyApp.graph.createSubgraph(subgraphData as ExportedSubgraph)
|
||||||
|
|
||||||
// @ts-expect-error Zod
|
// @ts-expect-error Zod
|
||||||
@@ -72,10 +69,16 @@ export const useSubgraphService = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Registers a new subgraph (e.g. user converted from nodes) */
|
/** Registers a new subgraph (e.g. user converted from nodes) */
|
||||||
const registerNewSubgraph = (subgraph: Subgraph) => {
|
const registerNewSubgraph = (
|
||||||
subgraphs.set(subgraph.id, subgraph)
|
subgraph: Subgraph,
|
||||||
|
exportedSubgraph: ExportedSubgraph
|
||||||
|
) => {
|
||||||
|
if (comfyApp.graph.subgraphs.has(subgraph.id)) {
|
||||||
|
console.debug(`Subgraph ${subgraph.id} already registered`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
deserialiseSubgraph(subgraph, subgraph.asSerialisable())
|
deserialiseSubgraph(subgraph, exportedSubgraph)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user