mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-05 15:40:10 +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
|
||||
this.graph.events.addEventListener('subgraph-created', (e) => {
|
||||
try {
|
||||
useSubgraphService().registerNewSubgraph(e.detail)
|
||||
const { subgraph, data } = e.detail
|
||||
useSubgraphService().registerNewSubgraph(subgraph, data)
|
||||
} catch (err) {
|
||||
console.error('Failed to register subgraph', err)
|
||||
useToastStore().add({
|
||||
|
||||
@@ -12,9 +12,6 @@ import { useNodeDefStore } from '@/stores/nodeDefStore'
|
||||
import { useLitegraphService } from './litegraphService'
|
||||
|
||||
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 */
|
||||
const deserialiseSubgraph = (
|
||||
subgraph: Subgraph,
|
||||
@@ -63,7 +60,7 @@ export const useSubgraphService = () => {
|
||||
|
||||
for (const subgraphData of graphData.definitions.subgraphs) {
|
||||
const subgraph =
|
||||
subgraphs.get(subgraphData.id) ??
|
||||
comfyApp.graph.subgraphs.get(subgraphData.id) ??
|
||||
comfyApp.graph.createSubgraph(subgraphData as ExportedSubgraph)
|
||||
|
||||
// @ts-expect-error Zod
|
||||
@@ -72,10 +69,16 @@ export const useSubgraphService = () => {
|
||||
}
|
||||
|
||||
/** Registers a new subgraph (e.g. user converted from nodes) */
|
||||
const registerNewSubgraph = (subgraph: Subgraph) => {
|
||||
subgraphs.set(subgraph.id, subgraph)
|
||||
const registerNewSubgraph = (
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user