jerosoler / Drawflow

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

Error in connectionRemoved event #475

Closed cer718 closed 2 years ago

cer718 commented 2 years ago

Hi,

I faced a new problem. After clearing the editor as in the code below, I created the editor again.

        editor.events = {};
        editor.postion = {};
        editor?.clear();
        editor = null;
        editor = new Drawflow(id);

And I registered connectionRemoved event listener, but error occur like below. I think the problem was caused by using the same node id as the previously created editor.

drawflow.min.js?21b5:1 Uncaught TypeError: Cannot read properties of undefined (reading 'outputs')
    at i.removeConnection (drawflow.min.js?21b5:1:41356)
    at i.key (drawflow.min.js?21b5:1:14731)

Please advise. Thank you for your help as always.

jerosoler commented 2 years ago

Try reset all parameters.

De default constructor is:

constructor(container, render = null, parent = null) {
    this.events = {};
    this.container = container;
    this.precanvas = null;
    this.nodeId = 1;
    this.ele_selected = null;
    this.node_selected = null;
    this.drag = false;
    this.reroute = false;
    this.reroute_fix_curvature = false;
    this.curvature = 0.5;
    this.reroute_curvature_start_end = 0.5;
    this.reroute_curvature = 0.5;
    this.reroute_width = 6;
    this.drag_point = false;
    this.editor_selected = false;
    this.connection = false;
    this.connection_ele = null;
    this.connection_selected = null;
    this.canvas_x = 0;
    this.canvas_y = 0;
    this.pos_x = 0;
    this.pos_x_start = 0;
    this.pos_y = 0;
    this.pos_y_start = 0;
    this.mouse_x = 0;
    this.mouse_y = 0;
    this.line_path = 5;
    this.first_click = null;
    this.force_first_input = false;
    this.draggable_inputs = true;
    this.useuuid = false;
    this.parent = parent;

    this.noderegister = {};
    this.render = render;
    this.drawflow = { "drawflow": { "Home": { "data": {} }}};
    // Configurable options
    this.module = 'Home';
    this.editor_mode = 'edit';
    this.zoom = 1;
    this.zoom_max = 1.6;
    this.zoom_min = 0.5;
    this.zoom_value = 0.1;
    this.zoom_last_value = 1;

    // Mobile
    this.evCache = new Array();
    this.prevDiff = -1;
  }
cer718 commented 2 years ago

I checked that the problem was caused by not unregistering the event listener when changing the Drawflow object to null and clear. So I modified my project to use one HTML Element for one drawflow. My project no longer nulls/clears objects.

Thank you for supporting