Skip to content

Commit

Permalink
✨ feat: add addNodes function ways
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangchu committed Jul 22, 2024
1 parent c7eea15 commit 1265d94
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
16 changes: 11 additions & 5 deletions src/FlowEditor/store/reducers/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
16 changes: 11 additions & 5 deletions src/FlowEditor/store/reducers/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down

0 comments on commit 1265d94

Please sign in to comment.