Re:Pocketbase: Open-source back end in one file
by aziis98 on Sunday January 07, 2024 @07:37PM
(#38906807)
This just looks like the "Event Bus" [1] [2] [3] pattern, this is not the one from the React world if you were thinking about that. Hooks here are just the following, the "Hook" is just a collection of event handlers.
type Handler[T any] func(e T) error
type handlerPair[T any] struct {
id string
handler Handler[T]
}
type Hook[T any] struct {
mux sync.RWMutex
handlers []*handlerPair[T]
}
It's very useful when you want to make an easily extensible library/framework/application, as you can see in pocketbase/core/app.go you can register handlers for various things that can happen.[1]: https://en.wikipedia.org/wiki/Event-driven_programming
[2]: https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_patt...
Where does it come from?
Why is it useful here?
What are the alternatives? Advantages/Drawbacks?
Is there an article somewhere, outside of the Pocketbase docs, presenting that pattern?
- https://github.com/pocketbase/pocketbase/blob/master/core/ap...
- https://github.com/pocketbase/pocketbase/tree/master/tools/h...