[#5614] removed hook.HandlerFunc[T] type
This commit is contained in:
+4
-7
@@ -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)
|
||||
}
|
||||
|
||||
@@ -124,12 +124,12 @@ func TestHookTriggerErrorPropagation(t *testing.T) {
|
||||
|
||||
scenarios := []struct {
|
||||
name string
|
||||
handlers []HandlerFunc[*Event]
|
||||
handlers []func(*Event) error
|
||||
expectedError error
|
||||
}{
|
||||
{
|
||||
"without error",
|
||||
[]HandlerFunc[*Event]{
|
||||
[]func(*Event) error{
|
||||
func(e *Event) error { return e.Next() },
|
||||
func(e *Event) error { return e.Next() },
|
||||
},
|
||||
@@ -137,7 +137,7 @@ func TestHookTriggerErrorPropagation(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"with error",
|
||||
[]HandlerFunc[*Event]{
|
||||
[]func(*Event) error{
|
||||
func(e *Event) error { return e.Next() },
|
||||
func(e *Event) error { e.Next(); return err },
|
||||
func(e *Event) error { return e.Next() },
|
||||
|
||||
@@ -73,7 +73,7 @@ func (h *TaggedHook[T]) Bind(handler *Handler[T]) string {
|
||||
//
|
||||
// It is similar to [Hook.Bind] with the difference that the handler
|
||||
// function is invoked only if the event data tags satisfy h.CanTriggerOn.
|
||||
func (h *TaggedHook[T]) BindFunc(fn HandlerFunc[T]) string {
|
||||
func (h *TaggedHook[T]) BindFunc(fn func(T) error) string {
|
||||
return h.mainHook.BindFunc(func(e T) error {
|
||||
if h.CanTriggerOn(e.Tags()) {
|
||||
return fn(e)
|
||||
|
||||
Reference in New Issue
Block a user