Skip to content

Commit

Permalink
Register all graphs from current project with the Graph protocol handler
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed Sep 4, 2020
1 parent 479337f commit bd84409
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
21 changes: 17 additions & 4 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
9 changes: 6 additions & 3 deletions src/protocol/Graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ class GraphProtocol extends EventEmitter {
// Pass the project baseDir
graph.baseDir = this.transport.options.baseDir;

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

registerGraph(id, graph, context = null) {
registerGraph(id, graph, context = null, propagate = true) {
// Prepare the network
this.transport.network.initNetwork(graph, id, context, (err, network) => {
if (err) {
Expand All @@ -123,8 +123,11 @@ class GraphProtocol extends EventEmitter {
},
context);

const fullName = graph.properties.library ? `${graph.properties.library}/${id}` : id;
if (!propagate) {
return;
}

const fullName = graph.properties.library ? `${graph.properties.library}/${id}` : id;
// Register for runtime exported ports
this.transport.runtime.registerNetwork(id, network);
if (graph.name === 'main' || graph.properties.main) {
Expand Down

0 comments on commit bd84409

Please sign in to comment.