Skip to content

Commit 67126fc

Browse files
committed
refactor(core): change generic of useNode, useEdges
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
1 parent 279438b commit 67126fc

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

packages/core/src/composables/useEdge.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CustomEvent, ElementData } from '~/types'
1+
import type { GraphEdge } from '~/types'
22

33
/**
44
* Access an edge
@@ -7,13 +7,13 @@ import type { CustomEvent, ElementData } from '~/types'
77
*
88
* Meaning if you do not provide an id, this composable has to be called in a child of your custom edge component, or it will throw
99
*/
10-
export default function useEdge<Data = ElementData, CustomEvents extends Record<string, CustomEvent> = any>(id?: string) {
10+
export default function useEdge<T extends GraphEdge = GraphEdge>(id?: string) {
1111
const edgeId = id ?? inject(EdgeId, '')
1212
const edgeEl = inject(EdgeRef, null)
1313

1414
const { findEdge } = useVueFlow()
1515

16-
const edge = findEdge<Data, CustomEvents>(edgeId)
16+
const edge = findEdge<T>(edgeId)
1717

1818
if (!edge) {
1919
throw new VueFlowError(`Edge with id ${edgeId} not found!`, 'useEdge')

packages/core/src/composables/useNode.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CustomEvent, ElementData } from '~/types'
1+
import type { GraphNode } from '~/types'
22

33
/**
44
* Access a node, it's parent (if one exists) and connected edges
@@ -7,13 +7,13 @@ import type { CustomEvent, ElementData } from '~/types'
77
*
88
* Meaning if you do not provide an id, this composable has to be called in a child of your custom node component, or it will throw
99
*/
10-
export default function useNode<Data = ElementData, CustomEvents extends Record<string, CustomEvent> = any>(id?: string) {
10+
export default function useNode<T extends GraphNode = GraphNode>(id?: string) {
1111
const nodeId = id ?? inject(NodeId, '')
1212
const nodeEl = inject(NodeRef, null)
1313

1414
const { findNode, getEdges } = useVueFlow()
1515

16-
const node = findNode<Data, CustomEvents>(nodeId)
16+
const node = findNode<T>(nodeId)
1717

1818
if (!node) {
1919
throw new VueFlowError(`Node with id ${nodeId} not found!`, 'useNode')

0 commit comments

Comments
 (0)