retejs / rete

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

Not understanding how Modules work #330

Closed timwea closed 5 years ago

timwea commented 5 years ago

I've analyzed the Module demo a dozen times and I cannot figure out where the logic to multiply input values by 2 is defined.

class ModuleComponent extends Rete.Component {

    constructor() {
        super("Module");
        this.module = {
            nodeType: 'module'
        }
    }

    builder(node) {
        var ctrl = new TextControl(this.editor, 'module');
        ctrl.onChange = () => {
            console.log(this)
            this.updateModuleSockets(node);
            node._alight.scan();
        }
        return node.addControl(ctrl);
    }

    change(node, item) {
        node.data.module = item;
        this.editor.trigger('process');
    }
}

What am I missing? Is it just magic?

Ni55aN commented 5 years ago

where the logic to multiply input values by 2 is defined

that login described in Node editor module's scheme

Opera Снимок_2019-06-26_203323_codepen io Opera Снимок_2019-06-26_203510_codepen io

timwea commented 5 years ago

that login described in Node editor module's scheme

are you saying the schema in the bottom pic is what's going on under the hood of the Module node in the top pic? where is the definition for this in the code? for example there seems to be a hardcoded '2' in the bottom socket of the Module node. is this coming from the Output none in the bottom schema? what if I want it to be 3?

Ni55aN commented 5 years ago

are you saying the schema in the bottom pic is what's going on under the hood of the Module node in the top pic?

exactly

hardcoded '2'

its just a label. Schemes for modules placed in https://rawgit.com/retejs/examples/master/Module/data.js

is this coming from the Output none

Output socket of the Module node will return value from the "Output" node of this module

timwea commented 5 years ago

Got it. Thanks!