# `MishkaGervaz.Table.Web.Events.HookRunner`
[🔗](https://github.com/mishka-group/mishka_gervaz/blob/v0.0.1-alpha.3/lib/mishka_gervaz/table/web/events/hook_runner.ex#L1)

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
    end

Then configure it in your resource's DSL:

    mishka_gervaz do
      table do
        events do
          hooks MyApp.CustomHookRunner
        end
      end
    end

See `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`.

# `hook_name`

```elixir
@type hook_name() :: atom() | {:on_event, String.t()} | {:on_bulk_action, String.t()}
```

# `hooks`

```elixir
@type hooks() :: map() | nil
```

# `socket`

```elixir
@type socket() :: Phoenix.LiveView.Socket.t()
```

# `apply_hook_result`

```elixir
@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 socket
- `socket` - Continues with the returned socket
- `nil` or other - Uses the default socket

# `run_hook`

```elixir
@callback run_hook(hooks :: hooks(), hook_name :: hook_name(), args :: list()) :: any()
```

Runs a hook with the given arguments.

Returns the hook's return value or nil if the hook doesn't exist.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
