Skip to main content

Module component

Module component 

Source
Expand description

Component: Flutter’s StatefulWidget analog.

A Component is a piece of UI with retained local state that lives in the widget tree, a per-component reactive Owner (context scoping + on_cleanup), and a state boundary the surrounding view tree never sees. It is the seam that lets a subtree own state independent of the ambient application state: a ComponentView implements View<Outer> for any outer state, and the subtree it hosts is diffed against the component’s own State instead.

§The state boundary

ComponentWidget builds an inner EventCtx over its own C::State and dispatches events to its child through the same capture/focus/IME routing contract single-child containers use (mirroring frust-widgets’ route_event_single), then mirrors the inner results (redraw / capture / focus request-release / IME publish) back onto the outer context. The subtree therefore mutates the component’s local state while the outer tree only observes the effects (a redraw, a capture, a focus change) — exactly as a container observes them from a leaf.

§Reactive ownership

Each component owns a child Owner created under the ambient owner (the root Owner a shell wraps its rebuild in; a nested component inherits its parent component’s owner because build/rebuild run under owner.with). The owner scopes provide_context/use_context and on_cleanup, and is disposed explicitly at teardown (and defensively on Drop).

§What Component does NOT do (yet)

Per-component tracked/reactive scopes and rebuild skipping are not implemented: a component always re-runs build on rebuild because its local state may have changed even when the component value compares equal. Root-level components are never torn down (the root widget lives for the app’s life), so a root component’s on_cleanup/owner disposal never runs — a known, accepted limitation.

Structs§

ComponentView
The View adapter that hosts a Component in any surrounding view tree.
ComponentWidget
The retained widget behind a ComponentView.

Traits§

Component
A piece of UI with retained local state (Flutter’s StatefulWidget analog).

Functions§

component
Host a Component as a View — the view-fn spelling of ComponentView, mirroring the text(..)/button(..) vocabulary.