pub struct Component<P, A, F = fn(&mut Context<A>, P) -> View<A>> { /* private fields */ }Expand description
Function-backed component storing cloneable props.
Every build clones props and passes the clone by value to render.
Function items and closure expressions keep their concrete Rust type, which
lets reconciliation distinguish different render implementations without
adding identity methods to ComponentNode.
Existing annotations such as Component<P, A> remain valid and use the
default erased function-pointer type. That explicit erasure preserves the
historical type-based reconciliation contract: changing the callback while
keeping the same erased type does not identify a new mount. Callers that
intentionally replace an erased callback should use a distinct component
type or reconciliation key.
§Examples
use ailloli_ui_runtime::component::{Component, Context, IntoView, View};
fn render(_: &mut Context<()>, label: String) -> View<()> { View::empty().key(label) }
let view = Component::new(String::from("root"), render).into_view();
assert!(matches!(view.kind, ailloli_ui_runtime::component::ViewKind::Component(_)));Implementations§
Source§impl<P, A, F> Component<P, A, F>
impl<P, A, F> Component<P, A, F>
Sourcepub fn new(props: P, render: F) -> Self
pub fn new(props: P, render: F) -> Self
Creates a function-backed component without running render.
§Examples
use ailloli_ui_runtime::component::{Component, Context, IntoView, View};
fn render(_: &mut Context<()>, _: u8) -> View<()> { View::empty() }
let view = Component::new(7, render).into_view();
assert!(view.children.is_empty());