Skip to content

Commit

Permalink
remove function instances when def is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
39bytes committed Dec 22, 2023
1 parent e2deae6 commit 6431f3e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/renderer/src/stores/flowchart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ export const useFlowchartStore = create<FlowchartState>()(
},

removeDefinition: (definitionBlockId: BlockID) => {
const instances = get().nodes.filter(
(n) =>
n.data.block_type === 'function_instance' &&
n.data.definition_block_id === definitionBlockId
);
const instanceIds = new Set(instances.map((n) => n.id));

set({
edges: get().edges.filter(
(e) => !instanceIds.has(e.source) && !instanceIds.has(e.target)
),
nodes: get().nodes.filter((n) => !instanceIds.has(n.id))
});
set((state) => {
delete state.functionDefinitionBlocks[definitionBlockId];
});
Expand Down

0 comments on commit 6431f3e

Please sign in to comment.