jerosoler / Drawflow

Simple flow library 🖥️🖱️
https://jerosoler.github.io/Drawflow/
MIT License
4.61k stars 721 forks source link

Getting node data when node is deleted #159

Closed iamnikhilrohan closed 3 years ago

iamnikhilrohan commented 3 years ago

Is there a way to get node info in node removed event

editor.on('nodeRemoved',function(id){ editor.getNodeFromId(id) })

i saw that getNodeFromId() returns an error when we try to access a removed node. Is there a way to get the info about the deleted node?

jerosoler commented 3 years ago

Hello @iamnikhilrohan

You cannot access the information because it is already deleted.

Try this, I have changed the order of the event trigger before it has been deleted.

  editor.removeNodeId = function (id) {
    this.removeConnectionNodeId(id);
    var moduleName = this.getModuleFromNodeId(id.slice(5))
    if(this.module === moduleName) {
      this.container.querySelector(`#${id}`).remove();
    }
    this.dispatch('nodeRemoved', id.slice(5)); //Changed
    delete this.drawflow.drawflow[moduleName].data[id.slice(5)]; //Changed

  }

Jero

iamnikhilrohan commented 3 years ago

Thanks @jerosoler for the lighting quick reply! and Thanks, it solved my problem.