Opened 8 years ago

Closed 7 years ago

#14129 closed defect (invalid)

aspect.before bypasses aspect.around

Reported by: Marcel Lucas Owned by: Kris Zyp
Priority: high Milestone: tbd
Component: Events Version: 1.7.0b1
Keywords: AOP aspect before around Cc:
Blocked By: Blocking:

Description

From http://lazutkin.com/blog/2008/may/18/aop-aspect-javascript-dojo/

The “around” advice will “eat” all previously attached “before” and “after” advices changing the order of their execution. We cannot guarantee anymore that “before” advices run before all “around” advices, and so on.

The current implementation kind of handles “around”/ parallel to “before”|“after” no matter in which order they are chained (means “before” chain is executed, “around” chain is executed right afterwards, followed by “after” chain)

require(["dojo/aspect"],function(aspect){
    var context = {func:function(){console.log("YOU DONT WANNA SEE THIS")}};

    aspect.after (context, "func", function(){console.log("DONE")});
    aspect.before(context, "func", function(){console.log("LET ME SHOW YOU SOMETHING...")});
    aspect.before(context, "func", function(){console.log("HEY BUD!")});
    aspect.around(context, "func", function(){return function(){console.log("... I HAVE NOTHING TO SHOW")}});

    context .func();
});

//outputs:
//HEY BUD!
//LET ME SHOW YOU SOMETHING...
//... I HAVE NOTHING TO SHOW
//DONE


//expected:
//... I HAVE NOTHING TO SHOW

I'm working "around" this problem by using aspect.around only (respectively the context-patched version #13992)

Change History (4)

comment:1 Changed 8 years ago by Kris Zyp

The blog post talks about around advice eating other advice as a problem. Why would we want to introduce this problem?

comment:2 Changed 8 years ago by Adam Peller

Milestone: 1.7.1tbd

comment:3 Changed 8 years ago by Marcel Lucas

Thanks for that quick response.

For me it was the intended behavior that arounds eat all other advices. The ticket can be closed as the current implementatin is definitely intended to be a problem solving feature - which I interpreted as an error.

I just wish to see a clear note to this behavior in the upcoming documentation.

Regards

comment:4 Changed 7 years ago by Kris Zyp

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.