From 862a3702b706d2dbe0185be4a1999d9ca2c83ae8 Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Fri, 28 Feb 2014 20:30:12 -0800 Subject: [PATCH] Refactor device/connection initialization methods --- lib/robot.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/robot.js b/lib/robot.js index 8216ed1..b44d9db 100644 --- a/lib/robot.js +++ b/lib/robot.js @@ -144,18 +144,18 @@ namespace("Cylon", function() { // // Returns initialized connections Robot.prototype.initConnections = function(connections) { - var connection, _i, _len; Logger.info("Initializing connections..."); - if (connections == null) { - return; - } + if (connections == null) { return; } + connections = [].concat(connections); - for (_i = 0, _len = connections.length; _i < _len; _i++) { - connection = connections[_i]; + + for (var i = 0; i < connections.length; i++) { + var connection = connections[i]; Logger.info("Initializing connection '" + connection.name + "'..."); connection['robot'] = this; this.connections[connection.name] = new Cylon.Connection(connection); } + return this.connections; }; @@ -165,20 +165,19 @@ namespace("Cylon", function() { // // Returns initialized devices Robot.prototype.initDevices = function(devices) { - var device, _i, _len, _results; Logger.info("Initializing devices..."); - if (devices == null) { - return; - } + if (devices == null) { return; } + devices = [].concat(devices); - _results = []; - for (_i = 0, _len = devices.length; _i < _len; _i++) { - device = devices[_i]; + + for (var i = 0; i < devices.length; i++) { + var device = devices[i]; Logger.info("Initializing device '" + device.name + "'..."); device['robot'] = this; - _results.push(this.devices[device.name] = new Cylon.Device(device)); + this.devices[device.name] = new Cylon.Device(device); } - return _results; + + return this.devices; }; // Public: Starts the Robot working.