noflo:dynamic组件加载 – 组件不可用于base

我收到错误:

Component [name] not available with base [path]

试图将组件dynamic附加到networking的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方法。 诀窍是通过将NoFlonetworking作为第三个parameter passing,以延迟模式启动NoFlonetworking。 这样它就不会马上开始执行,你可以先注册你的组件。

 // 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); 

另一种select是在你的项目中注册一个自定义的ComponentLoader。 这样你就不需要在启动networking时做任何特别的事情。

例如,在Node.js上查看浏览器或MicroFlo( 清单 , 自定义加载程序 )中的noflo-polymer( 清单 , 定制加载程序 )是如何完成的。

自NoFlo 0.5.1以来,已经支持自定义组件加载器。