feat(docs): wait for edge animation to finish to load node

This commit is contained in:
braks
2024-02-08 20:07:50 +01:00
committed by Braks
parent c9f8f6f974
commit fafad1e721
3 changed files with 84 additions and 16 deletions
+21 -1
View File
@@ -10,7 +10,7 @@ import { useVueFlow } from '@vue-flow/core'
* When a node has multiple descendants, it will run them in parallel.
*/
export function useRunProcess(dagreGraph) {
const { updateNodeData } = useVueFlow()
const { updateNodeData, getConnectedEdges } = useVueFlow()
const graph = toRef(() => toValue(dagreGraph))
@@ -23,6 +23,15 @@ export function useRunProcess(dagreGraph) {
return
}
const incomers = getConnectedEdges(node.id).filter((connection) => connection.target === node.id)
await Promise.all(incomers.map((incomer) => until(() => !incomer.data.isAnimating)))
if (!isRunning.value) {
// The process was stopped
return
}
executedNodes.add(node.id)
updateNodeData(node.id, { isRunning: true, isFinished: false, hasError: false, isCancelled: false })
@@ -121,3 +130,14 @@ export function useRunProcess(dagreGraph) {
return { run, stop, reset, isRunning }
}
async function until(condition) {
return new Promise((resolve) => {
const interval = setInterval(() => {
if (condition()) {
clearInterval(interval)
resolve()
}
}, 100)
})
}