Skip to content

Commit

Permalink
More simplifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhop committed Feb 11, 2012
1 parent 59ee1c2 commit 95d618d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
13 changes: 9 additions & 4 deletions advise.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
return f;
}

return function advise(instance, name, advice){
function advise(instance, name, advice){
var f = instance[name], a;
if(f && f.adviceNode && f.adviceNode instanceof Node){
a = f.adviceNode;
Expand All @@ -89,9 +89,14 @@
}
instance[name] = makeAOPStub(a);
}
if(advice instanceof Function){ advice = advice(instance, name); }
return a.a(advice.before, advice.after, 0, advice.around);
};
if(advice instanceof Function){ advice = advice(name, instance); }
return a.a(advice.before || advice.b, advice.after || advice.a, 0, advice.around || advice.f);
}

//advise.before = function(instance, name, f){ return advise(instance, name, {before: f}); };
//advise.after = function(instance, name, f){ return advise(instance, name, {after: f}); };

return advise;
});
})(typeof define != "undefined" ? define : function(_, f){
if(typeof module != "undefined"){
Expand Down
2 changes: 1 addition & 1 deletion dcl-mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
// put in place all decorations and return a constructor
ctor._meta = o;
ctor[pname] = proto;
proto.constructor = ctor;
//proto.constructor = ctor; // uncomment if constructor is not named "constructor"
bases[0] = ctor;

return ctor;
Expand Down
8 changes: 5 additions & 3 deletions dcl.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
this.f = this.f.around;
}
});
dcl.advise = function(f){
if(f instanceof Function){ f = advice(name); }
return new Advice(f);
}

function stub(id, bases, name){
var i = bases.length - 1, b = [], a = [], f;
Expand Down Expand Up @@ -88,8 +92,6 @@

dcl._setStubs(mixChains, buildStubs);

dcl.advise = function(f){ return new Advice(f); }

function chain(id){
return function(ctor, name){
var m = ctor._meta;
Expand All @@ -106,7 +108,7 @@
dcl.chainAfter = chain(2);

dcl.isInstanceOf = function(o, ctor){
return o instanceof ctor || (o.constructor._meta && o.constructor._meta.bases.indexOf(ctor) >= 0);
return o instanceof ctor || o.constructor._meta && o.constructor._meta.bases.indexOf(ctor) > 0;
};

return dcl;
Expand Down

0 comments on commit 95d618d

Please sign in to comment.