Skip to content

Commit

Permalink
Merge bd84409 into f731e9e
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed Sep 4, 2020
2 parents f731e9e + bd84409 commit a5f38f2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 24 deletions.
23 changes: 18 additions & 5 deletions src/protocol/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const debounce = require('debounce');
const {
EventEmitter,
} = require('events');
const utils = require('../utils');
const { parseName } = require('../utils');

class ComponentProtocol extends EventEmitter {
static initClass() {
Expand Down Expand Up @@ -72,13 +72,14 @@ class ComponentProtocol extends EventEmitter {
return loader.getSource(payload.name, (err, component) => {
if (err) {
// Try one of the registered graphs
const graph = this.transport.graph.graphs[payload.name];
const nameParts = parseName(payload.name);
const graph = this.transport.graph.graphs[payload.name]
|| this.transport.graph.graphs[nameParts.name];
if (graph == null) {
this.send('error', err, context);
return;
}

const nameParts = utils.parseName(payload.name);
this.send('source', {
name: nameParts.name,
library: nameParts.library,
Expand Down Expand Up @@ -119,15 +120,27 @@ class ComponentProtocol extends EventEmitter {
callback(err);
return;
}

const { library, name: componentName } = parseName(component);
// Ensure graphs are not run automatically when just querying their ports
if (!instance.isReady()) {
instance.once('ready', () => {
if (instance.isSubgraph()
&& library === this.transport.options.namespace
&& !this.transport.graph.graphs[componentName]) {
// Register subgraph also to the graph protocol handler
this.transport.graph.registerGraph(componentName, instance.network.graph, null, false);
}
this.sendComponent(component, instance, context);
callback(null);
});
return;
}
if (instance.isSubgraph()
&& library === this.transport.options.namespace
&& !this.transport.graph.graphs[component]) {
// Register subgraph also to the graph protocol handler
this.transport.graph.registerGraph(componentName, instance.network.graph, null, false);
}
this.sendComponent(component, instance, context);
callback(null);
},
Expand Down Expand Up @@ -197,7 +210,7 @@ class ComponentProtocol extends EventEmitter {
this.send('error', err, context);
return;
}
loader.registerComponent('', id, graph);
loader.registerComponent(graph.properties.library, id, graph);
// Send initial graph info back to client
send();
});
Expand Down
40 changes: 21 additions & 19 deletions src/protocol/Graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,12 @@ class GraphProtocol extends EventEmitter {
}
const graph = new noflo.Graph(payload.name || 'NoFlo runtime');
graph.properties.id = payload.id;
graph.properties.main = payload.main;

let fullName = payload.id;
let { library } = payload;
if (library) {
library = library.replace('noflo-', '');
graph.properties.library = library;
fullName = `${library}/${fullName}`;
}
if (payload.icon) {
graph.properties.icon = payload.icon;
Expand All @@ -100,29 +99,38 @@ class GraphProtocol extends EventEmitter {
// Pass the project baseDir
graph.baseDir = this.transport.options.baseDir;

this.registerGraph(payload.id, graph, context, true);
}

registerGraph(id, graph, context = null, propagate = true) {
// Prepare the network
this.transport.network.initNetwork(graph, payload.id, context, (err, network) => {
this.transport.network.initNetwork(graph, id, context, (err, network) => {
if (err) {
this.send('error', err, context);
return;
}

this.subscribeGraph(payload.id, graph, context);
this.subscribeGraph(id, graph, context);

this.graphs[payload.id] = graph;
this.graphs[id] = graph;
this.sendAll('clear', {
id: payload.id,
name: payload.name,
library: payload.library,
main: payload.main,
icon: payload.icon,
description: payload.description,
id,
name: graph.name,
library: graph.properties.library,
main: graph.properties.main,
icon: graph.properties.icon,
description: graph.properties.description,
},
context);

if (!propagate) {
return;
}

const fullName = graph.properties.library ? `${graph.properties.library}/${id}` : id;
// Register for runtime exported ports
this.transport.runtime.registerNetwork(payload.id, network);
if (payload.main) {
this.transport.runtime.registerNetwork(id, network);
if (graph.name === 'main' || graph.properties.main) {
this.transport.runtime.setMainGraph(fullName, graph, context);
} else {
// Register to component loading
Expand All @@ -131,12 +139,6 @@ class GraphProtocol extends EventEmitter {
});
}

registerGraph(id, graph) {
if (id === 'default/main') { this.transport.runtime.setMainGraph(id, graph); }
this.subscribeGraph(id, graph, '');
this.graphs[id] = graph;
}

subscribeGraph(id, graph, context) {
graph.on('addNode', (node) => {
this.sendAll('addnode', {
Expand Down

0 comments on commit a5f38f2

Please sign in to comment.