Skip to content

Commit

Permalink
Namespace all Andro stuff to owner.andro property.
Browse files Browse the repository at this point in the history
  • Loading branch information
maryrosecook committed Feb 5, 2012
1 parent 00c25c3 commit 4a03ce6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 26 deletions.
27 changes: 9 additions & 18 deletions andro.js
Expand Up @@ -21,24 +21,15 @@
};
};

var generateBehaviourName = function(owner) {
var name = Math.floor(Math.random() * 1000000000000000).toString();
if(owner.behaviours[name] === undefined) {
return name;
}
else {
return generateBehaviourName(owner);
}
};

Andro.prototype = {
setup: function(owner) {
if(this.isSetup(owner)) {
throw "Object already set up, or has conflicting property called behaviours.";
throw "Object already set up, or has conflicting property called andro.";
}
else {
owner.behaviours = [];
owner.behaviours.eventer = new Eventer();
owner.andro = {};
owner.andro.behaviours = [];
owner.andro.eventer = new Eventer();
}
},

Expand All @@ -52,7 +43,7 @@
}

var behaviour = {};
owner.behaviours.push(behaviour);
owner.andro.behaviours.push(behaviour);
extend(behaviour, behaviourMixin);

// write exports to owner
Expand All @@ -77,16 +68,16 @@

eventer: function(owner) {
if(this.checkIsSetup(owner)) {
return owner.behaviours.eventer;
return owner.andro.eventer;
}
},

// Returns true if owner has behaviours set up on it.
// Returns true if owner has andro obj on it.
isSetup: function(owner) {
return owner.behaviours !== undefined;
return owner.andro !== undefined;
},

// Returns true if owner has behaviours set up on it, or throws exception if it doesn't.
// Returns true if owner has andro obj on it, or throws exception if it doesn't.
checkIsSetup: function(owner) {
if(this.isSetup(owner)) {
return true;
Expand Down
16 changes: 8 additions & 8 deletions spec/andro.spec.js
Expand Up @@ -18,20 +18,20 @@ describe('setup', function(){

it('should put behaviours on passed object', function(){
andro.setup(obj);
expect(obj.behaviours).toBeDefined();
expect(obj.andro.behaviours).toBeDefined();
});

it('should put eventer on behaviours', function(){
andro.setup(obj);
expect(obj.behaviours.eventer.bind).toBeDefined();
expect(obj.andro.eventer.bind).toBeDefined();
});

it('should throw error if setup called twice on one obj', function(){
andro.setup(obj);

expect(function(){
andro.setup(obj)
}).toThrow("Object already set up, or has conflicting property called behaviours.");
}).toThrow("Object already set up, or has conflicting property called andro.");
});
});

Expand Down Expand Up @@ -69,8 +69,8 @@ describe('augment', function(){
andro.setup(obj);
andro.augment(obj, basicBehaviour);

expect(typeof(obj.behaviours[0].blah)).toEqual('function');
expect(typeof(obj.behaviours[0].woo)).toEqual('number');
expect(typeof(obj.andro.behaviours[0].blah)).toEqual('function');
expect(typeof(obj.andro.behaviours[0].woo)).toEqual('number');
});

it('should call setup function on behaviour if specified', function(){
Expand All @@ -81,7 +81,7 @@ describe('augment', function(){
andro.setup(obj);
andro.augment(obj, basicBehaviour);

expect(obj.behaviours[0].yeah).toEqual(true);
expect(obj.andro.behaviours[0].yeah).toEqual(true);
});

it('should pass settings into setup() when called on behaviour', function(){
Expand All @@ -95,7 +95,7 @@ describe('augment', function(){
woohoo: "yes"
});

expect(obj.behaviours[0].yeah).toEqual(true);
expect(obj.andro.behaviours[0].yeah).toEqual(true);
});

it('should pass empty obj into setup() when called on behaviour if no settings', function(){
Expand All @@ -107,7 +107,7 @@ describe('augment', function(){
andro.setup(obj);
andro.augment(obj, basicBehaviour);

expect(obj.behaviours[0].yeah).toEqual(true);
expect(obj.andro.behaviours[0].yeah).toEqual(true);
});

it('should write exports from setup to main obj', function() {
Expand Down

0 comments on commit 4a03ce6

Please sign in to comment.