update(types): remove null types and use undefined

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
Braks
2021-11-22 17:14:57 +01:00
parent fec38a129a
commit b9bb3cfb1a
9 changed files with 40 additions and 25 deletions
+2 -2
View File
@@ -41,7 +41,7 @@ export function getHandlePosition(position: Position, node: GraphNode, handle: a
}
}
export function getHandle(bounds: HandleElement[], handleId: ElementId | null): HandleElement | undefined {
export function getHandle(bounds: HandleElement[], handleId?: ElementId): HandleElement | undefined {
if (!bounds) return undefined
// there is no handleId when there are no multiple handles/ handles with ids
@@ -53,7 +53,7 @@ export function getHandle(bounds: HandleElement[], handleId: ElementId | null):
handle = bounds.find((d) => d.id === handleId)
}
return typeof handle === 'undefined' ? undefined : handle
return !handle ? undefined : handle
}
export const getEdgePositions = (
+4 -4
View File
@@ -171,8 +171,8 @@ export const parseNode = (node: Node, nodeExtent: NodeExtent): GraphNode => ({
width: 0,
height: 0,
handleBounds: {
source: null,
target: null,
source: undefined,
target: undefined,
},
isDragging: false,
},
@@ -182,8 +182,8 @@ export const parseEdge = (edge: Edge): Edge => ({
...edge,
source: edge.source.toString(),
target: edge.target.toString(),
sourceHandle: edge.sourceHandle ? edge.sourceHandle.toString() : null,
targetHandle: edge.targetHandle ? edge.targetHandle.toString() : null,
sourceHandle: edge.sourceHandle ? edge.sourceHandle.toString() : undefined,
targetHandle: edge.targetHandle ? edge.targetHandle.toString() : undefined,
id: edge.id.toString(),
type: edge.type || 'default',
})
+3 -3
View File
@@ -18,7 +18,7 @@ export const getHandleBoundsByHandleType = (
return handlesArray.map((handle): HandleElement => {
const bounds = handle.getBoundingClientRect()
const dimensions = getDimensions(handle)
const handleId = handle.getAttribute('data-handleid')
const handleId = handle.getAttribute('data-handleid') ?? undefined
const handlePosition = handle.getAttribute('data-handlepos') as Position
return {
@@ -35,7 +35,7 @@ export const getHandleBounds = (nodeElement: HTMLDivElement, scale: number) => {
const bounds = nodeElement.getBoundingClientRect()
return {
source: getHandleBoundsByHandleType('.source', nodeElement, bounds, scale),
target: getHandleBoundsByHandleType('.target', nodeElement, bounds, scale),
source: getHandleBoundsByHandleType('.source', nodeElement, bounds, scale) ?? undefined,
target: getHandleBoundsByHandleType('.target', nodeElement, bounds, scale) ?? undefined,
}
}