Raxol.Core.Runtime.Events.Bubbler (Raxol v2.6.0)

View Source

Implements capture and bubbling event dispatch through the view tree.

The full event flow follows the W3C model:

  1. Capture phase (root -> target): walks down from root, checking :on_capture handlers. A capture handler can intercept the event before it reaches the target.

  2. Target + Bubble phase (target -> root): the focused element and its ancestors get a chance to handle via inline handlers (:on_click, :on_event, :on_change) and component handle_event/3. :passthrough continues to the next ancestor.

If no handler in either phase consumes the event, it falls through to the app-level update/2.

Summary

Functions

Attempts to bubble an event through the view tree starting at the focused element. Does NOT run the capture phase. Use dispatch/4 for the full cycle.

Dispatches an event through the full capture + bubble cycle.

Finds the path from the root to the target element (inclusive). Returns the path in bottom-up order (target first, root last) for bubbling. Returns nil if the element is not found.

Types

dispatch_result()

@type dispatch_result() :: {:handled, term()} | {:commands, [term()]} | :passthrough

element()

@type element() :: map()

Functions

bubble(event, view_tree, focused_id, context)

@spec bubble(Raxol.Core.Events.Event.t(), element(), term(), map()) ::
  dispatch_result()

Attempts to bubble an event through the view tree starting at the focused element. Does NOT run the capture phase. Use dispatch/4 for the full cycle.

Returns:

  • {:handled, result} if a component consumed the event
  • {:commands, commands} if a component returned commands to process
  • :passthrough if no component handled the event

dispatch(event, view_tree, focused_id, context)

@spec dispatch(Raxol.Core.Events.Event.t(), element(), term(), map()) ::
  dispatch_result()

Dispatches an event through the full capture + bubble cycle.

Returns:

  • {:handled, result} if a handler consumed the event
  • {:commands, commands} if a handler returned commands
  • :passthrough if no handler consumed the event

find_ancestor_path(tree, target_id)

@spec find_ancestor_path(element(), term()) :: [element()] | nil

Finds the path from the root to the target element (inclusive). Returns the path in bottom-up order (target first, root last) for bubbling. Returns nil if the element is not found.