Skip to content

Commit 0cdff91

Browse files
committed
chore(core): cleanup getters
Signed-off-by: braks <[email protected]>
1 parent d59cc78 commit 0cdff91

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

packages/core/src/store/getters.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,50 @@ export function useGetters(state: State): ComputedGetters {
66
const edgeIds = computed(() => state.edges.map((e) => e.id))
77

88
const getNode: ComputedGetters['getNode'] = computed(() => (id: string) => {
9-
if (state.nodes && !nodeIds.value.length) return state.nodes.find((node) => node.id === id)
9+
if (state.nodes && !nodeIds.value.length) {
10+
return state.nodes.find((node) => node.id === id)
11+
}
12+
1013
return state.nodes[nodeIds.value.indexOf(id)]
1114
})
1215

1316
const getEdge: ComputedGetters['getEdge'] = computed(() => (id: string) => {
14-
if (state.edges && !edgeIds.value.length) return state.edges.find((edge) => edge.id === id)
17+
if (state.edges && !edgeIds.value.length) {
18+
return state.edges.find((edge) => edge.id === id)
19+
}
20+
1521
return state.edges[edgeIds.value.indexOf(id)]
1622
})
1723

18-
const getEdgeTypes = computed(() => {
24+
const getEdgeTypes: ComputedGetters['getEdgeTypes'] = computed(() => {
1925
const edgeTypes: Record<string, any> = {
2026
...defaultEdgeTypes,
2127
...state.edgeTypes,
2228
}
29+
2330
const keys = Object.keys(edgeTypes)
31+
2432
state.edges?.forEach((e) => e.type && !keys.includes(e.type) && (edgeTypes[e.type] = e.type))
33+
2534
return edgeTypes
2635
})
2736

28-
const getNodeTypes = computed(() => {
37+
const getNodeTypes: ComputedGetters['getNodeTypes'] = computed(() => {
2938
const nodeTypes: Record<string, any> = {
3039
...defaultNodeTypes,
3140
...state.nodeTypes,
3241
}
42+
3343
const keys = Object.keys(nodeTypes)
44+
3445
state.nodes?.forEach((n) => n.type && !keys.includes(n.type) && (nodeTypes[n.type] = n.type))
46+
3547
return nodeTypes
3648
})
3749

38-
const getNodes = computed<GraphNode[]>(() => {
50+
const getNodes: ComputedGetters['getNodes'] = computed(() => {
3951
const nodes = state.nodes.filter((n) => !n.hidden)
52+
4053
return state.onlyRenderVisibleElements
4154
? nodes &&
4255
getNodesInside(
@@ -67,7 +80,7 @@ export function useGetters(state: State): ComputedGetters {
6780
return !e.hidden && !target.hidden && !source.hidden
6881
}
6982

70-
const getEdges = computed<GraphEdge[]>(() => {
83+
const getEdges: ComputedGetters['getEdges'] = computed(() => {
7184
if (!state.onlyRenderVisibleElements) return state.edges.filter((edge) => edgeHidden(edge))
7285

7386
return state.edges.filter((e) => {

0 commit comments

Comments
 (0)