[#5614] removed hook.HandlerFunc[T] type

This commit is contained in:
Gani Georgiev
2024-10-07 09:52:31 +03:00
parent 1d4dd5d5b4
commit 393b461ea2
13 changed files with 4236 additions and 4235 deletions

View File

@@ -7,9 +7,6 @@ import (
"github.com/pocketbase/pocketbase/tools/security"
)
// HandlerFunc defines a hook handler function.
type HandlerFunc[T Resolver] func(e T) error
// 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.
@@ -18,7 +15,7 @@ type Handler[T Resolver] struct {
//
// Note that users need to call e.Next() in order to proceed with
// the execution of the hook chain.
Func HandlerFunc[T]
Func func(T) error
// Id is the unique identifier of the handler.
//
@@ -111,7 +108,7 @@ func (h *Hook[T]) Bind(handler *Handler[T]) string {
// 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.
func (h *Hook[T]) BindFunc(fn HandlerFunc[T]) string {
func (h *Hook[T]) BindFunc(fn func(T) error) string {
return h.Bind(&Handler[T]{Func: fn})
}
@@ -151,9 +148,9 @@ func (h *Hook[T]) Length() int {
// handlers that will be temporary appended to the handlers queue.
//
// NB! Each hook handler must call event.Next() in order the hook chain to proceed.
func (h *Hook[T]) Trigger(event T, oneOffHandlers ...HandlerFunc[T]) error {
func (h *Hook[T]) Trigger(event T, oneOffHandlers ...func(T) error) error {
h.mu.RLock()
handlers := make([]HandlerFunc[T], 0, len(h.handlers)+len(oneOffHandlers))
handlers := make([]func(T) error, 0, len(h.handlers)+len(oneOffHandlers))
for _, handler := range h.handlers {
handlers = append(handlers, handler.Func)
}