'onConnectionRemoved' called before 'onConnectionCreated'
See original GitHub issueFor some reason, my code emits the ‘onConnectionRemoved’ before ‘onConnectionCreated’ when I try to delete a connection after it is made.
Steps to reproduce below: (See codepen.io)
let editor = new Drawflow(document.querySelector("#drawflow"));
editor.start();
editor.addNode("Home", 0, 1, 10, 10, "node-test", {}, "Drag from here =>", false);
editor.addNode("Home", 1, 0, 300, 10, "node-test", {}, "<= Connect to here", false);
// Issue: When we delete just after creating a connection, the events
// below get fired incorrently. First "connectionRemoved", then "connectionCreated"
editor.on("connectionCreated", deleteCreatedConnection)
editor.on("connectionCreated", () => console.log("connectionCreated"));
editor.on("connectionRemoved", () => console.log("connectionRemoved"));
// Registering the listener after fixes the problem somehow?
// editor.on("connectionCreated", deleteCreatedConnection)
function deleteCreatedConnection({input_id, output_id, input_class, output_class}) {
editor.removeSingleConnection(output_id, input_id, output_class, input_class);
}
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I found a workaround by deleting the connection in the next event loop using a timeout (still not ideal):
Thanks for the thorough explanation, and yes internally events are handled in a synchronous fashion, however logically one could sort the scheduled events to avoid this.
I wrote a wrapper class that makes instantiates Drawflow and make internal changes, like modifying the curves and listening to
connectionCreated
to delete specified connections. After instantiating my wrapper class, one might want to use the same event twice. In this case, I add a listener toconnectionCreated
, andconnectionRemove
, to update the state of the connected nodes, but events aren’t played in order.