retejs / rete

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

Input sockets for controls? #563

Closed exellian closed 1 year ago

exellian commented 2 years ago

Is it somehow possible to create an input socket for a control. I didn't find anything on docs. Or is there some way to workaround this?

jayemes commented 2 years ago

You can use the input of the node and pass the value to the control like this:

worker(node, inputs, outputs) {
    const n1 = inputs.num1.length ? inputs.num1[0] : node.data.num1;
    const n2 = inputs.num2.length ? inputs.num2[0] : node.data.num2;
    const sum = n1 + n2;

    this.editor.nodes
      .find((n) => n.id === node.id)
      .controls.get("preview")
      .setValue(sum);
    outputs.num = sum;
  }

where setValue is this function on the Control:

 setValue(val) {
    this.props.value = val.toFixed(3);
    this.putData(this.key, val);
    this.update();
  }

If you need a full example I can share it with you

rete-js[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.