fix(hooks): repair useStoreActions hook
This commit is contained in:
@@ -158,9 +158,7 @@ interface UpdateTransform {
|
||||
|
||||
interface UpdateSize {
|
||||
type: typeof UPDATE_SIZE;
|
||||
payload: {
|
||||
size: Dimensions;
|
||||
};
|
||||
payload: Dimensions;
|
||||
}
|
||||
|
||||
interface InitD3Zoom {
|
||||
|
||||
+38
-4
@@ -161,10 +161,8 @@ export const updateTransform = (transform: Transform): ActionTypes => ({
|
||||
export const updateSize = (size: Dimensions): ActionTypes => ({
|
||||
type: UPDATE_SIZE,
|
||||
payload: {
|
||||
size: {
|
||||
width: size.width || 500,
|
||||
height: size.height || 500,
|
||||
},
|
||||
width: size.width || 500,
|
||||
height: size.height || 500,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -241,3 +239,39 @@ export const setConnectionMode = (connectionMode: ConnectionMode): ActionTypes =
|
||||
type: SET_CONNECTION_MODE,
|
||||
payload: { connectionMode },
|
||||
});
|
||||
|
||||
export const actions = {
|
||||
setOnConnect,
|
||||
setOnConnectStart,
|
||||
setOnConnectStop,
|
||||
setOnConnectEnd,
|
||||
setElements,
|
||||
batchUpdateNodeDimensions,
|
||||
updateNodeDimensions,
|
||||
updateNodePos,
|
||||
updateNodePosDiff,
|
||||
setUserSelection,
|
||||
updateUserSelection,
|
||||
unsetUserSelection,
|
||||
setSelection,
|
||||
unsetNodesSelection,
|
||||
resetSelectedElements,
|
||||
setSelectedElements,
|
||||
addSelectedElements,
|
||||
updateTransform,
|
||||
updateSize,
|
||||
initD3Zoom,
|
||||
setMinZoom,
|
||||
setMaxZoom,
|
||||
setTranslateExtent,
|
||||
setConnectionPosition,
|
||||
setConnectionNodeId,
|
||||
setSnapToGrid,
|
||||
setSnapGrid,
|
||||
setInteractive,
|
||||
setNodesDraggable,
|
||||
setNodesConnectable,
|
||||
setElementsSelectable,
|
||||
setMultiSelectionActive,
|
||||
setConnectionMode,
|
||||
};
|
||||
|
||||
+7
-12
@@ -1,24 +1,19 @@
|
||||
import { bindActionCreators, ActionCreatorsMapObject } from 'redux';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import { useStore as useStoreRedux, useSelector, useDispatch, TypedUseSelectorHook } from 'react-redux';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { ReactFlowState, AppDispatch } from './index';
|
||||
import { ActionTypes } from './action-types';
|
||||
import { actions } from './actions';
|
||||
|
||||
export const useTypedSelector: TypedUseSelectorHook<ReactFlowState> = useSelector;
|
||||
|
||||
export function useActions(actions: ActionTypes, deps?: any): ActionTypes {
|
||||
export function useActions(actionSelector: any): any {
|
||||
const dispatch: AppDispatch = useDispatch();
|
||||
|
||||
const action = useMemo(
|
||||
() => {
|
||||
if (Array.isArray(actions)) {
|
||||
return actions.map((a) => bindActionCreators(a, dispatch));
|
||||
}
|
||||
return bindActionCreators<ActionCreatorsMapObject<ActionTypes>>(actions, dispatch);
|
||||
},
|
||||
deps ? [dispatch, ...deps] : [dispatch]
|
||||
);
|
||||
const action = useMemo(() => {
|
||||
const currAction = actionSelector(actions);
|
||||
return bindActionCreators(currAction, dispatch);
|
||||
}, [dispatch, actionSelector]);
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
+1
-1
@@ -306,7 +306,7 @@ export function reactFlowReducer(state = initialState, action: ActionTypes): Rea
|
||||
isDragging,
|
||||
position: {
|
||||
x: el.__rf.position.x + diff.x,
|
||||
y: el.__rf.position.x + diff.y,
|
||||
y: el.__rf.position.y + diff.y,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user