fix(edges): edge-renderer to update on edge updates

This commit is contained in:
braks
2022-10-07 22:55:38 +02:00
committed by Braks
parent f0f24cee5c
commit 8c0982a7f3
3 changed files with 7 additions and 8 deletions
@@ -67,10 +67,8 @@ onPaneReady(() => {
if (!scope) scope = effectScope()
scope.run(() => {
const edgeAmount = computed(() => getEdges.length)
watch(
[$$(getSelectedNodes), edgeAmount],
[$$(getSelectedNodes), $$(getEdges)],
() => {
getEdges.forEach((edge) => {
if (hooks[edge.id]) return
+1 -2
View File
@@ -353,8 +353,7 @@ export default (state: State, getters: ComputedGetters): Actions => {
return state.edges[edgeIds.indexOf(id)]
}
const updateEdge: Actions['updateEdge'] = (oldEdge, newConnection) =>
updateEdgeAction(oldEdge, newConnection, state.edges, addEdges)
const updateEdge: Actions['updateEdge'] = (oldEdge, newConnection) => updateEdgeAction(oldEdge, newConnection, state.edges)
const applyNodeChanges: Actions['applyNodeChanges'] = (changes) => applyChanges(changes, state.nodes)
+5 -3
View File
@@ -23,7 +23,7 @@ export const addEdgeToStore = (edgeParams: Edge | Connection, edges: Edge[]) =>
return edge
}
export const updateEdgeAction = (edge: GraphEdge, newConnection: Connection, edges: GraphEdge[], add: Actions['addEdges']) => {
export const updateEdgeAction = (edge: GraphEdge, newConnection: Connection, edges: GraphEdge[]) => {
if (!newConnection.source || !newConnection.target) {
console.warn("[vueflow]: Can't create new edge. An edge needs a source and a target.")
return false
@@ -36,7 +36,8 @@ export const updateEdgeAction = (edge: GraphEdge, newConnection: Connection, edg
return false
}
edges.splice(edges.indexOf(edge), 1)
console.log('foo')
const newEdge = {
...edge,
id: getEdgeId(newConnection),
@@ -45,7 +46,8 @@ export const updateEdgeAction = (edge: GraphEdge, newConnection: Connection, edg
sourceHandle: newConnection.sourceHandle,
targetHandle: newConnection.targetHandle,
}
add([newEdge])
edges.splice(edges.indexOf(foundEdge), 1, newEdge)
return newEdge
}