jerosoler / Drawflow

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

Adding unique ids for outputs/inputs? #343

Closed galanflorind closed 2 years ago

galanflorind commented 2 years ago

Hello, To begin, I'd like to mention that this library is pretty cool, and I enjoy working with it. It has saved me a lot of time.

I've hit a problem that's pretty big for me, I need to add/remove outputs/inputs dynamically from an external panel, and having the ids of the outputs/inputs incremented causes a lot of problems and I'm not seeing any other way than finding a way to add unique ids to inputs/outputs.

Is there a way to add unique ids for outputs/inputs that won't change when I remove an output/input? (when i have output_1, output_2 and output_3, if i remove output_2, output_3 becomes output_2)

Thanks!

jerosoler commented 2 years ago

Hi @galanflorind

Thanks!

You can see this issue which deals with the same problem.

galanflorind commented 2 years ago

@jerosoler Thank you for your prompt answer!

I've seen that issue but at the same time I would need to pass an ID there (only having a number would be pretty hard on making all the logic we have behind), somehow I would need a unique id.

Is there a way to attach a unique ID or is it something that needs too much change and we need to find a workaround with output_[number] and see what we could do?

jerosoler commented 2 years ago

As described in the previous issue, you have to modify the addNodeImport, you could use it to modify the addNode as well and add something like this:

editor.addNode(name, [ID,ID,ID], [ID,ID,ID], posx, posy, class, data, html);

Basically the addNode and addNodeImport functions are almost identical, I even think they could be unified.

galanflorind commented 2 years ago

I see, thanks for the directions!