refactor(actions): combine batch update and update node dimension actions

This commit is contained in:
moklick
2021-02-11 19:14:30 +01:00
parent 9b70e1e0fa
commit 1d1a17c80a
6 changed files with 6 additions and 41 deletions
+1 -29
View File
@@ -87,7 +87,7 @@ export default function reactFlowReducer(state = initialState, action: ReactFlow
return { ...state, nodes: nextNodes, edges: nextEdges };
}
case constants.BATCH_UPDATE_NODE_DIMENSIONS: {
case constants.UPDATE_NODE_DIMENSIONS: {
const updatedNodes = state.nodes.map((node) => {
const update = action.payload.find((u) => u.id === node.id);
if (update) {
@@ -119,34 +119,6 @@ export default function reactFlowReducer(state = initialState, action: ReactFlow
nodes: updatedNodes,
};
}
case constants.UPDATE_NODE_DIMENSIONS: {
const { nodeElement, id } = action.payload;
const dimensions = getDimensions(nodeElement);
if (!dimensions.width || !dimensions.height) {
return state;
}
const nextNodes = state.nodes.map((node) => {
if (node.id === id) {
const handleBounds = getHandleBounds(nodeElement, state.transform[2]);
return {
...node,
__rf: {
...node.__rf,
width: dimensions.width,
height: dimensions.height,
handleBounds,
},
};
}
return node;
});
return { ...state, nodes: nextNodes };
}
case constants.UPDATE_NODE_POS: {
const { id, pos } = action.payload;