# `ExGram.Router.Dispatcher`
[🔗](https://github.com/rockneurotiko/ex_gram_router/blob/v0.1.0/lib/ex_gram/router/dispatcher.ex#L1)

Runtime component responsible for walking the routing tree and dispatching
updates to the appropriate handler.

This module is called by the generated `handle/2` function and should not
be called directly in user code.

## Dispatch algorithm

1. Iterate over top-level scopes in declaration order.
2. For each scope, evaluate all filters (AND logic, short-circuit on first false).
3. After each passing filter, call `scope_extra/2` if implemented — the returned
   map is merged into `context.extra` before proceeding to remaining filters and
   child scopes. Sibling scopes receive the original, un-enriched context.
4. If all filters pass and the scope is a leaf (has a handler), call the handler
   with the enriched context.
5. If all filters pass and the scope is a branch (has children), recurse into
   children with the enriched context.
6. If no scope matches, return the context unchanged (no-op).

# `dispatch`

```elixir
@spec dispatch(term(), ExGram.Cnt.t(), [ExGram.Router.Scope.t()]) :: ExGram.Cnt.t()
```

Dispatches an update to the first matching handler in the routing tree.

Returns the context (potentially modified by the handler), or the original
context unchanged if no handler matches.

---

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