retejs / rete

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

[FR] Safer inputs for workers and other improvements #124

Closed trsh closed 5 years ago

trsh commented 6 years ago

For now it's like this:

.....
return node
         .addInput(inp1)
         .addInput(inp2)
         .addControl(numControl)
         .addOutput(out);
   },
   worker(node, inputs, outputs) {
      var sum = inputs[0][0] + inputs[1][0];
      editor.nodes.find(n => n.id == node.id).controls[0].setValue(sum);
      outputs[0] = sum;
   }

I suggest something like this

...
return node
         .addInput('kavabanga1', inp1)
         .addInput('kavabanga2', inp2)
         .addControl(numControl)
         .addOutput(out);
   },
   worker(node, inputs, outputs) {
      var sum = inputs['kavabanga1'][0] + inputs['kavabanga2'][0];
      editor.nodes.find(n => n.id == node.id).controls[0].setValue(sum);
      outputs[0] = sum;
   }

This way you don't care if the order you add inputs changes. In Bonus it will alarm you, if change the inputs and not worker with new stuff at some level.

editor.nodes.find(n => n.id == node.id).controls[0].setValue(sum);

AS for this. Any chance to get controls / real node without this full scan? Or at least do it on core code and push it under node? if I have 100 nodes, it would make ~100x100 loop in summ, that seems much :). Have no suggestions right now. The solution should not be over-complicated

trsh commented 6 years ago

Same for Outputs. .addOutput('kavabanga3', a).

I think this overall is very trivial. Especially if play/change the IO on run.

Ni55aN commented 6 years ago

Yeah, it's make sense. I'll investigate it

trsh commented 6 years ago

Thanks

Ni55aN commented 5 years ago

v1.0.0-alpha.7 released

https://github.com/retejs/rete/releases/tag/v1.0.0-alpha.7

Example updated: https://codepen.io/Ni55aN/pen/xzgQYq?editors=0010

Also changes affected the task-plugin and module-plugin

module-plugin compatible with rete v1.0.0-alpha.7 starting with v0.1.3 task-plugin compatible with rete v1.0.0-alpha.7 starting with v0.1.6

trsh commented 5 years ago

(clap) tnx