Engine

This component allows you to process Flow-based data in nodes and transfer them from an output to input. The engine is independent of other components of the editor. All it needs is an identifier, workers from components and JSON data.

var engine = new Rete.Engine('demo@0.1.0');

engine.register(myComponent);
await engine.process(data);

It can work independently from, and without knowing anything about NodeEditor.

How it works:

Processing

Consider the situation when during the work in the editor you need to immediately receive the results of the changes (this is easy to do with change event)

editor.on('process', () => {
    engine.process(editor.toJSON()); // imagine that it could take one second of time
});

The user will be annoyed that the editor hangs. In fact, the process method is also asynchronous, so you can call it many times without waiting for the previous one to complete. To avoid this, use the abort method, which waits until the previous processing is canceled.

editor.on('process', async () => {
    await engine.abort();
    await engine.process(editor.toJSON());
});

Now this gives a guarantee that only one processing at a time will be performed, and the previous one will be canceled when the data is changed

Usually there is some main node from which the processing should start or all data go to it, then you can specify it:

engine.process(data, node.id);

If in any situation you need the data that you specify when processing

engine.process(data, null, arg1, arg2);

To each worker executed by this process will transfared this arguments

worker(node, inputs, outputs, arg1, arg2){
     outputs[0] = node.data.num;
}

If an error occurs during processing (detected recursion, wrong startId, invalid data), you can get its message and data (if any)

engine.on('error', ({ message, data }) => {

});

Cross-platform

D3-Node-Engine for C++