static/jsvm/interfaces/hook.Hook.html
Hook defines a generic concurrent safe structure for managing event hooks.
When using custom event it must embed the base [hook.Event].
Example:
type CustomEvent struct { hook.Event SomeField int } h := Hook[*CustomEvent]{} h.BindFunc(func(e *CustomEvent) error { println(e.SomeField) return e.Next() }) h.Trigger(&CustomEvent{ SomeField: 123 })Copy
bindbindFunclengthtriggerunbindunbindAll
Bind registers the provided handler to the current hooks queue.
If handler.Id is empty it is updated with autogenerated value.
If a handler from the current hook list has Id matching handler.Id then the old handler is replaced with the new one.
BindFunc is similar to Bind but registers a new handler from just the provided function.
The registered handler is added with a default 0 priority and the id will be autogenerated.
If you want to register a handler with custom priority or id use the [Hook.Bind] method.
-
- (e): void
-
-
Length returns to total number of registered hook handlers.
Trigger executes all registered hook handlers one by one with the specified event as an argument.
Optionally, this method allows also to register additional one off handler funcs that will be temporary appended to the handlers queue.
NB! Each hook handler must call event.Next() in order the hook chain to proceed.
Rest ...oneOffHandlerFuncs: ((_arg0) => void)[]Unbind removes one or many hook handler by their id.
Rest ...idsToRemove: string[]UnbindAll removes all registered handlers.
OSLightDark
Generated using TypeDoc