jerosoler / Drawflow

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

How can remove event listener? #474

Closed cer718 closed 2 years ago

cer718 commented 2 years ago

Hi,

I registered <div id='drawflow'> and deleted it after using it.

const el = document.getElementsByClassName('drawflow')[0]; el?.remove();

And if you try to register and use a new <div id='drawflow'>, the event occurs twice.

Is there any way to delete the editor's event listener when deleting an element?

Thanks for helping

cer718 commented 2 years ago

I tried calling editor.clear(), but the following error occurs in the event handler.

Uncaught TypeError: Cannot read properties of undefined (reading 'data')
    at i.getNodeFromId (drawflow.min.js?21b5:1:29555)
    at eval (index.tsx?07ff:311:60)
    at eval (drawflow.min.js?21b5:1:45969)
    at Array.forEach (<anonymous>)
    at i.dispatch (drawflow.min.js?21b5:1:45932)
    at i.click `(drawflow.min.js?21b5:1:5538)
jerosoler commented 2 years ago

Remove events with:

editor.events = {};
// Register new events. 
jerosoler commented 2 years ago

Or remove manual event create:

editor.removeListener(event, callback);
cer718 commented 2 years ago

Thanks for your help 👍 It works well