Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Transmit node metadata to component instances, fixes #145

  • Loading branch information...
commit 671afe1dc4d3683077b4b183c745d4331eb3dd7c 1 parent 1025428
@bergie bergie authored
View
1  CHANGES.md
@@ -5,6 +5,7 @@ NoFlo ChangeLog
* Support for loading graph definitions via AJAX on browser-based NoFlo
* Support for delayed initialization of Subgraph components via ComponentLoader
+* Component instances now get the node's metadata passed to the `getComponent` function
* New methods for manipulating Graph metadata:
- `setProperties`
- `setInportMetadata`
View
7 spec/Network.coffee
@@ -79,7 +79,12 @@ describe 'NoFlo Network', ->
chai.expect(n.processes.Graph).to.exist
done()
, 10
- g.addNode 'Graph', 'Graph'
+ g.addNode 'Graph', 'Graph',
+ foo: 'Bar'
+ it 'should have transmitted the node metadata to the process', ->
+ chai.expect(n.processes.Graph.component.metadata).to.exist
+ chai.expect(n.processes.Graph.component.metadata).to.be.an.object
+ chai.expect(n.processes.Graph.component.metadata).to.eql g.getNode('Graph').metadata
it 'should not contain the node after removal', (done) ->
g.once 'removeNode', ->
setTimeout ->
View
4 src/components/Graph.coffee
@@ -4,7 +4,7 @@ else
noflo = require '../lib/NoFlo'
class Graph extends noflo.Component
- constructor: ->
+ constructor: (@metadata) ->
@network = null
@ready = true
@started = false
@@ -163,4 +163,4 @@ class Graph extends noflo.Component
return unless @network
@network.stop()
-exports.getComponent = -> new Graph
+exports.getComponent = (metadata) -> new Graph metadata
View
22 src/lib/ComponentLoader.coffee
@@ -63,10 +63,10 @@ class ComponentLoader
callback @components
- load: (name, callback, delayed) ->
+ load: (name, callback, delayed, metadata) ->
unless @components
@listComponents (components) =>
- @load name, callback
+ @load name, callback, delayed, metadata
return
component = @components[name]
unless component
@@ -84,27 +84,27 @@ class ComponentLoader
if typeof process isnt 'undefined' and process.execPath and process.execPath.indexOf('node') isnt -1
# nextTick is faster on Node.js
process.nextTick =>
- @loadGraph name, component, callback, delayed
+ @loadGraph name, component, callback, delayed, metadata
else
setTimeout =>
- @loadGraph name, component, callback, delayed
+ @loadGraph name, component, callback, delayed, metadata
, 0
return
if typeof component is 'function'
implementation = component
if component.getComponent and typeof component.getComponent is 'function'
- instance = component.getComponent()
+ instance = component.getComponent metadata
else
- instance = component()
+ instance = component metadata
# Direct component instance, return as is
else if typeof component is 'object' and typeof component.getComponent is 'function'
- instance = component.getComponent()
+ instance = component.getComponent metadata
else
implementation = require component
if implementation.getComponent and typeof implementation.getComponent is 'function'
- instance = implementation.getComponent()
+ instance = implementation.getComponent metadata
else
- instance = implementation()
+ instance = implementation metadata
instance.baseDir = @baseDir if name is 'Graph'
@setIcon name, instance
callback instance
@@ -114,10 +114,10 @@ class ComponentLoader
return false unless typeof cPath is 'string'
cPath.indexOf('.fbp') isnt -1 or cPath.indexOf('.json') isnt -1
- loadGraph: (name, component, callback, delayed) ->
+ loadGraph: (name, component, callback, delayed, metadata) ->
graphImplementation = require @components['Graph']
graphSocket = internalSocket.createSocket()
- graph = graphImplementation.getComponent()
+ graph = graphImplementation.getComponent metadata
graph.loader = @
graph.baseDir = @baseDir
View
6 src/lib/Network.coffee
@@ -100,8 +100,8 @@ class Network extends EventEmitter
#
# * As direct, instantiated JavaScript objects
# * As filenames
- load: (component, callback) ->
- @loader.load component, callback
+ load: (component, metadata, callback) ->
+ @loader.load component, callback, false, metadata
# ## Add a process to the network
#
@@ -128,7 +128,7 @@ class Network extends EventEmitter
return
# Load the component for the process.
- @load node.component, (instance) =>
+ @load node.component, node.metadata, (instance) =>
instance.nodeId = node.id
process.component = instance
Please sign in to comment.
Something went wrong with that request. Please try again.