Trait ComponentNode

Source
pub trait ComponentNode<A>: 'static {
    // Required method
    fn build(&self, context: &mut Context<A>) -> View<A>;
}
Expand description

Stateful declarative component contract.

Each build runs synchronously with a fresh hook cursor and returns exactly one root view. Reactive reads are observed automatically. After a successful build, the sources reached by that build atomically replace the component’s previous observations; this includes switching conditional branches or observing no source. A panic preserves the previous observations, although reconciliation and application-side mutations are not rolled back. All observations are removed when the component unmounts. A fresh payload of the same concrete component type preserves the mount; changing that type starts a new mount generation. Panics propagate.

§Examples

use ailloli_ui_runtime::component::{ComponentNode, Context, View};
struct Empty;
impl ComponentNode<()> for Empty {
    fn build(&self, _: &mut Context<()>) -> View<()> { View::empty() }
}

Required Methods§

Source

fn build(&self, context: &mut Context<A>) -> View<A>

Builds the component’s current declarative root view.

The callback runs synchronously on the UI thread. Reading a Signal, State, reactive Binding, or derived Memo records the source for this mounted component.

§Examples
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::app::RuntimeHandle;
use ailloli_ui_runtime::component::{ComponentNode, Context, View};
struct Empty;
impl ComponentNode<()> for Empty { fn build(&self, _: &mut Context<()>) -> View<()> { View::empty() } }
let mut ctx = Context::new(ElementId(1), RuntimeHandle::new());
assert!(Empty.build(&mut ctx).children.is_empty());

Implementors§

Source§

impl<P, A, F> ComponentNode<A> for Component<P, A, F>
where P: Clone + 'static, A: 'static, F: Fn(&mut Context<A>, P) -> View<A> + 'static,