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);
|
||||
|
||||
_.forEach(opts.connections, function(conn, key) {
|
||||
var name = _.isString(key) ? key : conn.name;
|
||||
this.connection(name, conn);
|
||||
}, this);
|
||||
|
||||
this.performArraySetup(opts.connections, "connection");
|
||||
return this.connections;
|
||||
}
|
||||
|
||||
|
@ -269,11 +265,7 @@ Robot.prototype.initDevices = function(opts) {
|
|||
|
||||
Logger.warn(str);
|
||||
|
||||
_.forEach(opts.devices, function(device, key) {
|
||||
var name = _.isString(key) ? key : device.name;
|
||||
this.device(name, device);
|
||||
}, this);
|
||||
|
||||
this.performArraySetup(opts.devices, "device");
|
||||
return this.devices;
|
||||
}
|
||||
|
||||
|
@ -421,3 +413,10 @@ Robot.prototype.halt = function(callback) {
|
|||
Robot.prototype.toString = function() {
|
||||
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