Skip to content

Commit 93bed0d

Browse files
committed
refactor(core): change generic of useNode, useEdges
Signed-off-by: braks <[email protected]>
1 parent 8e4ef50 commit 93bed0d

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,6 +1,6 @@
11
import { inject } from 'vue'
22
import { useVueFlow } from './useVueFlow'
3-
import type { CustomEvent, ElementData } from '~/types'
3+
import type { GraphEdge } from '~/types'
44
import { ErrorCode, VueFlowError } from '~/utils'
55
import { EdgeId, EdgeRef } from '~/context'
66

@@ -11,13 +11,13 @@ import { EdgeId, EdgeRef } from '~/context'
1111
*
1212
* 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
1313
*/
14-
export function useEdge<Data = ElementData, CustomEvents extends Record<string, CustomEvent> = any>(id?: string) {
14+
export function useEdge<T extends GraphEdge = GraphEdge>(id?: string) {
1515
const edgeId = id ?? inject(EdgeId, '')
1616
const edgeEl = inject(EdgeRef, null)
1717

1818
const { findEdge, emits } = useVueFlow()
1919

20-
const edge = findEdge<Data, CustomEvents>(edgeId)
20+
const edge = findEdge<T>(edgeId)
2121

2222
if (!edge) {
2323
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,6 +1,6 @@
11
import { computed, inject } from 'vue'
22
import { useVueFlow } from './useVueFlow'
3-
import type { CustomEvent, ElementData } from '~/types'
3+
import type { GraphNode } from '~/types'
44
import { NodeId, NodeRef } from '~/context'
55
import { ErrorCode, VueFlowError, getConnectedEdges } from '~/utils'
66

@@ -11,13 +11,13 @@ import { ErrorCode, VueFlowError, getConnectedEdges } from '~/utils'
1111
*
1212
* 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
1313
*/
14-
export function useNode<Data = ElementData, CustomEvents extends Record<string, CustomEvent> = any>(id?: string) {
14+
export function useNode<T extends GraphNode = GraphNode>(id?: string) {
1515
const nodeId = id ?? inject(NodeId, '')
1616
const nodeEl = inject(NodeRef, null)
1717

1818
const { findNode, edges, emits } = useVueFlow()
1919

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

2222
if (!node) {
2323
emits.error(new VueFlowError(ErrorCode.NODE_NOT_FOUND, nodeId))

0 commit comments

Comments
 (0)