diff --git a/src/FlowEditor/store/reducers/edge.ts b/src/FlowEditor/store/reducers/edge.ts index 1660368..4f7d60c 100644 --- a/src/FlowEditor/store/reducers/edge.ts +++ b/src/FlowEditor/store/reducers/edge.ts @@ -58,11 +58,17 @@ export const edgesReducer = (state: EdgesState, payload: EdgeDispatch): EdgesSta const { edges } = payload; if (!edges) return; - Object.keys(edges).forEach((id) => { - if (!draftState[id]) { - draftState[id] = edges[id]; - } - }); + if (Array.isArray(edges)) { + edges.forEach((edge) => { + draftState[edge.id] = edge; + }); + } else if (typeof edges === 'object') { + Object.keys(edges).forEach((id) => { + if (!draftState[id]) { + draftState[id] = edges[id]; + } + }); + } }); case 'updateEdge': diff --git a/src/FlowEditor/store/reducers/node.ts b/src/FlowEditor/store/reducers/node.ts index f2b24e5..3cd765b 100644 --- a/src/FlowEditor/store/reducers/node.ts +++ b/src/FlowEditor/store/reducers/node.ts @@ -76,11 +76,17 @@ export const nodeReducer = (state: FlattenNodes, action: NodeDispatch): FlattenN const { nodes } = action; if (!nodes) return; - Object.keys(nodes).forEach((id) => { - if (!draftState[id]) { - draftState[id] = nodes[id]; - } - }); + if (Array.isArray(nodes)) { + nodes.forEach((node) => { + draftState[node.id] = node; + }); + } else if (typeof nodes === 'object') { + Object.keys(nodes).forEach((id) => { + if (!draftState[id]) { + draftState[id] = nodes[id]; + } + }); + } }); case 'deleteNode':