-
Notifications
You must be signed in to change notification settings - Fork 5
03. Guards
Pete Shand edited this page Aug 3, 2018
·
1 revision
Guards say "yes" or "no". They are typically used by extensions to guard against certain actions based on environmental conditions.
A guard can exist in one of three forms:
- Function
- Object
- Class
A function guard is expected to return a Boolean value:
function randomGuard():Bool {
return Math.random() < 0.5;
}
An object guard is expected to expose an "approve" method that returns a Boolean value:
class HappyGuard
{
public function approve():Bool
{
return true;
}
}
Instantiating a Class guard should result in an object that exposes an "approve" method which returns a Boolean value:
class SomeGuard
{
@inject public var someModel:SomeModel;
public function approve():Bool
{
return someModel.enabled;
}
}