Skip to content

Commit

Permalink
update(types): Typeguard input type
Browse files Browse the repository at this point in the history
  • Loading branch information
bcakmakoglu committed Apr 9, 2022
1 parent b5f4ecc commit c295a83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/src/Basic/Basic.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts" setup>
import { VueFlow, MiniMap, Controls, Background, isNode, useVueFlow, Elements } from '@braks/vue-flow'
import { VueFlow, MiniMap, Controls, Background, isNode, useVueFlow, Elements } from '@braks/vue-flow/src/index'
const elements = ref<Elements>([
{ id: '1', type: 'input', label: 'Node 1', position: { x: 250, y: 5 } },
Expand Down
12 changes: 6 additions & 6 deletions package/src/utils/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Edge,
EdgeMarkerType,
Elements,
FlowElement,
FlowElements,
FlowExportObject,
Getters,
Expand Down Expand Up @@ -52,14 +53,13 @@ export const getHostForElement = (element: HTMLElement): Document => {
else return window.document
}

export const isEdge = (element: Node | Edge | Connection): element is Edge =>
'id' in element && 'source' in element && 'target' in element
export const isGraphEdge = (element: any): element is GraphEdge =>
type MaybeElement = Node | Edge | Connection | FlowElement
export const isEdge = (element: MaybeElement): element is Edge => 'id' in element && 'source' in element && 'target' in element
export const isGraphEdge = (element: MaybeElement): element is GraphEdge =>
isEdge(element) && 'sourceNode' in element && 'targetNode' in element

export const isNode = (element: Node | Edge | Connection): element is Node => 'id' in element && !isEdge(element)
export const isGraphNode = (element: Node | Edge | Connection): element is GraphNode =>
isNode(element) && 'computedPosition' in element
export const isNode = (element: MaybeElement): element is Node => 'id' in element && !isEdge(element)
export const isGraphNode = (element: MaybeElement): element is GraphNode => isNode(element) && 'computedPosition' in element

export const parseNode = (node: Node, nodeExtent: CoordinateExtent, defaults?: Partial<GraphNode>): GraphNode => {
let defaultValues = defaults
Expand Down

0 comments on commit c295a83

Please sign in to comment.