-
Notifications
You must be signed in to change notification settings - Fork 5
04. Hooks
Pete Shand edited this page Aug 3, 2018
·
1 revision
Hooks run before or after certain extension actions. They are typically used by extensions to run custom actions based on environmental conditions.
A hook can exist in one of three forms:
- Function
- Object
- Class
A function hook is simply invoked when the time is right:
function randomHook():Void {
trace("hooked!");
}
An object hook must expose a "hook" method:
class SomeHook
{
public function hook():Void
{
trace("hooked!");
}
}
The "hook" method will be called each time the hook runs. The object will not be injected into.
A class reference can be used as a hook:
class SomeOtherHook
{
@inject public var someModel:SomeModel;
public function hook():Void
{
someModel.enabled = false;
}
}
A new object will be constructed each time the hook is run. The object will be injected into.