refactor(types): Remove SourceTargetNode-type

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
Braks
2021-11-25 15:21:36 +01:00
parent 729d3d5ca2
commit 8b0ddc9be9
9 changed files with 46 additions and 56 deletions
+10 -12
View File
@@ -1,4 +1,4 @@
import { rectToBox } from './graph'
import { isGraphNode, rectToBox } from './graph'
import {
Edge,
EdgePositions,
@@ -6,11 +6,10 @@ import {
GraphNode,
HandleElement,
Position,
SourceTargetNode,
Transform,
XYPosition,
Elements,
FlowElements,
GraphEdge,
} from '~/types'
export function getHandlePosition(position: Position, node: GraphNode, handle?: HandleElement): XYPosition {
@@ -115,18 +114,17 @@ export function isEdgeVisible({ sourcePos, targetPos, width, height, transform }
return overlappingArea > 0
}
export const getSourceTargetNodes = (edge: Edge, elements: FlowElements | Elements): SourceTargetNode => {
let { sourceNode, targetNode }: any = {
sourceNode: null,
targetNode: null,
}
export const getSourceTargetNodes = (edge: GraphEdge | Edge, elements: FlowElements) => {
const nodes: GraphNode[] = []
for (const el of elements) {
if (!sourceNode || !targetNode) {
if (el.id === edge.source) sourceNode = el
if (el.id === edge.target) targetNode = el
if (!nodes[0] || !nodes[1]) {
if (isGraphNode(el)) {
if (el.id === edge.source) nodes[0] = el
if (el.id === edge.target) nodes[1] = el
}
} else {
break
}
}
return { sourceNode, targetNode }
return { sourceNode: nodes[0], targetNode: nodes[1] }
}