ExGram.Router.Dispatcher (ex_gram_router v0.1.0)

Copy Markdown View Source

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).

Summary

Functions

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

Functions

dispatch(update_info, context, scopes)

@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.