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§
- Event
Dispatcher - Routes events through capture/bubble phases over a
WidgetTree. - Handler
Ctx - Context handed to a handler during dispatch.
Enums§
- Dispatch
Event - The kinds of input events the dispatcher routes.
- Phase
- The dispatch phase in which a handler is being invoked.
Traits§
- Event
Handler - A typed event handler attached to a node.