chore(connections): get fresh ref of onConnectEnd

This commit is contained in:
moklick
2023-02-05 21:58:30 +01:00
parent ada190f028
commit 7a652fc17c
@@ -2,7 +2,7 @@ import type { MouseEvent as ReactMouseEvent, TouchEvent as ReactTouchEvent } fro
import { StoreApi } from 'zustand'; import { StoreApi } from 'zustand';
import { getHostForElement, calcAutoPan, getEventPosition } from '../../utils'; import { getHostForElement, calcAutoPan, getEventPosition } from '../../utils';
import type { OnConnect, HandleType, ReactFlowState, Connection, ConnectionStatus } from '../../types'; import type { OnConnect, HandleType, ReactFlowState, Connection } from '../../types';
import { pointToRendererPoint, rendererPointToPoint } from '../../utils/graph'; import { pointToRendererPoint, rendererPointToPoint } from '../../utils/graph';
import { import {
ConnectionHandle, ConnectionHandle,
@@ -46,7 +46,6 @@ export function handlePointerDown({
autoPanOnConnect, autoPanOnConnect,
connectionRadius, connectionRadius,
onConnectStart, onConnectStart,
onConnectEnd,
panBy, panBy,
getNodes, getNodes,
cancelConnection, cancelConnection,
@@ -159,7 +158,9 @@ export function handlePointerDown({
onConnect?.(connection); onConnect?.(connection);
} }
onConnectEnd?.(event); // it's important to get a fresh reference from the store here
// in order to get the latest state of onConnectEnd
getState().onConnectEnd?.(event);
if (edgeUpdaterType) { if (edgeUpdaterType) {
onEdgeUpdateEnd?.(event); onEdgeUpdateEnd?.(event);