retejs / rete

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

Using Rete.js without a visual part #352

Closed limuyao closed 5 years ago

limuyao commented 5 years ago

Hi Ni55aN ! Thanks for the awesome lib! I want to ask: How do i use Rete.js without a visual part of it?

I mean, i want to use it with Node.js at the server side of my application. So i tried to use a simple code from documentation (https://rete.js.org/#/docs) and want to use Rete.js without 'Editor' But it doesn't works (I suppose "it works" string at the console). the code of main.js is here:

'use strict';

import Rete from "rete";

const numSocket = new Rete.Socket('Number value');
class NumComponent extends Rete.Component {
  constructor() {
    super('Number');
  }

  builder(node) {
    let out = new Rete.Output('num', 'Number', numSocket);

    node.addOutput(out);
  }

  worker(node, inputs, outputs) {
    console.log('it works!');
    //outputs['num'] = node.data.num;
  }
}
const numComponent = new NumComponent();

const engine = new Rete.Engine('demo@0.1.0');
engine.register(numComponent);

let map = '{"id":"demo@0.1.0","nodes":{"1":{"id":1,"data":{},"inputs":{},"outputs":{"num":{"connections":[]}},"position":[102,54],"name":"Number"}}}';

(async () =>{
    await engine.abort();
    await engine.process(map);
})();

the error:

$ node main.js
(node:5468) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'split' of undefined
    at Function.validate (webpack:///./node_modules/rete/build/rete.esm.js?:738:25)
    at Engine._callee11$ (webpack:///./node_modules/rete/build/rete.esm.js?:2621:38)
    at tryCatch (webpack:///./node_modules/regenerator-runtime/runtime.js?:65:40)
    at Generator.invoke [as _invoke] (webpack:///./node_modules/regenerator-runtime/runtime.js?:303:22)
    at Generator.prototype.(anonymous function) [as next] (webpack:///./node_modules/regenerator-runtime/runtime.js?:117:21)
    at asyncGeneratorStep (webpack:///./node_modules/rete/build/rete.esm.js?:21:24)
    at _next (webpack:///./node_modules/rete/build/rete.esm.js?:43:9)
    at eval (webpack:///./node_modules/rete/build/rete.esm.js?:50:7)
    at new Promise (<anonymous>)
    at Engine.eval (webpack:///./node_modules/rete/build/rete.esm.js?:39:12)

Thank you for any kind of help

Ni55aN commented 5 years ago
await engine.process(map); // map should be a json format, not a string
limuyao commented 5 years ago

oh such a silly mistake... Thank you! It works now!