From f323fa9c4cf32f190797506f94696cb380e29471 Mon Sep 17 00:00:00 2001 From: Henri Bergius Date: Thu, 8 Nov 2012 18:08:37 +0100 Subject: [PATCH] Deal with asynchronous component loading --- Cakefile | 1 - src/lib/NoFlo.coffee | 3 ++- test/ArrayPort.coffee | 39 +++++++++++++++++++-------------------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/Cakefile b/Cakefile index 7dbccf499..39c117be8 100644 --- a/Cakefile +++ b/Cakefile @@ -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', -> diff --git a/src/lib/NoFlo.coffee b/src/lib/NoFlo.coffee index 52413143a..df8340625 100644 --- a/src/lib/NoFlo.coffee +++ b/src/lib/NoFlo.coffee @@ -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 diff --git a/test/ArrayPort.coffee b/test/ArrayPort.coffee index 28e1641e1..c9fef899d 100644 --- a/test/ArrayPort.coffee +++ b/test/ArrayPort.coffee @@ -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()