hook
Types from PocketBase's Go package hook, as JavaScript sees them: you get these objects from $app and the other globals and from hook events, and call their methods by their JS names (Go's FindRecordById is findRecordById). The same package in Go: hook.
hook.Event
Event implements Resolver and it is intended to be used as a base
Hook event that you can embed in your custom typed event structs.
Example:
type CustomEvent struct {
hook.Event
SomeField int
}
| Member | Type | |
|---|---|---|
extra |
{ [key: string]: any } |
Extra holds any dynamic data that could be passed between event handlers. |
next() |
(): void |
Next calls the next hook handler. |
hook.Handler
Handler defines a single Hook handler. Multiple handlers can share the same id. If Id is not explicitly set it will be autogenerated by Hook.Add and Hook.AddHandler.
| Member | Type | |
|---|---|---|
func |
(_arg0: T) => void |
Func defines the handler function to execute. |
id |
string |
Id is the unique identifier of the handler. |
priority |
number |
Priority allows changing the default exec priority of the handler within a hook. |
hook.Hook
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 })
| Member | Type | |
|---|---|---|
bind() |
(handler: Handler<T>): string |
Bind registers the provided handler to the current hooks queue. |
bindFunc() |
(fn: (e: T) => void): string |
BindFunc is similar to Bind but registers a new handler from just the provided function. |
unbind() |
(...idsToRemove: string[]): void |
Unbind removes one or many hook handler by their id. |
unbindAll() |
(): void |
UnbindAll removes all registered handlers. |
length() |
(): number |
Length returns to total number of registered hook handlers. |
trigger() |
(event: T, ...oneOffHandlerFuncs: ((_arg0: T) => void)[]): void |
Trigger executes all registered hook handlers one by one with the specified event as an argument. |
hook.TaggedHook
Has everything _t077<T> has.
| Member | Type | |
|---|---|---|
canTriggerOn() |
(tagsToCheck: Array<string>): boolean |
CanTriggerOn checks if the current TaggedHook can be triggered with the provided event data tags. |
bind() |
(handler: Handler<T>): string |
Bind registers the provided handler to the current hooks queue. |
bindFunc() |
(fn: (e: T) => void): string |
BindFunc registers a new handler with the specified function. |
hook.mainHook
Has everything _t078<T> has.
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.