reverted useHandleConnections

This commit is contained in:
peterkogo
2025-01-06 12:22:28 +01:00
parent ed82fd2eda
commit dcf6a63595
2 changed files with 6 additions and 8 deletions
@@ -12,7 +12,7 @@ import { useNodeId } from '../contexts/NodeIdContext';
type useHandleConnectionsParams = { type useHandleConnectionsParams = {
type: HandleType; type: HandleType;
id?: string; id?: string | null;
nodeId?: string; nodeId?: string;
onConnect?: (connections: Connection[]) => void; onConnect?: (connections: Connection[]) => void;
onDisconnect?: (connections: Connection[]) => void; onDisconnect?: (connections: Connection[]) => void;
@@ -31,7 +31,7 @@ type useHandleConnectionsParams = {
*/ */
export function useHandleConnections({ export function useHandleConnections({
type, type,
id, id = null,
nodeId, nodeId,
onConnect, onConnect,
onDisconnect, onDisconnect,
@@ -42,7 +42,7 @@ export function useHandleConnections({
const prevConnections = useRef<Map<string, HandleConnection> | null>(null); const prevConnections = useRef<Map<string, HandleConnection> | null>(null);
const connections = useStore( const connections = useStore(
(state) => state.connectionLookup.get(`${currentNodeId}${type ? (id ? `-${type}-${id}` : `-${type}`) : ''}`), (state) => state.connectionLookup.get(`${currentNodeId}-${type}-${id}`),
areConnectionMapsEqual areConnectionMapsEqual
); );
@@ -7,7 +7,7 @@ import { getContext } from 'svelte';
export type useHandleConnectionsParams = { export type useHandleConnectionsParams = {
type: HandleType; type: HandleType;
nodeId?: string; nodeId?: string;
id?: string; id?: string | null;
}; };
const initialConnections: HandleConnection[] = []; 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) * @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 * @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 { edges, connectionLookup } = useStore();
const _nodeId = getContext<string>('svelteflow__node_id'); const _nodeId = getContext<string>('svelteflow__node_id');
@@ -32,9 +32,7 @@ export function useHandleConnections({ type, nodeId, id }: useHandleConnectionsP
return derived( return derived(
[edges, connectionLookup], [edges, connectionLookup],
([, connectionLookup], set) => { ([, connectionLookup], set) => {
const nextConnections = connectionLookup.get( const nextConnections = connectionLookup.get(`${currentNodeId}-${type}-${id || null}`);
`${currentNodeId}${type ? (id ? `-${type}-${id}` : `-${type}`) : ''}`
);
if (!areConnectionMapsEqual(nextConnections, prevConnections)) { if (!areConnectionMapsEqual(nextConnections, prevConnections)) {
prevConnections = nextConnections; prevConnections = nextConnections;