Misc. small refactors
This commit is contained in:
parent
f1ba43d919
commit
ee366739d3
|
@ -12,11 +12,6 @@ var Basestar = require('./basestar'),
|
|||
Logger = require('./logger'),
|
||||
Utils = require('./utils');
|
||||
|
||||
// The Adaptor class is a base class for Adaptor classes in external Cylon
|
||||
// modules to use. It offers basic functions for connecting/disconnecting that
|
||||
// descendant classes can use.
|
||||
var Adaptor;
|
||||
|
||||
// Public: Creates a new Adaptor
|
||||
//
|
||||
// opts - hash of acceptable params
|
||||
|
@ -24,10 +19,8 @@ var Adaptor;
|
|||
// connection - Connection the adaptor will use to proxy commands/events
|
||||
//
|
||||
// Returns a new Adaptor
|
||||
module.exports = Adaptor = function Adaptor(opts) {
|
||||
if (opts == null) {
|
||||
opts = {};
|
||||
}
|
||||
var Adaptor = module.exports = function Adaptor(opts) {
|
||||
opts = opts || {};
|
||||
|
||||
this.name = opts.name;
|
||||
this.connection = opts.connection;
|
||||
|
@ -46,7 +39,6 @@ Adaptor.prototype.commands = [];
|
|||
Adaptor.prototype.connect = function(callback) {
|
||||
Logger.info("Connecting to adaptor '" + this.name + "'.");
|
||||
callback(null);
|
||||
return true;
|
||||
};
|
||||
|
||||
// Public: Disconnects from the adaptor
|
||||
|
@ -57,7 +49,7 @@ Adaptor.prototype.connect = function(callback) {
|
|||
Adaptor.prototype.disconnect = function(callback) {
|
||||
Logger.info("Disconnecting from adaptor '" + this.name + "'.");
|
||||
this.removeAllListeners();
|
||||
callback();
|
||||
callback(null);
|
||||
};
|
||||
|
||||
// Public: Voids all command functions so they do not interact
|
||||
|
@ -65,7 +57,7 @@ Adaptor.prototype.disconnect = function(callback) {
|
|||
//
|
||||
// Returns nothing
|
||||
Adaptor.prototype._noop = function() {
|
||||
this.commands.forEach((function(command) {
|
||||
this[command] = function() { return null; };
|
||||
}).bind(this));
|
||||
this.commands.forEach(function(command) {
|
||||
this[command] = function() {};
|
||||
}.bind(this));
|
||||
};
|
||||
|
|
|
@ -39,7 +39,6 @@ Driver.prototype.commands = [];
|
|||
Driver.prototype.start = function(callback) {
|
||||
Logger.info("Driver " + this.name + " started.");
|
||||
callback(null);
|
||||
return true;
|
||||
};
|
||||
|
||||
// Public: Halts the driver
|
||||
|
@ -50,5 +49,5 @@ Driver.prototype.start = function(callback) {
|
|||
Driver.prototype.halt = function(callback) {
|
||||
Logger.info("Driver " + this.name + " halted.");
|
||||
this.removeAllListeners();
|
||||
callback();
|
||||
callback(null);
|
||||
};
|
||||
|
|
30
lib/utils.js
30
lib/utils.js
|
@ -119,7 +119,7 @@ var Utils = module.exports = {
|
|||
force = false;
|
||||
}
|
||||
|
||||
var fn = function(method) {
|
||||
var proxy = function(method) {
|
||||
return base[method] = function() {
|
||||
return target[method].apply(target, arguments);
|
||||
};
|
||||
|
@ -132,7 +132,7 @@ var Utils = module.exports = {
|
|||
continue;
|
||||
}
|
||||
|
||||
fn(method);
|
||||
proxy(method);
|
||||
}
|
||||
return base;
|
||||
},
|
||||
|
@ -145,9 +145,7 @@ var Utils = module.exports = {
|
|||
//
|
||||
// Returns base
|
||||
proxyTestStubs: function proxyTestStubs(methods, base) {
|
||||
if (base == null) {
|
||||
base = this;
|
||||
}
|
||||
base = base || this;
|
||||
|
||||
methods.forEach(function(method) {
|
||||
base[method] = function() {
|
||||
|
@ -290,9 +288,11 @@ var addCoreExtensions = function addCoreExtensions() {
|
|||
var val = (this - Math.min(start, end)) / (Math.max(start, end) - Math.min(start, end));
|
||||
|
||||
if (val > 1) {
|
||||
val = 1;
|
||||
} else if (val < 0){
|
||||
val = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (val < 0){
|
||||
return 0;
|
||||
}
|
||||
|
||||
return val;
|
||||
|
@ -312,13 +312,15 @@ var addCoreExtensions = function addCoreExtensions() {
|
|||
Number.prototype.toScale = function(start, end) {
|
||||
var i = this * (Math.max(start, end) - Math.min(start, end)) + Math.min(start, end);
|
||||
|
||||
if (i < Math.min(start, end)) {
|
||||
return Math.min(start, end);
|
||||
} else if (i > Math.max(start,end)){
|
||||
return Math.max(start, end);
|
||||
} else {
|
||||
return i;
|
||||
if (i < start) {
|
||||
return start;
|
||||
}
|
||||
|
||||
if (i > end) {
|
||||
return end;
|
||||
}
|
||||
|
||||
return i;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue