noflo:动态组件加载-组件[name]与基础[path]不可用

noflo: Dynamic component loading - Component [name] not available with base [path]

本文关键字:path name 动态 组件 加载 -组件 noflo      更新时间:2023-09-26

我得到错误:

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;

您可以使用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 (manifest,自定义加载器)或Node.js上的MicroFlo (manifest,自定义加载器)。

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