refactor(react/handle-connection-state): cleanup

This commit is contained in:
moklick
2023-12-04 14:23:42 +01:00
parent 124df00f60
commit b6743a3cf3
5 changed files with 50 additions and 40 deletions
+30
View File
@@ -6,6 +6,7 @@ import {
getIncomersBase,
updateEdgeBase,
getConnectedEdgesBase,
Connection,
} from '@xyflow/system';
import type { Edge, Node } from '../types';
@@ -17,3 +18,32 @@ export const getIncomers = getIncomersBase<Node, Edge>;
export const addEdge = addEdgeBase<Edge>;
export const updateEdge = updateEdgeBase<Edge>;
export const getConnectedEdges = getConnectedEdgesBase<Node, Edge>;
export function isSameConnection(a: Connection, b: Connection) {
return (
a.source === b.source &&
a.target === b.target &&
a.sourceHandle === b.sourceHandle &&
a.targetHandle === b.targetHandle
);
}
export function areConnectionsEqual(a: Connection[] | null | undefined, b: Connection[] | null | undefined) {
if (!a && !b) {
return true;
}
if (!a || !b) {
return false;
}
if (a.length !== b.length) {
return false;
}
if (!a.length && !b.length) {
return true;
}
return !a.some((connA) => !b.find((connB) => isSameConnection(connA, connB)));
}