From 0747ab595d97599c158330dd8865a5cd825c30d9 Mon Sep 17 00:00:00 2001 From: bpostlethwaite Date: Tue, 6 Sep 2022 10:53:10 -0700 Subject: [PATCH] return disconnect responses before removal response This allows for a more logical order of cleanup operations in user code. Disconnect and clean up the node before removal. --- egui_node_graph/src/editor_ui.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/egui_node_graph/src/editor_ui.rs b/egui_node_graph/src/editor_ui.rs index 5ecfc60..1311b9b 100644 --- a/egui_node_graph/src/editor_ui.rs +++ b/egui_node_graph/src/editor_ui.rs @@ -242,17 +242,19 @@ where } NodeResponse::DeleteNodeUi(node_id) => { let (node, disc_events) = self.graph.remove_node(*node_id); + // Pass the disconnection responses first so user code can perform cleanup + // before node removal response. + extra_responses.extend( + disc_events + .into_iter() + .map(|(input, output)| NodeResponse::DisconnectEvent { input, output }), + ); // Pass the full node as a response so library users can // listen for it and get their user data. extra_responses.push(NodeResponse::DeleteNodeFull { node_id: *node_id, node, }); - extra_responses.extend( - disc_events - .into_iter() - .map(|(input, output)| NodeResponse::DisconnectEvent { input, output }), - ); self.node_positions.remove(*node_id); // Make sure to not leave references to old nodes hanging if self.selected_node.map(|x| x == *node_id).unwrap_or(false) {