Guards and Hooks

Seth Gilmer's Avatar

Seth Gilmer

20 Jan, 2013 05:04 AM

Guards and Hooks… what are they? For what reason we should use them? Is there any articles/examples to see them in action? I've tried to find it, but didn't understand at all.

  1. Support Staff 1 Posted by Ondina D.F. on 21 Jan, 2013 04:10 PM

    Ondina D.F.'s Avatar

    Hi Seth,

    You’re right, there are no examples (yet) showing how to use guards and hooks.

    For now, you could take a look at the readme files and the tests on github to get a general idea about guards and hooks:



    I haven’t used guards and hooks until now. A really silly example here:

    In context config:

    const expectedViewWidth:Number = 100;
    const expectedViewHeight:Number = 200;
           , 'rectHeight').toValue(expectedViewHeight);, 'rectWidth').toValue(expectedViewWidth);
    public class HookedMediator extends Mediator
        public var view:HookedView;
        public var rectWidth:Number;
        public var rectHeight:Number;
        override public function initialize():void
        public function hook():void
  , 0, rectWidth, rectHeight);
        public function approve():Boolean
            return ( =="Bender");

    In plain text: if View’s name is Bender, draw a rectangle before running Mediator’s initialize().
    The guard checks if a certain condition has been met ( =="Bender")
    I created a guard inside the Mediator, but any class with an approve() method can be used to check against different conditions.;

    IsViewVisible could have an aprove() method like this:

    public function approve():Boolean
    { return (view.visible); }


    P.S. Adding Shaun as a guard to approve my example or to talk about more complex scenarios ;-);

  2. 2 Posted by Seth Gilmer on 22 Jan, 2013 07:41 AM

    Seth Gilmer's Avatar

    Thank you, Ondina.
    It was really helpful. Now I see basic idea.

  3. Support Staff 3 Posted by Ondina D.F. on 22 Jan, 2013 10:00 AM

    Ondina D.F.'s Avatar

    Seth, you’re welcome!!
    I’m closing this discussion for now, but please don’t hesitate to ask more questions in another thread or to re-open this, if need be.


  4. Ondina D.F. closed this discussion on 22 Jan, 2013 10:00 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac