noflo:动态组件加载 - 组件[名称]不适用于base [path]

时间:2014-06-17 16:41:29

标签: javascript node.js noflo

我收到错误:

Component [name] not available with base [path]

尝试将组件动态附加到网络的ComponentLoader实例时。

var components = []; // This is populated with noflo.Component instances at runtime.
var graph = {
    properties: { name: 'Test components' },
    processes: {
        log: { component: 'log' },
        split: { component: 'split' }
    },
    connections: [
        {
            data: 'John Doe',
            tgt: { process: 'split', port: 'in' }
        },
        {
            src: { process: 'split', port: 'left' },
            tgt: { process: 'log', port: 'in' }
        },
        {
            src: { process: 'split', port: 'right' },
            tgt: { process: 'log', port: 'in' }
        }
    ]
};

noflo.graph.loadJSON(graph, function(g) {

    noflo.createNetwork(g, function(n) {

        var getComponent = function(c) {
            return c;
        }

        for (var i = 0; i < components.length; i++) {

            var c = components[i];
            n.loader.components[c.key] = {};
            n.loader.components[c.key].getComponent = getComponent.bind(null, c);

        };

    });
});

我还尝试将组件直接分配给加载器中组件集合的属性:

n.loader.components[c.key] = c;

1 个答案:

答案 0 :(得分:1)

您可以使用NoFlo ComponentLoader的registerComponent方法。诀窍是通过将true作为第三个参数传递,以延迟模式启动NoFlo网络。这样它就不会立即开始执行,您可以先将组件注册到它。

// Create NoFlo network in delayed mode (see the third param in the end)
noflo.createNetwork(g, function(n) {

  // Register the custom components
  components.forEach (function (component) {
    n.loader.registerComponent('myproject', component.key, {
      getComponent: function () { return component; }
    });
  });

  // Once the components have been registered we can wire up and start it
  n.connect(function () {
    n.start();
  });

}, true);

另一种选择是在项目中注册自定义ComponentLoader。这样,在启动网络时,你不需要做任何特别的事情。

例如,请参阅浏览器上的noflo-polymer(manifestcustom loader)或Node.js上的MicroFlo(manifestcustom loader)的完成情况。 / p>

支持自定义组件加载器since NoFlo 0.5.1