Skip to content

Commit

Permalink
Merge pull request #256 from PrefectHQ/replace-foreach-with-for-of
Browse files Browse the repository at this point in the history
Replace forEach with for of for performance
  • Loading branch information
pleek91 authored Oct 20, 2023
2 parents 4c8745e + 8021e18 commit d7222b9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/factories/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function nodesContainerFactory(runId: string) {
}

function setPositions(): void {
layout.forEach((position, nodeId) => {
for (const [nodeId, position] of layout) {
const node = nodes.get(nodeId)

if (!node) {
Expand All @@ -89,7 +89,7 @@ export async function nodesContainerFactory(runId: string) {
}

node.container.position = getActualPosition(position)
})
}

container.emit('resized')
container.emit('rendered')
Expand Down
8 changes: 4 additions & 4 deletions src/workers/layouts/horizontal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ function getHorizontalDependencyLayout({ data, horizontalSettings }: ClientLayou
const scale = horizontalScaleFactory(horizontalSettings)
const layout: HorizontalLayout = new Map()

data.nodes.forEach((node, nodeId) => {
for (const [nodeId] of data.nodes) {
layout.set(nodeId, scale(levels.get(nodeId)!))
})
}

return layout
}
Expand All @@ -29,9 +29,9 @@ function getHorizontalTimeLayout({ data, horizontalSettings }: ClientLayoutMessa
const scale = horizontalScaleFactory(horizontalSettings)
const layout: HorizontalLayout = new Map()

data.nodes.forEach((node, nodeId) => {
for (const [nodeId, node] of data.nodes) {
layout.set(nodeId, scale(node.start_time))
})
}

return layout
}
Expand Down
4 changes: 2 additions & 2 deletions src/workers/layouts/vertical.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ function getVerticalWaterfallLayout(message: ClientLayoutMessage): VerticalLayou

let index = 0

message.data.nodes.forEach((node, nodeId) => {
for (const [nodeId] of message.data.nodes) {
layout.set(nodeId, index++)
})
}

return layout
}
Expand Down
4 changes: 2 additions & 2 deletions src/workers/runGraph.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function handleLayoutMessage(message: ClientLayoutMessage): void {
const vertical = getVerticalLayout(message, horizontal)
const layout: NodeLayoutResponse = new Map()

data.nodes.forEach((node, nodeId) => {
for (const [nodeId, node] of data.nodes) {
const x = horizontal.get(nodeId)
const y = vertical.get(nodeId)

Expand All @@ -46,7 +46,7 @@ function handleLayoutMessage(message: ClientLayoutMessage): void {
x,
y,
})
})
}

post({
type: 'layout',
Expand Down

0 comments on commit d7222b9

Please sign in to comment.