Merge pull request #176 from hybridgroup/remove-class-cruft-and-namespace

Remove class cruft and namespace from Basestar
This commit is contained in:
Ron Evans 2014-05-04 02:34:14 -07:00
commit 2958f148f3
4 changed files with 118 additions and 137 deletions

View File

@ -8,7 +8,8 @@
"use strict"; "use strict";
require('./basestar'); var Basestar = require('./basestar');
var namespace = require('node-namespace'); var namespace = require('node-namespace');
// The Adaptor class is a base class for Adaptor classes in external Cylon // The Adaptor class is a base class for Adaptor classes in external Cylon
@ -63,5 +64,5 @@ namespace("Cylon", function() {
return Adaptor; return Adaptor;
})(Cylon.Basestar); })(Basestar);
}); });

View File

@ -9,7 +9,7 @@
"use strict"; "use strict";
require('./utils'); require('./utils');
var namespace = require('node-namespace');
var EventEmitter = require('events').EventEmitter; var EventEmitter = require('events').EventEmitter;
// Basestar is a base class to be used when writing external Cylon adaptors and // Basestar is a base class to be used when writing external Cylon adaptors and
@ -17,14 +17,14 @@ var EventEmitter = require('events').EventEmitter;
// //
// It also extends EventEmitter, so child classes are capable of emitting events // It also extends EventEmitter, so child classes are capable of emitting events
// for other parts of the system to handle. // for other parts of the system to handle.
namespace("Cylon", function() { var Basestar;
this.Basestar = (function(klass) {
subclass(Basestar, klass);
function Basestar(opts) { module.exports = Basestar = function Basestar(opts) {
this.self = this; this.self = this;
} }
subclass(Basestar, EventEmitter);
// Public: Proxies calls from all methods in the object to a target object // Public: Proxies calls from all methods in the object to a target object
// //
// methods - array of methods to proxy // methods - array of methods to proxy
@ -100,8 +100,3 @@ namespace("Cylon", function() {
return this.defineEvent(opts); return this.defineEvent(opts);
}; };
return Basestar;
})(EventEmitter);
});

View File

@ -8,7 +8,8 @@
'use strict'; 'use strict';
require('./basestar'); var Basestar = require('./basestar');
var namespace = require('node-namespace'); var namespace = require('node-namespace');
// The Driver class is a base class for Driver classes in external Cylon // The Driver class is a base class for Driver classes in external Cylon
@ -65,5 +66,5 @@ namespace("Cylon", function() {
return Driver; return Driver;
})(Cylon.Basestar); })(Basestar);
}); });

View File

@ -1,13 +1,13 @@
"use strict"; "use strict";
source('basestar'); var Basestar = source('basestar');
var EventEmitter = require('events').EventEmitter; var EventEmitter = require('events').EventEmitter;
describe('Basestar', function() { describe('Basestar', function() {
describe('constructor', function() { describe('constructor', function() {
it('assigns @self to the instance of the Basestar class', function() { it('assigns @self to the instance of the Basestar class', function() {
var instance = new Cylon.Basestar(); var instance = new Basestar();
expect(instance.self).to.be.eql(instance); expect(instance.self).to.be.eql(instance);
}); });
}); });
@ -15,8 +15,7 @@ describe('Basestar', function() {
describe('#proxyMethods', function() { describe('#proxyMethods', function() {
var methods = ['asString', 'toString', 'returnString']; var methods = ['asString', 'toString', 'returnString'];
var ProxyClass = (function() { var ProxyClass = function ProxyClass() {}
function ProxyClass() {}
ProxyClass.prototype.asString = function() { ProxyClass.prototype.asString = function() {
return "[object ProxyClass]"; return "[object ProxyClass]";
@ -30,21 +29,12 @@ describe('Basestar', function() {
return string; return string;
}; };
return ProxyClass; var TestClass = function TestClass() {
})();
var TestClass = (function(_super) {
subclass(TestClass, _super);
function TestClass() {
this.testInstance = new ProxyClass; this.testInstance = new ProxyClass;
this.proxyMethods(methods, this.testInstance, this, true); this.proxyMethods(methods, this.testInstance, this, true);
} }
return TestClass; subclass(TestClass, Basestar);
})(Cylon.Basestar);
it('can alias methods', function() { it('can alias methods', function() {
var testclass = new TestClass; var testclass = new TestClass;
@ -66,16 +56,10 @@ describe('Basestar', function() {
}); });
describe("#defineEvent", function() { describe("#defineEvent", function() {
var ProxyClass = (function(klass) {
subclass(ProxyClass, klass);
function ProxyClass() {}
return ProxyClass;
})(Cylon.Basestar);
var EmitterClass = (function(klass) { var ProxyClass = function ProxyClass() {};
subclass(EmitterClass, klass);
function EmitterClass(update) { var EmitterClass = function EmitterClass(update) {
update || (update = false); update || (update = false);
this.proxy = new ProxyClass(); this.proxy = new ProxyClass();
this.defineEvent({ this.defineEvent({
@ -86,8 +70,8 @@ describe('Basestar', function() {
}); });
} }
return EmitterClass; subclass(ProxyClass, Basestar);
})(Cylon.Basestar); subclass(EmitterClass, Basestar);
it("proxies events from one class to another", function() { it("proxies events from one class to another", function() {
var eventSpy = spy(), var eventSpy = spy(),
@ -127,7 +111,7 @@ describe('Basestar', function() {
var basestar; var basestar;
before(function() { before(function() {
basestar = new Cylon.Basestar(); basestar = new Basestar();
basestar.connector = new EventEmitter(); basestar.connector = new EventEmitter();
basestar.connection = new EventEmitter(); basestar.connection = new EventEmitter();
}); });
@ -159,7 +143,7 @@ describe('Basestar', function() {
var basestar; var basestar;
before(function() { before(function() {
basestar = new Cylon.Basestar(); basestar = new Basestar();
basestar.connection = new EventEmitter(); basestar.connection = new EventEmitter();
basestar.device = new EventEmitter(); basestar.device = new EventEmitter();
}); });