Skip to content

Commit 02f3ca2

Browse files
committed
refactor(core): replace array fns
1 parent ac5e69b commit 02f3ca2

File tree

7 files changed

+353
-227
lines changed

7 files changed

+353
-227
lines changed

packages/core/src/composables/useUpdateNodePositions.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,28 @@ export function useUpdateNodePositions() {
2121
const positionDiffX = positionDiff.x * xVelo * factor
2222
const positionDiffY = positionDiff.y * yVelo * factor
2323

24-
const nodeUpdates = getSelectedNodes.value
25-
.filter((n) => n.draggable || (nodesDraggable && typeof n.draggable === 'undefined'))
26-
.map((n) => {
27-
const nextPosition = { x: n.computedPosition.x + positionDiffX, y: n.computedPosition.y + positionDiffY }
24+
const nodeUpdates: NodeDragItem[] = []
25+
for (const node of getSelectedNodes.value) {
26+
if (node.draggable || (nodesDraggable && typeof node.draggable === 'undefined')) {
27+
const nextPosition = { x: node.computedPosition.x + positionDiffX, y: node.computedPosition.y + positionDiffY }
2828

2929
const { computedPosition } = calcNextPosition(
30-
n,
30+
node,
3131
nextPosition,
3232
emits.error,
3333
nodeExtent.value,
34-
n.parentNode ? findNode(n.parentNode) : undefined,
34+
node.parentNode ? findNode(node.parentNode) : undefined,
3535
)
3636

37-
return {
38-
id: n.id,
37+
nodeUpdates.push({
38+
id: node.id,
3939
position: computedPosition,
40-
from: n.position,
40+
from: node.position,
4141
distance: { x: positionDiff.x, y: positionDiff.y },
42-
dimensions: n.dimensions,
43-
} as NodeDragItem
44-
})
42+
dimensions: node.dimensions,
43+
})
44+
}
45+
}
4546

4647
updateNodePositions(nodeUpdates, true, false)
4748
}

packages/core/src/composables/useViewportHelper.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,16 @@ export function useViewportHelper(state: State) {
132132
duration: 0,
133133
},
134134
) => {
135-
const nodesToFit: GraphNode[] = state.nodes.filter((node) => {
135+
const nodesToFit: GraphNode[] = []
136+
for (const node of state.nodes) {
136137
const isVisible = node.dimensions.width && node.dimensions.height && (options?.includeHiddenNodes || !node.hidden)
137138

138-
if (options.nodes?.length) {
139-
return isVisible && options.nodes.includes(node.id)
139+
if (isVisible) {
140+
if (!options.nodes?.length || (options.nodes?.length && options.nodes.includes(node.id))) {
141+
nodesToFit.push(node)
142+
}
140143
}
141-
142-
return isVisible
143-
})
144+
}
144145

145146
if (!nodesToFit.length) {
146147
return Promise.resolve(false)

0 commit comments

Comments
 (0)