Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task plugin documentation #170

Closed
MrWizardGN opened this issue Sep 1, 2018 · 11 comments
Closed

Task plugin documentation #170

MrWizardGN opened this issue Sep 1, 2018 · 11 comments

Comments

@MrWizardGN
Copy link

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
Copy link
Member

Ni55aN commented Sep 1, 2018

Hello @MrWizardGN

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

@Ni55aN
Copy link
Member

Ni55aN commented Sep 1, 2018

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

@MrWizardGN
Copy link
Author

MrWizardGN commented Sep 1, 2018

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
Copy link
Member

Ni55aN commented Sep 1, 2018

@MrWizardGN some answers about the work of the plugin retejs/task-plugin#1

Can you share your live example on codesandbox?

@MrWizardGN
Copy link
Author

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
Copy link
Member

Ni55aN commented Sep 1, 2018

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
Copy link
Author

MrWizardGN commented Sep 1, 2018

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
Copy link

telcy commented Sep 1, 2018

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
Copy link
Member

Ni55aN commented Sep 1, 2018

@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
Copy link
Member

Ni55aN commented Sep 1, 2018

@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
Copy link

telcy commented Sep 1, 2018

Thanks, that absolutely makes sense now.

@Ni55aN Ni55aN closed this as completed Sep 2, 2018
This was referenced Sep 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants