From dcf6a635958ca9d4a0f4456acc9146983748bc55 Mon Sep 17 00:00:00 2001 From: peterkogo Date: Mon, 6 Jan 2025 12:22:28 +0100 Subject: [PATCH] reverted useHandleConnections --- packages/react/src/hooks/useHandleConnections.ts | 6 +++--- packages/svelte/src/lib/hooks/useHandleConnections.ts | 8 +++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/react/src/hooks/useHandleConnections.ts b/packages/react/src/hooks/useHandleConnections.ts index ff20c909..20b65a2d 100644 --- a/packages/react/src/hooks/useHandleConnections.ts +++ b/packages/react/src/hooks/useHandleConnections.ts @@ -12,7 +12,7 @@ import { useNodeId } from '../contexts/NodeIdContext'; type useHandleConnectionsParams = { type: HandleType; - id?: string; + id?: string | null; nodeId?: string; onConnect?: (connections: Connection[]) => void; onDisconnect?: (connections: Connection[]) => void; @@ -31,7 +31,7 @@ type useHandleConnectionsParams = { */ export function useHandleConnections({ type, - id, + id = null, nodeId, onConnect, onDisconnect, @@ -42,7 +42,7 @@ export function useHandleConnections({ const prevConnections = useRef | null>(null); const connections = useStore( - (state) => state.connectionLookup.get(`${currentNodeId}${type ? (id ? `-${type}-${id}` : `-${type}`) : ''}`), + (state) => state.connectionLookup.get(`${currentNodeId}-${type}-${id}`), areConnectionMapsEqual ); diff --git a/packages/svelte/src/lib/hooks/useHandleConnections.ts b/packages/svelte/src/lib/hooks/useHandleConnections.ts index 909ecee6..7aec3858 100644 --- a/packages/svelte/src/lib/hooks/useHandleConnections.ts +++ b/packages/svelte/src/lib/hooks/useHandleConnections.ts @@ -7,7 +7,7 @@ import { getContext } from 'svelte'; export type useHandleConnectionsParams = { type: HandleType; nodeId?: string; - id?: string; + id?: string | null; }; const initialConnections: HandleConnection[] = []; @@ -21,7 +21,7 @@ const initialConnections: HandleConnection[] = []; * @param param.id - the handle id (this is only needed if the node has multiple handles of the same type) * @returns an array with connections */ -export function useHandleConnections({ type, nodeId, id }: useHandleConnectionsParams) { +export function useHandleConnections({ type, nodeId, id = null }: useHandleConnectionsParams) { const { edges, connectionLookup } = useStore(); const _nodeId = getContext('svelteflow__node_id'); @@ -32,9 +32,7 @@ export function useHandleConnections({ type, nodeId, id }: useHandleConnectionsP return derived( [edges, connectionLookup], ([, connectionLookup], set) => { - const nextConnections = connectionLookup.get( - `${currentNodeId}${type ? (id ? `-${type}-${id}` : `-${type}`) : ''}` - ); + const nextConnections = connectionLookup.get(`${currentNodeId}-${type}-${id || null}`); if (!areConnectionMapsEqual(nextConnections, prevConnections)) { prevConnections = nextConnections;