Skip to content

Commit

Permalink
addedAsDelegate implemented in base.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewrobbins committed Jun 12, 2013
1 parent 5f1dd28 commit 8d1372d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions base/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ sudo.Base = function() {
sudo.Base.prototype.addDelegate = function addDelegate(del) {
del.delegator = this;
this.delegates.push(del);
if('addedAsDelegate' in del) del.addedAsDelegate(this);
return this;
};
// ###base
Expand Down
10 changes: 10 additions & 0 deletions base/spec/base.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ describe('Sudo Base Object', function() {
d.burgle = function() {
return this.role;
};
d.addedAsDelegate = function() {
this.added = true;
};
});

it('is an instance of the Base class', function() {
Expand All @@ -25,6 +28,13 @@ describe('Sudo Base Object', function() {
expect(b.delegates.length).toBe(1);
});

it('calls addedAsDelegate if present', function() {
var spy = spyOn(d, 'addedAsDelegate').andCallThrough();
b.addDelegate(d);
expect(spy).toHaveBeenCalled();
expect(d.added).toBe(true);
});

it('can fetch a delegate by role', function() {
b.addDelegate(d);
expect(b.delegate('encyclopediaSalesman')).toBe(d);
Expand Down
3 changes: 2 additions & 1 deletion build/debug/sudo-x.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ sudo.Base = function() {
sudo.Base.prototype.addDelegate = function addDelegate(del) {
del.delegator = this;
this.delegates.push(del);
if('addedAsDelegate' in del) del.addedAsDelegate(this);
return this;
};
// ###base
Expand Down Expand Up @@ -1815,7 +1816,7 @@ sudo.delegates.Data.prototype.removeFilter = function removeFilter(key) {
// `private`
sudo.delegates.Data.prototype.role = 'data';

sudo.version = "0.9.4";
sudo.version = "0.9.5";
window.sudo = sudo;
if(typeof window._ === "undefined") window._ = sudo;
}).call(this, this);
3 changes: 2 additions & 1 deletion build/debug/sudo.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ sudo.Base = function() {
sudo.Base.prototype.addDelegate = function addDelegate(del) {
del.delegator = this;
this.delegates.push(del);
if('addedAsDelegate' in del) del.addedAsDelegate(this);
return this;
};
// ###base
Expand Down Expand Up @@ -827,7 +828,7 @@ sudo.extensions.observable = {
return this.deliverChangeRecords();
}
};
sudo.version = "0.9.4";
sudo.version = "0.9.5";
window.sudo = sudo;
if(typeof window._ === "undefined") window._ = sudo;
}).call(this, this);

0 comments on commit 8d1372d

Please sign in to comment.