refactor(react/handle-connection-state): cleanup
This commit is contained in:
@@ -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)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user