Extract function to DRY up code
This commit is contained in:
parent
a7e8caf19d
commit
5cea07602a
19
lib/robot.js
19
lib/robot.js
|
@ -172,11 +172,7 @@ Robot.prototype.initConnections = function(opts) {
|
||||||
|
|
||||||
Logger.warn(str);
|
Logger.warn(str);
|
||||||
|
|
||||||
_.forEach(opts.connections, function(conn, key) {
|
this.performArraySetup(opts.connections, "connection");
|
||||||
var name = _.isString(key) ? key : conn.name;
|
|
||||||
this.connection(name, conn);
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
return this.connections;
|
return this.connections;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,11 +265,7 @@ Robot.prototype.initDevices = function(opts) {
|
||||||
|
|
||||||
Logger.warn(str);
|
Logger.warn(str);
|
||||||
|
|
||||||
_.forEach(opts.devices, function(device, key) {
|
this.performArraySetup(opts.devices, "device");
|
||||||
var name = _.isString(key) ? key : device.name;
|
|
||||||
this.device(name, device);
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
return this.devices;
|
return this.devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,3 +413,10 @@ Robot.prototype.halt = function(callback) {
|
||||||
Robot.prototype.toString = function() {
|
Robot.prototype.toString = function() {
|
||||||
return "[Robot name='" + this.name + "']";
|
return "[Robot name='" + this.name + "']";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Robot.prototype.performArraySetup = function(things, typeOfThing) {
|
||||||
|
_.forEach(things, function(t, key) {
|
||||||
|
var name = _.isString(key) ? key : t.name;
|
||||||
|
this[typeOfThing](name, t);
|
||||||
|
}, this);
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue