retejs / rete

JavaScript framework for visual programming
https://retejs.org
MIT License
9.86k stars 647 forks source link

Feature : onDelete #118

Closed JMidd91 closed 6 years ago

JMidd91 commented 6 years ago

Hi,

would it be possible to implement an onDelete function to the nodes?

so any code we put into the onDelete part of a node, it executes before it gets removed from the screen when we hit the delete key.

kind of like a final update? incase we need any thing removing that our nodes added.

hope that makes sense!

kind regards

JMidd91 commented 6 years ago

Maybe an onInputChange may be a good shout also, or onInputRemoval

Ni55aN commented 6 years ago

onDelete must be called after or before deleting node? Component's destroyed() provide such ability (calls after a node deleted)

If you want to execute some method before deleting or even prevent deletion, you can subscribe to the noderemove event

editor.on('noderemove', node => {
    return false; // false to prevent
});
// or editor.eventListener in v0.7.4 and earlier
JMidd91 commented 6 years ago

oh ok i will give that a try!

JMidd91 commented 6 years ago

could you give me a basic example of where destroyed() would go in a component ? im running v0.7.3 at the moment. I couldnt find it in the docs

Ni55aN commented 6 years ago

https://github.com/retejs/rete/issues/72

new D3NE.Component('mycomp', {
    builder(node){ },
    worker(node, inputs, outputs){ },
    created(node){ }.
    destroyed(node){ }
});
JMidd91 commented 6 years ago

Awesome thank you very much. Will give it a try ASAP.

JMidd91 commented 6 years ago

this works a charm! can be closed now 👍

Ni55aN commented 5 years ago

https://github.com/retejs/lifecycle-plugin