Skip to content

Commit f9d9d29

Browse files
committed
chore(core): update find action types
Signed-off-by: braks <[email protected]>
1 parent 9f06717 commit f9d9d29

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Diff for: packages/core/src/store/actions.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,22 @@ export function useActions(state: State, getters: ComputedGetters): Actions {
3838
state.hooks.updateNodeInternals.trigger(updateIds)
3939
}
4040

41-
const findNode: Actions['findNode'] = (id) => {
42-
if (state.nodes && !nodeIds.length) return state.nodes.find((node) => node.id === id)
41+
const findNode: Actions['findNode'] = <T extends GraphNode = GraphNode>(id: string) => {
42+
let node
4343

44-
return state.nodes[nodeIds.indexOf(id)]
44+
if (state.nodes && !nodeIds.length) node = state.nodes.find((node) => node.id === id)
45+
else node = state.nodes[nodeIds.indexOf(id)]
46+
47+
return node as T | undefined
4548
}
4649

47-
const findEdge: Actions['findEdge'] = (id) => {
48-
if (state.edges && !edgeIds.length) return state.edges.find((edge) => edge.id === id)
50+
const findEdge: Actions['findEdge'] = <T extends GraphEdge = GraphEdge>(id: string) => {
51+
let edge
52+
53+
if (state.edges && !edgeIds.length) edge = state.edges.find((edge) => edge.id === id)
54+
else edge = state.edges[edgeIds.indexOf(id)]
4955

50-
return state.edges[edgeIds.indexOf(id)]
56+
return edge as T | undefined
5157
}
5258

5359
const updateNodePositions: Actions['updateNodePositions'] = (dragItems, changed, dragging) => {

0 commit comments

Comments
 (0)