[refactor] Simplify conditionals and improve method naming per review

- Combine nested conditions into single check for canvas change
- Use guard clauses to reduce nesting in rendering mode watch
- Rename start() to attemptStart() to better reflect that it may not actually start
This commit is contained in:
Benjamin Lu
2025-09-05 09:45:57 -07:00
parent 942cec10b4
commit 50e957e56f
2 changed files with 18 additions and 19 deletions

View File

@@ -303,17 +303,15 @@ watch(
}
// Canvas changed - restart sync
if (oldCanvas && oldCanvas !== canvas) {
if (slotSync && slotSyncStarted) {
slotSync.stop()
slotSyncStarted = false
}
if (oldCanvas && oldCanvas !== canvas && slotSync && slotSyncStarted) {
slotSync.stop()
slotSyncStarted = false
}
// Start sync if not in Vue mode and not already started
if (!slotSync) slotSync = useSlotLayoutSync()
if (!slotSyncStarted && !isVueNodesEnabled.value) {
const started = slotSync.start(canvas as LGraphCanvas)
const started = slotSync.attemptStart(canvas as LGraphCanvas)
slotSyncStarted = started
}
},
@@ -334,16 +332,17 @@ watch(
slotSyncStarted = false
}
// DOM will re-register via useDomSlotRegistration
} else {
// Switching TO LiteGraph
if (canvasStore.canvas && comfyApp.graph) {
// Ensure slot sync is active
if (!slotSync) slotSync = useSlotLayoutSync()
if (!slotSyncStarted) {
const started = slotSync.start(canvasStore.canvas as LGraphCanvas)
slotSyncStarted = started
}
}
return
}
// Switching TO LiteGraph
if (!canvasStore.canvas || !comfyApp.graph) return
// Ensure slot sync is active
if (!slotSync) slotSync = useSlotLayoutSync()
if (!slotSyncStarted) {
const started = slotSync.attemptStart(canvasStore.canvas as LGraphCanvas)
slotSyncStarted = started
}
},
{ immediate: false }

View File

@@ -57,11 +57,11 @@ export function useSlotLayoutSync() {
let restoreHandlers: (() => void) | null = null
/**
* Start slot layout sync with full event-driven functionality
* Attempt to start slot layout sync with full event-driven functionality
* @param canvas LiteGraph canvas instance
* @returns true if sync was actually started, false if early-returned
*/
function start(canvas: LGraphCanvas): boolean {
function attemptStart(canvas: LGraphCanvas): boolean {
// When Vue nodes are enabled, slot DOM registers exact positions.
// Skip calculated registration to avoid conflicts.
if (LiteGraph.vueNodesMode) {
@@ -160,7 +160,7 @@ export function useSlotLayoutSync() {
})
return {
start,
attemptStart,
stop
}
}