chore(docs): cleanup comments
This commit is contained in:
@@ -96,6 +96,7 @@ watch(isAnimating, (isAnimating) => {
|
|||||||
const edge = findEdge(props.id)
|
const edge = findEdge(props.id)
|
||||||
|
|
||||||
if (edge) {
|
if (edge) {
|
||||||
|
// we set the `isAnimating` flag, so we can wait until the next node gets executed
|
||||||
edge.data = {
|
edge.data = {
|
||||||
...edge.data,
|
...edge.data,
|
||||||
isAnimating,
|
isAnimating,
|
||||||
@@ -112,6 +113,7 @@ watch(edgePoint, (point) => {
|
|||||||
|
|
||||||
const nextLength = pathEl.getTotalLength()
|
const nextLength = pathEl.getTotalLength()
|
||||||
|
|
||||||
|
// if length changed, restart animation
|
||||||
if (currentLength.value !== nextLength) {
|
if (currentLength.value !== nextLength) {
|
||||||
runAnimation()
|
runAnimation()
|
||||||
return
|
return
|
||||||
@@ -135,12 +137,15 @@ async function runAnimation() {
|
|||||||
|
|
||||||
const totalLength = pathEl.getTotalLength()
|
const totalLength = pathEl.getTotalLength()
|
||||||
|
|
||||||
|
// if animation restarted, use last edgePoint value to continue from
|
||||||
const from = edgePoint.value || 0
|
const from = edgePoint.value || 0
|
||||||
|
|
||||||
|
// update initial label position
|
||||||
labelPosition.value = pathEl.getPointAtLength(from)
|
labelPosition.value = pathEl.getPointAtLength(from)
|
||||||
|
|
||||||
isAnimating.value = true
|
isAnimating.value = true
|
||||||
|
|
||||||
|
// update currentLength value, so we can check if the path length changed during animation
|
||||||
if (currentLength.value !== totalLength) {
|
if (currentLength.value !== totalLength) {
|
||||||
currentLength.value = totalLength
|
currentLength.value = totalLength
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,12 +27,15 @@ export function useRunProcess({ dagreGraph, cancelOnError = true }) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// save the upcoming task in case it gets cancelled before we even start it
|
||||||
upcomingTasks.add(node.id)
|
upcomingTasks.add(node.id)
|
||||||
|
|
||||||
const incomers = getConnectedEdges(node.id).filter((connection) => connection.target === node.id)
|
const incomers = getConnectedEdges(node.id).filter((connection) => connection.target === node.id)
|
||||||
|
|
||||||
|
// wait for edge animations to finish before starting the process
|
||||||
await Promise.all(incomers.map((incomer) => until(() => !incomer.data.isAnimating)))
|
await Promise.all(incomers.map((incomer) => until(() => !incomer.data.isAnimating)))
|
||||||
|
|
||||||
|
// remove the upcoming task since we are about to start it
|
||||||
upcomingTasks.clear()
|
upcomingTasks.clear()
|
||||||
|
|
||||||
if (!isRunning.value) {
|
if (!isRunning.value) {
|
||||||
@@ -40,20 +43,23 @@ export function useRunProcess({ dagreGraph, cancelOnError = true }) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mark the node as executed, so it doesn't run again
|
||||||
executedNodes.add(node.id)
|
executedNodes.add(node.id)
|
||||||
|
|
||||||
updateNodeData(node.id, { isRunning: true, isFinished: false, hasError: false, isCancelled: false })
|
updateNodeData(node.id, { isRunning: true, isFinished: false, hasError: false, isCancelled: false })
|
||||||
|
|
||||||
// Simulate an async process with a random timeout between 1 and 3 seconds
|
// simulate an async process with a random timeout between 1-2 seconds
|
||||||
const delay = Math.floor(Math.random() * 2000) + 1000
|
const delay = Math.floor(Math.random() * 2000) + 1000
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const timeout = setTimeout(
|
const timeout = setTimeout(
|
||||||
async () => {
|
async () => {
|
||||||
const children = graph.value.successors(node.id)
|
const children = graph.value.successors(node.id)
|
||||||
|
|
||||||
// Randomly decide whether the node will throw an error
|
// randomly decide whether the node will throw an error
|
||||||
const willThrowError = Math.random() < 0.15
|
const willThrowError = Math.random() < 0.15
|
||||||
|
|
||||||
|
// we avoid throwing an error on the starting node
|
||||||
if (!isStart && willThrowError) {
|
if (!isStart && willThrowError) {
|
||||||
updateNodeData(node.id, { isRunning: false, hasError: true })
|
updateNodeData(node.id, { isRunning: false, hasError: true })
|
||||||
|
|
||||||
@@ -71,15 +77,17 @@ export function useRunProcess({ dagreGraph, cancelOnError = true }) {
|
|||||||
runningTasks.delete(node.id)
|
runningTasks.delete(node.id)
|
||||||
|
|
||||||
if (children.length > 0) {
|
if (children.length > 0) {
|
||||||
// Run the process on the children in parallel
|
// run the process on the children in parallel
|
||||||
await Promise.all(children.map((id) => runNode({ id })))
|
await Promise.all(children.map((id) => runNode({ id })))
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve()
|
resolve()
|
||||||
},
|
},
|
||||||
|
// if this is a starting node, we don't want to wait
|
||||||
isStart ? 0 : delay,
|
isStart ? 0 : delay,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// save the timeout so we can cancel it if needed
|
||||||
runningTasks.set(node.id, timeout)
|
runningTasks.set(node.id, timeout)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -93,10 +101,10 @@ export function useRunProcess({ dagreGraph, cancelOnError = true }) {
|
|||||||
|
|
||||||
isRunning.value = true
|
isRunning.value = true
|
||||||
|
|
||||||
// Get all starting nodes (nodes with no predecessors)
|
// get all starting nodes (nodes with no predecessors)
|
||||||
const startingNodes = nodes.filter((node) => graph.value.predecessors(node.id)?.length === 0)
|
const startingNodes = nodes.filter((node) => graph.value.predecessors(node.id)?.length === 0)
|
||||||
|
|
||||||
// Run the process on all starting nodes in parallel
|
// run the process on all starting nodes in parallel
|
||||||
await Promise.all(startingNodes.map((node) => runNode(node, true)))
|
await Promise.all(startingNodes.map((node) => runNode(node, true)))
|
||||||
|
|
||||||
clear()
|
clear()
|
||||||
|
|||||||
Reference in New Issue
Block a user