feat(flow): Promisify updateNodePosition

* helps with selected nodes dragging performance
This commit is contained in:
Braks
2022-04-11 11:30:10 +02:00
parent 3be164b20e
commit bf2c77fb59
2 changed files with 20 additions and 12 deletions
+16 -10
View File
@@ -117,21 +117,27 @@ const createGraphNodes = (nodes: Node[], getNode: Getters['getNode'], currGraphN
export default (state: State, getters: ComputedGetters): Actions => {
const updateNodePosition: Actions['updateNodePosition'] = ({ id, diff = { x: 0, y: 0 }, dragging }) => {
const changes: NodePositionChange[] = []
const nodePosPromise = new Promise<NodePositionChange[]>((resolve) => {
const changes: NodePositionChange[] = []
state.nodes.forEach((node) => {
if (node.selected) {
if (!node.parentNode) {
changes.push(createPositionChange({ node, diff, nodeExtent: state.nodeExtent, dragging }, state.nodes))
} else if (!isParentSelected(node, getters.getNode.value)) {
state.nodes.forEach((node) => {
if (node.selected) {
if (!node.parentNode) {
changes.push(createPositionChange({ node, diff, nodeExtent: state.nodeExtent, dragging }, state.nodes))
} else if (!isParentSelected(node, getters.getNode.value)) {
changes.push(createPositionChange({ node, diff, nodeExtent: state.nodeExtent, dragging }, state.nodes))
}
} else if (node.id === id) {
changes.push(createPositionChange({ node, diff, nodeExtent: state.nodeExtent, dragging }, state.nodes))
}
} else if (node.id === id) {
changes.push(createPositionChange({ node, diff, nodeExtent: state.nodeExtent, dragging }, state.nodes))
}
})
if (changes.length) resolve(changes)
})
if (changes.length) state.hooks.nodesChange.trigger(changes)
nodePosPromise.then((changes) => {
state.hooks.nodesChange.trigger(changes)
})
}
const updateNodeDimensions: Actions['updateNodeDimensions'] = (updates) => {