refactor(useHandleConnections): also return edge id

This commit is contained in:
moklick
2024-02-08 13:32:37 +01:00
parent 57270f3eb4
commit c3d5c8cdfa
6 changed files with 28 additions and 18 deletions
+6 -6
View File
@@ -1,9 +1,9 @@
import { Connection } from '../types';
import { HandleConnection } from '../types';
/**
* @internal
*/
export function areConnectionMapsEqual(a?: Map<string, Connection>, b?: Map<string, Connection>) {
export function areConnectionMapsEqual(a?: Map<string, HandleConnection>, b?: Map<string, HandleConnection>) {
if (!a && !b) {
return true;
}
@@ -31,15 +31,15 @@ export function areConnectionMapsEqual(a?: Map<string, Connection>, b?: Map<stri
* @internal
*/
export function handleConnectionChange(
a: Map<string, Connection>,
b: Map<string, Connection>,
cb?: (diff: Connection[]) => void
a: Map<string, HandleConnection>,
b: Map<string, HandleConnection>,
cb?: (diff: HandleConnection[]) => void
) {
if (!cb) {
return;
}
const diff: Connection[] = [];
const diff: HandleConnection[] = [];
a.forEach((connection, key) => {
if (!b?.has(key)) {
+1 -1
View File
@@ -260,7 +260,7 @@ export function updateConnectionLookup(connectionLookup: ConnectionLookup, edgeL
const prevSource = connectionLookup.get(sourceKey) || new Map();
const prevTarget = connectionLookup.get(targetKey) || new Map();
const connection = { source, target, sourceHandle, targetHandle };
const connection = { edgeId: edge.id, source, target, sourceHandle, targetHandle };
edgeLookup.set(edge.id, edge);
connectionLookup.set(sourceKey, prevSource.set(`${target}-${targetHandle}`, connection));