1

我收到错误消息:

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;
4

1 回答 1

1

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

// 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(清单自定义加载器)或 Node.js 上的 MicroFlo(清单自定义加载器)中完成此操作。

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

于 2014-06-17T16:55:22.540 回答