Handles hook execution for Events module.
This module provides functions for running hooks and applying hook results. Hooks allow customization of event handling at specific points.
Customization
You can create a custom HookRunner:
defmodule MyApp.CustomHookRunner do
use MishkaGervaz.Table.Web.Events.HookRunner
# Custom hook runner with error logging
def run_hook(hooks, hook_name, args) do
result = super(hooks, hook_name, args)
case result do
{:error, reason} -> Logger.error("Hook failed", hook: hook_name, reason: reason)
_ -> :ok
end
result
end
endThen configure it in your resource's DSL:
mishka_gervaz do
table do
events do
hooks MyApp.CustomHookRunner
end
end
endSee MishkaGervaz.Table.Web.Events,
MishkaGervaz.Table.Dsl.Hooks (where hooks are declared),
MishkaGervaz.Table.Entities.ActionHook (the per-action hook entity),
MishkaGervaz.Table.Web.DataLoader.HookRunner (data-loading counterpart),
and the sibling handlers SanitizationHandler, RecordHandler,
SelectionHandler, BulkActionHandler, RelationFilterHandler.
Summary
Types
Callbacks
@callback apply_hook_result( hooks :: hooks(), hook_name :: hook_name(), args :: list(), default_socket :: socket() ) :: socket() | {:halt, socket()}
Applies a hook result to the socket.
Handles various hook return formats:
{:halt, socket}- Stops processing and returns{:halt, socket}{:cont, socket}- Continues with the returned socketsocket- Continues with the returned socketnilor other - Uses the default socket
Runs a hook with the given arguments.
Returns the hook's return value or nil if the hook doesn't exist.