Skip to content

Commit 9f06717

Browse files
committed
refactor(core): change generic of useNode, useEdges
Signed-off-by: braks <[email protected]>
1 parent 41f08c3 commit 9f06717

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
import { VueFlowError } from '~/utils/errors'
33

44
/**
@@ -8,13 +8,13 @@ import { VueFlowError } from '~/utils/errors'
88
*
99
* 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
1010
*/
11-
export default function useEdge<Data = ElementData, CustomEvents extends Record<string, CustomEvent> = any>(id?: string) {
11+
export default function useEdge<T extends GraphEdge = GraphEdge>(id?: string) {
1212
const edgeId = id ?? inject(EdgeId, '')
1313
const edgeEl = inject(EdgeRef, null)
1414

1515
const { findEdge, emits } = useVueFlow()
1616

17-
const edge = findEdge<Data, CustomEvents>(edgeId)
17+
const edge = findEdge<T>(edgeId)
1818

1919
if (!edge) {
2020
emits.error(new VueFlowError(ErrorCode.EDGE_NOT_FOUND, edgeId))

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, emits } = useVueFlow()
1515

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

1818
if (!node) {
1919
emits.error(new VueFlowError(ErrorCode.NODE_NOT_FOUND, nodeId))

0 commit comments

Comments
 (0)