From f8111f97abfa44b19ce8dcb2fd38568c9f56d5d3 Mon Sep 17 00:00:00 2001 From: Daniel Lobo Date: Thu, 24 Nov 2022 09:48:38 -0300 Subject: [PATCH] setNodes --- src/index.js | 4 ++++ src/nodesReducer.js | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/index.js b/src/index.js index 56c8b106..65e1b520 100644 --- a/src/index.js +++ b/src/index.js @@ -111,6 +111,10 @@ export let NodeEditor = ( }, getComments: () => { return comments; + }, + setNodes: newNodes => { + dispatchNodes({ type: "SET_NODES", nodes: newNodes }); + triggerRecalculation(); } })); diff --git a/src/nodesReducer.js b/src/nodesReducer.js index adac3518..390f656b 100644 --- a/src/nodesReducer.js +++ b/src/nodesReducer.js @@ -329,6 +329,12 @@ const nodesReducer = ( return removeNode(nodes, nodeId); } + case "SET_NODES": { + const newNodes = { ...action.nodes }; + nodesReducer(newNodes, { type: "HYDRATE_DEFAULT_NODES", nodes: newNodes }, { nodeTypes, portTypes, cache, circularBehavior, context, connectionMode }, dispatchToasts); + return newNodes; + } + case "HYDRATE_DEFAULT_NODES": { const newNodes = { ...nodes }; for (const key in newNodes) {