Skip to content

Commit

Permalink
Deal with asynchronous component loading
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed Nov 8, 2012
1 parent 472df50 commit f323fa9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
1 change: 0 additions & 1 deletion Cakefile
Expand Up @@ -32,7 +32,6 @@ buildDir = (path) ->

task 'build', 'transpile CoffeeScript sources to JavaScript', ->
buildDir "lib"
buildDir "components"
buildDir "bin"

task 'test', 'run the unit tests', ->
Expand Down
3 changes: 2 additions & 1 deletion src/lib/NoFlo.coffee
Expand Up @@ -263,13 +263,14 @@ class NoFlo
socket.send initializer.from.data
socket.disconnect()

exports.createNetwork = (graph, debug = false) ->
exports.createNetwork = (graph, debug = false, callback) ->
network = new NoFlo graph
network.debug = debug

connect = ->
network.addEdge edge for edge in graph.edges
network.addInitial initializer for initializer in graph.initializers
callback network if callback

todo = graph.nodes.length
for node in graph.nodes
Expand Down
39 changes: 19 additions & 20 deletions test/ArrayPort.coffee
Expand Up @@ -5,34 +5,33 @@ getBaseGraph = ->
graph.addNode "Display", "Output"
graph.addInitial "Foo", "Display", "in"
graph.addInitial "Bar", "Display", "in"
noflo.createNetwork graph
graph

exports["test ArrayPort type"] = (test) ->
network = getBaseGraph()

port = network.processes["Display"].component.inPorts["in"]
test.equal port instanceof noflo.ArrayPort, true

test.done()
graph = getBaseGraph()
network = noflo.createNetwork graph, false, ->
port = network.processes["Display"].component.inPorts["in"]
test.equal port instanceof noflo.ArrayPort, true
test.done()

exports["test connecting to ArrayPorts"] = (test) ->
graph = getBaseGraph()
network = noflo.createNetwork graph, false, ->
test.equal network.connections.length, 2

network = getBaseGraph()
test.equal network.connections.length, 2

port = network.processes["Display"].component.inPorts["in"]
test.equal port.sockets.length, 2
port = network.processes["Display"].component.inPorts["in"]
test.equal port.sockets.length, 2

test.done()
test.done()

exports["test removing ArrayPorts"] = (test) ->

network = getBaseGraph()
graph = getBaseGraph()
network = noflo.createNetwork graph, false, ->

port = network.processes["Display"].component.inPorts["in"]
port = network.processes["Display"].component.inPorts["in"]

first = port.sockets[0]
port.detach first
test.equal port.sockets.length, 1
first = port.sockets[0]
port.detach first
test.equal port.sockets.length, 1

test.done()
test.done()

0 comments on commit f323fa9

Please sign in to comment.