retejs / rete

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

Task plugin documentation #170

Closed MrWizardGN closed 6 years ago

MrWizardGN commented 6 years ago

Hello @Ni55aN ,

we are trying to use rete js to automate certain processes within our software. We are trying to make a simple If/Else structure

image

The problem here is that both nodes worker will still be executed, even though we only want it to go into either the one connect to true or false.

Is it normal that all nodes get executed at all times? Is it suppose to also go through connection sockets that dont get any output? How can we prevent it? I can see in your Task plugin example that you achieved this via the plugin, but it seems like the code example is outdated, we already tried to fiddle around with this with no luck. Any pointers or updates on the documentation for it? We dont want all nodes to get executed, only the ones that get a valid output.

Any help is much appreciated. Thanks in advance

Ni55aN commented 6 years ago

Hello @MrWizardGN

For now I'll update an example for Task plugin on codepen

Ni55aN commented 6 years ago

Example has been updated: https://codepen.io/Ni55aN/pen/MOYPEz?editors=0010

MrWizardGN commented 6 years ago

Hello @Ni55aN, thanks for the quick response. Unfortunately i can't get it to work.

here is how my chart looks like.

image

Here is the modified code of my Text component for testing purposes. Do i misunderstand the concept of rete js? Shouldn't the node connected to text2 not get executed at all? (Not execute the worker logic that is) (tried to include it as code snippets with the tags, but it ruined the formating, sorry for the images)

Text component: image

Log component: image

Anything you can spot thats wrong or maybe just misunderstanding the concept ? Thanks again

Ni55aN commented 6 years ago

@MrWizardGN some answers about the work of the plugin https://github.com/retejs/task-plugin/issues/1

Can you share your live example on codesandbox?

MrWizardGN commented 6 years ago

Let me see if i can prepare it

on a side note: if i remove the: init: function(task) { // сalled when initializing all tasks (at the engine.process()) task.run(); task.reset(); }

from the log component, it wont fire at all anymore, but on your AlertComponent you also didnt use any init. Any idea what's wrong here?

Ni55aN commented 6 years ago

from the log component, it wont fire at all anymore, but on your AlertComponent you also didnt use any init. Any idea what's wrong here?

Alert does not have init() because it is called by other nodes and should not be called by any factors from outside.

For example, Keydown event should be fired from an outside factor (keydown event). This is similar to Event nodes in UE4 Blueprint.

ue4 blueprint events

In our case the white socket is an Output with an 'option' type

MrWizardGN commented 6 years ago

Ok, thanks for the clarification on the init part. This means i need some sort of "Starting" component. So for a simple test i did the following: image

Start Component:

class Start extends Rete.Component {
  constructor() {
    super("Start");
    this.task = {
      outputs: {
      },
      init: function(task) {  // сalled when initializing all tasks (at the engine.process())
        task.run();
        task.reset();
      }
    }
  }

    builder(node) {
        node.addOutput(new Rete.Output('action', "Action", Sockets.action));
        return node
    }

    worker(node, inputs, outputs) {
        console.log("Start");
    }
}

Test Component(Only logs to console):

class Test extends Rete.Component {
  constructor() {
    super("Test");
    this.task = {
      outputs: {
          in:'option'
      }
    }
  }

    builder(node) {
        node.addOutput(new Rete.Output('in', "Action", Sockets.action));
        node.addInput(new Rete.Input('out', "Action", Sockets.action));
        return node
    }

    worker(node, inputs, outputs) {
        console.log("Test");
    }
}

Now the result is the same, it doesnt even execute the following node at all. I was assuming that it worked before, because i had the Init everywhere. But i guess it gets called on all nodes if they have it.

So for my understanding, it should now in theory execute the "Test" component correct?(Which is not happening though)

telcy commented 6 years ago

Here is a codepen demo of the problem: https://codepen.io/telcy/pen/XPMXGM

Maybe you can bring some light here why the Test Component does not receive anything.

Ni55aN commented 6 years ago

@telcy

  1. you shouldn't call the task.run() inside init synchoniously
  2. StartComponent doesn't have { action: 'option'} in this.task.outputs
  3. TestComponent have whong keys in Input and Output (conversely)
Ni55aN commented 6 years ago

@telcy https://codepen.io/Ni55aN/pen/oPZxRr

The engine.process() initializes the tasks. Running tasks should be performed after initialization (not immediately inside the init()). Moreover, this approach implies that you need to initialize the tasks once and you can run them many times.

telcy commented 6 years ago

Thanks, that absolutely makes sense now.