Closed amfl closed 5 years ago
this.closed
works with the 'option' Outputs. It prevents calling of following nodes. If you want to prepare data for other nodes, you must to return it in worker (instead of writing to outputs
argument)
3.
task.run('any data');
worker(node, inputs, data) { // the last parameter contains data ('any data' string) that you pass when running task
Thanks @Ni55aN! I don't think I understand it completely yet, but I was able to get some code working with your explanation above.
Just to clarify....
,________, ,________, ,________,
| | --- option --> | | | |
| Node A | | Node B | --- output --> | Node C |
|________| --- output --> |________| |________|
In the situation above, Node A can receive an event which would cause it to update Node B because it has an option
which connects it. That update CANNOT flow through from Node B to Node C unless there is a new editor.trigger("process")
. Is that correct?
In the situation above, Node A can receive an event which would cause it to update Node B because it has an option which connects it
Exactly
That update CANNOT flow through from Node B to Node C unless there is a new editor.trigger("process")
Not really, trigger("process") is only required to initialize tasks, not to execute them
Okay, that makes sense.
Thanks for your detailed answers, @Ni55aN!
@amfl you are welcome!
Hi, execute me. In my case,
Input Component
;Text Component
。But, in Text Component
, worker not be execute.
Is necessary connect Ajax Component
and Text Component
use option socket?
This is console.log
This is Ajax Component
This is Text Component
My English is not very good, hope you can understand. Thanks.
@hughfenghen does the TextComponent's constructor have a task
property?
https://rete.readthedocs.io/en/latest/Plugins/#task
yeah, this is TextComponent's code
export class TextComp extends Rete.Component {
constructor () {
super('Text')
this.task = {
outputs: {}
}
}
builder (node) {
node.addInput(new Rete.Input('text', 'input', dataSocket))
}
async worker (node, inputs, outputs) {
console.log('-----text worker:', inputs, outputs)
}
}
package.json
"dependencies": {
"rete": "^1.0.0-beta.5",
"rete-connection-plugin": "^0.2.4",
"rete-context-menu-plugin": "^0.2.4",
"rete-task-plugin": "^0.1.7",
"rete-vue-render-plugin": "^0.2.4"
}
What AjaxComponent' constructor contains ?
@Ni55aN I create a demo https://codesandbox.io/s/oojzmw1vz6
export class AjaxComp extends Rete.Component {
constructor () {
super('Ajax')
this.task = {
outputs: {
ajaxOutput: 'output',
evtAct: 'option'
}
}
}
builder (node) {
node.addInput(new Rete.Input('evtAct', 'option', dataSocket))
.addInput(new Rete.Input('inputStr', 'input str', dataSocket))
.addOutput(new Rete.Output('ajaxData', 'ajax data', dataSocket))
}
async worker (node, inputs, data) {
console.log('------ajax worker:', inputs, data)
const rs = await ajax()
console.log('------ajax result:', inputs, data)
return { ajaxData: rs }
}
}
1.AjaxComp should have Output with "action" socket. Otherwise it will not be able to transfer control to the next node. Type of this Outputs is defined in this.task.outputs. So
this.task = {
outputs: {
ajaxOutput: 'output',
evtAct: 'option'
}
}
is wrong because evtAct
isn't Output, and Output with key ajaxOutput
hasn't defined.
This should works:
export class AjaxComp extends Rete.Component {
constructor () {
super('Ajax')
this.task = {
outputs: {
evtAct: 'option',
ajaxData: 'output'
}
}
}
builder (node) {
node.addInput(new Rete.Input('evtAct', 'option', actSocket))
.addInput(new Rete.Input('inputStr', 'input str', dataSocket))
.addOutput(new Rete.Output('evtAct', 'action', actSocket))
.addOutput(new Rete.Output('ajaxData', 'ajax data', dataSocket))
}
async worker (node, inputs, data) {
console.log('------ajax worker:', inputs, data)
const rs = await ajax()
console.log('------ajax result:', inputs, data)
return { ajaxData: rs }
}
}
In short, this plugin requires the object this.task.outputs {
emm... it working after add a ActionSocket. https://codesandbox.io/s/oojzmw1vz6
But as the number of nodes increases, ActionSocket seems to be redundant.
ActionSocket fulfills its role, sockets for data - its own. Each has its own purpose, so they must be separated.
I am struggling to understand how to use the task plugin.
I have seen some components on the site which use it and read the documentation but I still don't get it.
option
and anoutput
?this.closed
and sometimes return values?data
, and why does it replaceoutputs
?Sorry if I am being daft.