implemented more broader tracking of handleConnections

This commit is contained in:
peterkogo
2024-10-10 17:20:21 +02:00
parent eb71e34d44
commit 0ae06ce5cb
3 changed files with 34 additions and 16 deletions
@@ -7,7 +7,7 @@ import { getContext } from 'svelte';
export type useHandleConnectionsParams = {
type: HandleType;
nodeId?: string;
id?: string | null;
id?: string;
};
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 = null }: useHandleConnectionsParams) {
export function useHandleConnections({ type, nodeId, id }: useHandleConnectionsParams) {
const { edges, connectionLookup } = useStore();
const _nodeId = getContext<string>('svelteflow__node_id');
@@ -32,7 +32,9 @@ export function useHandleConnections({ type, nodeId, id = null }: useHandleConne
return derived(
[edges, connectionLookup],
([, connectionLookup], set) => {
const nextConnections = connectionLookup.get(`${currentNodeId}-${type}-${id || null}`);
const nextConnections = connectionLookup.get(
`${currentNodeId}${type ? (id ? `-${type}-${id}` : `-${type}`) : ''}`
);
if (!areConnectionMapsEqual(nextConnections, prevConnections)) {
prevConnections = nextConnections;