Skip to main content

Module dispatch

Module dispatch 

Source
Expand description

Event dispatch with W3C-style capture and bubble phases.

EventDispatcher routes a DispatchEvent from the tree root down to a target node (the capture phase) and back up to the root (the bubble phase), invoking the handlers registered for each node along the way. A handler returns a Propagation result; once stop_propagation is set the dispatcher visits no further nodes.

§Handler-safe mutation during dispatch

Handlers commonly want to add or remove handlers as a side effect (e.g. a “close” button that detaches its own listener). Mutating the handler list while iterating it is a classic use-after-free / skipped-element bug. The dispatcher avoids it with a collect-then-apply protocol: the live registry is never borrowed mutably during a dispatch. Instead, handlers push RegistryEdits into a deferred queue carried by HandlerCtx; the queue is drained and applied to the registry only after the whole dispatch finishes. Adds and removes therefore take effect on the next event, never mid-flight.

Structs§

EventDispatcher
Routes events through capture/bubble phases over a WidgetTree.
HandlerCtx
Context handed to a handler during dispatch.

Enums§

DispatchEvent
The kinds of input events the dispatcher routes.
Phase
The dispatch phase in which a handler is being invoked.

Traits§

EventHandler
A typed event handler attached to a node.