Merge pull request #2657 from wbkd/refactor/node-drag
Refactor Nodes: only trigger drag event when change happened
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@reactflow/core': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Only trigger drag event when change happened
|
||||||
@@ -108,6 +108,9 @@ function useDrag({
|
|||||||
x: pointerPos.xSnapped,
|
x: pointerPos.xSnapped,
|
||||||
y: pointerPos.ySnapped,
|
y: pointerPos.ySnapped,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let hasChange = false;
|
||||||
|
|
||||||
dragItems.current = dragItems.current.map((n) => {
|
dragItems.current = dragItems.current.map((n) => {
|
||||||
const nextPosition = { x: pointerPos.x - n.distance.x, y: pointerPos.y - n.distance.y };
|
const nextPosition = { x: pointerPos.x - n.distance.x, y: pointerPos.y - n.distance.y };
|
||||||
|
|
||||||
@@ -118,12 +121,20 @@ function useDrag({
|
|||||||
|
|
||||||
const updatedPos = calcNextPosition(n, nextPosition, nodeInternals, nodeExtent, nodeOrigin);
|
const updatedPos = calcNextPosition(n, nextPosition, nodeInternals, nodeExtent, nodeOrigin);
|
||||||
|
|
||||||
|
// we want to make sure that we only fire a change event when there is a changes
|
||||||
|
hasChange =
|
||||||
|
hasChange || n.position.x !== updatedPos.position.x || n.position.y !== updatedPos.position.y;
|
||||||
|
|
||||||
n.position = updatedPos.position;
|
n.position = updatedPos.position;
|
||||||
n.positionAbsolute = updatedPos.positionAbsolute;
|
n.positionAbsolute = updatedPos.positionAbsolute;
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!hasChange) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const onDrag = nodeId ? onNodeDrag : wrapSelectionDragFunc(onSelectionDrag);
|
const onDrag = nodeId ? onNodeDrag : wrapSelectionDragFunc(onSelectionDrag);
|
||||||
|
|
||||||
updateNodePositions(dragItems.current, true, true);
|
updateNodePositions(dragItems.current, true, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user