Guards and Hooks
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.
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | 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
Support Staff 1 Posted by Ondina D.F. on 21 Jan, 2013 04:10 PM
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:
https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...
https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...
Guards
https://github.com/robotlegs/robotlegs-framework/blob/master/test/r...
https://github.com/robotlegs/robotlegs-framework/blob/master/test/r...
Hooks
https://github.com/robotlegs/robotlegs-framework/blob/master/test/r...
https://github.com/robotlegs/robotlegs-framework/blob/master/test/r...
I haven’t used guards and hooks until now. A really silly example here:
In context config:
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 (view.name =="Bender")
I created a guard inside the Mediator, but any class with an approve() method can be used to check against different conditions.
_viewProcessorMap.map(HookedView).toNoProcess().withHooks(HookedMediator).withGuards(IsViewVisible);
IsViewVisible could have an aprove() method like this:
public function approve():Boolean
{ return (view.visible); }
HTH
Ondina
P.S. Adding Shaun as a guard to approve my example or to talk about more complex scenarios ;-)
discussionProcessorMap.map(MySillyExample).toNoProcess().withGuards(ShaunSmith);
2 Posted by Seth Gilmer on 22 Jan, 2013 07:41 AM
Thank you, Ondina.
It was really helpful. Now I see basic idea.
Support Staff 3 Posted by Ondina D.F. on 22 Jan, 2013 10:00 AM
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.
Ondina
Ondina D.F. closed this discussion on 22 Jan, 2013 10:00 AM.