dont invoke connection updates if the snapped handle stays the same
This commit is contained in:
@@ -314,6 +314,7 @@ const createStore = ({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
updateConnection: (connection) => {
|
updateConnection: (connection) => {
|
||||||
|
console.log('newUpdate');
|
||||||
set({ connection });
|
set({ connection });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
NodeLookup,
|
NodeLookup,
|
||||||
Position,
|
Position,
|
||||||
oppositePosition,
|
oppositePosition,
|
||||||
|
ConnectionInProgress,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
|
|
||||||
import { getClosestHandle, isConnectionValid, getHandleLookup, getHandleType } from './utils';
|
import { getClosestHandle, isConnectionValid, getHandleLookup, getHandleType } from './utils';
|
||||||
@@ -145,7 +146,7 @@ function onPointerDown(
|
|||||||
|
|
||||||
const from = getHandlePosition(fromNodeInternal, fromHandle, Position.Left, true);
|
const from = getHandlePosition(fromNodeInternal, fromHandle, Position.Left, true);
|
||||||
|
|
||||||
updateConnection({
|
const newConnection: ConnectionInProgress = {
|
||||||
inProgress: true,
|
inProgress: true,
|
||||||
isValid: null,
|
isValid: null,
|
||||||
|
|
||||||
@@ -158,7 +159,10 @@ function onPointerDown(
|
|||||||
toHandle: null,
|
toHandle: null,
|
||||||
toPosition: oppositePosition[fromHandle.position],
|
toPosition: oppositePosition[fromHandle.position],
|
||||||
toNode: null,
|
toNode: null,
|
||||||
});
|
};
|
||||||
|
|
||||||
|
updateConnection(newConnection);
|
||||||
|
let previousConnection: ConnectionInProgress = newConnection;
|
||||||
|
|
||||||
onConnectStart?.(event, { nodeId, handleId, handleType });
|
onConnectStart?.(event, { nodeId, handleId, handleType });
|
||||||
|
|
||||||
@@ -198,7 +202,7 @@ function onPointerDown(
|
|||||||
connection = result.connection;
|
connection = result.connection;
|
||||||
isValid = isConnectionValid(!!closestHandle, result.isValid);
|
isValid = isConnectionValid(!!closestHandle, result.isValid);
|
||||||
|
|
||||||
updateConnection({
|
const newConnection: ConnectionInProgress = {
|
||||||
inProgress: true,
|
inProgress: true,
|
||||||
isValid,
|
isValid,
|
||||||
|
|
||||||
@@ -214,7 +218,21 @@ function onPointerDown(
|
|||||||
toHandle: result.toHandle,
|
toHandle: result.toHandle,
|
||||||
toPosition: isValid && result.toHandle ? result.toHandle.position : oppositePosition[fromHandle.position],
|
toPosition: isValid && result.toHandle ? result.toHandle.position : oppositePosition[fromHandle.position],
|
||||||
toNode: result.toHandle ? nodeLookup.get(result.toHandle.nodeId)!.internals.userNode : null,
|
toNode: result.toHandle ? nodeLookup.get(result.toHandle.nodeId)!.internals.userNode : null,
|
||||||
});
|
};
|
||||||
|
|
||||||
|
// we don't want to trigger an update when the connection
|
||||||
|
// is snapped to the same handle as before
|
||||||
|
if (
|
||||||
|
previousConnection.toHandle &&
|
||||||
|
newConnection.toHandle &&
|
||||||
|
previousConnection.toHandle.nodeId === newConnection.toHandle.nodeId &&
|
||||||
|
previousConnection.toHandle.id === newConnection.toHandle.id
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateConnection(newConnection);
|
||||||
|
previousConnection = newConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onPointerUp(event: MouseEvent | TouchEvent) {
|
function onPointerUp(event: MouseEvent | TouchEvent) {
|
||||||
|
|||||||
Reference in New Issue
Block a user