refactor(core): allow passing single element to add actions

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
braks
2023-05-11 15:33:42 +02:00
committed by Braks
parent d9f8cf49d2
commit ca9eda98dd
2 changed files with 11 additions and 4 deletions
+4 -2
View File
@@ -413,7 +413,8 @@ export function useActions(
}
const addNodes: Actions['addNodes'] = (nodes) => {
const nextNodes = nodes instanceof Function ? nodes(state.nodes) : nodes
let nextNodes = nodes instanceof Function ? nodes(state.nodes) : nodes
nextNodes = Array.isArray(nextNodes) ? nextNodes : [nextNodes]
const graphNodes = createGraphNodes(nextNodes, state.nodes, findNode, state.hooks.error.trigger)
@@ -425,7 +426,8 @@ export function useActions(
}
const addEdges: Actions['addEdges'] = (params) => {
const nextEdges = params instanceof Function ? params(state.edges) : params
let nextEdges = params instanceof Function ? params(state.edges) : params
nextEdges = Array.isArray(nextEdges) ? nextEdges : [nextEdges]
const validEdges = state.isValidConnection
? nextEdges.filter((edge) =>