Skip to content

Commit 0970c52

Browse files
committed
refactor: Remove extra gates (already has an early return)
Simplify createLinkConnectorAdapter cache check
1 parent 74728a9 commit 0970c52

File tree

2 files changed

+32
-34
lines changed

2 files changed

+32
-34
lines changed

src/renderer/core/canvas/links/linkConnectorAdapter.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,13 @@ export function createLinkConnectorAdapter(): LinkConnectorAdapter | null {
154154
const graph = app.canvas?.graph
155155
const connector = app.canvas?.linkConnector
156156
if (!graph || !connector) return null
157-
let adapter = adapterByGraph.get(graph)
158-
if (!adapter || adapter.linkConnector !== connector) {
159-
adapter = new LinkConnectorAdapter(graph, connector)
160-
adapterByGraph.set(graph, adapter)
157+
158+
const adapter = adapterByGraph.get(graph)
159+
if (adapter && adapter.linkConnector === connector) {
160+
return adapter
161161
}
162-
return adapter
162+
163+
const newAdapter = new LinkConnectorAdapter(graph, connector)
164+
adapterByGraph.set(graph, newAdapter)
165+
return newAdapter
163166
}

src/renderer/extensions/vueNodes/composables/useSlotLinkInteraction.ts

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { useEventListener } from '@vueuse/core'
1+
import { tryOnScopeDispose, useEventListener } from '@vueuse/core'
22
import type { Fn } from '@vueuse/core'
3-
import { onBeforeUnmount } from 'vue'
43

54
import { useSharedCanvasPositionConversion } from '@/composables/element/useCanvasPositionConversion'
65
import type { LGraph } from '@/lib/litegraph/src/LGraph'
@@ -555,6 +554,8 @@ export function useSlotLinkInteraction({
555554
if (event.button !== 0) return
556555
if (!nodeId) return
557556
if (pointerSession.isActive()) return
557+
event.preventDefault()
558+
event.stopPropagation()
558559

559560
const canvas = app.canvas
560561
const graph = canvas?.graph
@@ -613,7 +614,7 @@ export function useSlotLinkInteraction({
613614

614615
if (shouldBatchDisconnectOutputLinks && resolvedNode) {
615616
resolvedNode.disconnectOutput(index)
616-
app.canvas?.setDirty(true, true)
617+
canvas.setDirty(true, true)
617618
event.preventDefault()
618619
event.stopPropagation()
619620
return
@@ -634,20 +635,18 @@ export function useSlotLinkInteraction({
634635
const shouldMoveExistingInput =
635636
isInputSlot && !shouldBreakExistingInputLink && hasExistingInputLink
636637

637-
if (activeAdapter) {
638-
if (isOutputSlot) {
639-
activeAdapter.beginFromOutput(localNodeId, index, {
640-
moveExisting: shouldMoveExistingOutput
641-
})
642-
} else {
643-
activeAdapter.beginFromInput(localNodeId, index, {
644-
moveExisting: shouldMoveExistingInput
645-
})
646-
}
638+
if (isOutputSlot) {
639+
activeAdapter.beginFromOutput(localNodeId, index, {
640+
moveExisting: shouldMoveExistingOutput
641+
})
642+
} else {
643+
activeAdapter.beginFromInput(localNodeId, index, {
644+
moveExisting: shouldMoveExistingInput
645+
})
646+
}
647647

648-
if (shouldMoveExistingInput && existingInputLink) {
649-
existingInputLink._dragging = true
650-
}
648+
if (shouldMoveExistingInput && existingInputLink) {
649+
existingInputLink._dragging = true
651650
}
652651

653652
syncRenderLinkOrigins()
@@ -678,21 +677,19 @@ export function useSlotLinkInteraction({
678677
toCanvasPointerEvent(event)
679678
updatePointerState(event)
680679

681-
if (activeAdapter) {
682-
activeAdapter.linkConnector.state.snapLinksPos = [
683-
state.pointer.canvas.x,
684-
state.pointer.canvas.y
685-
]
686-
}
680+
activeAdapter.linkConnector.state.snapLinksPos = [
681+
state.pointer.canvas.x,
682+
state.pointer.canvas.y
683+
]
687684

688685
pointerSession.register(
689-
useEventListener(window, 'pointermove', handlePointerMove, {
686+
useEventListener('pointermove', handlePointerMove, {
690687
capture: true
691688
}),
692-
useEventListener(window, 'pointerup', handlePointerUp, {
689+
useEventListener('pointerup', handlePointerUp, {
693690
capture: true
694691
}),
695-
useEventListener(window, 'pointercancel', handlePointerCancel, {
692+
useEventListener('pointercancel', handlePointerCancel, {
696693
capture: true
697694
})
698695
)
@@ -710,12 +707,10 @@ export function useSlotLinkInteraction({
710707
: activeAdapter.isOutputValidDrop(slotLayout.nodeId, idx)
711708
setCompatibleForKey(key, ok)
712709
}
713-
app.canvas?.setDirty(true, true)
714-
event.preventDefault()
715-
event.stopPropagation()
710+
canvas.setDirty(true, true)
716711
}
717712

718-
onBeforeUnmount(() => {
713+
tryOnScopeDispose(() => {
719714
if (pointerSession.isActive()) {
720715
cleanupInteraction()
721716
}

0 commit comments

Comments
 (0)