ailloli_ui_runtime/component/mod.rs
1//! Declarative UI: views, components, and reactive bindings.
2
3/// Binding implementation details.
4pub mod binding;
5/// Context implementation details.
6pub mod context;
7/// Node implementation details.
8pub mod node;
9/// Props implementation details.
10pub mod props;
11/// Hidden retained reactive dependency contracts shared inside the framework.
12#[doc(hidden)]
13pub mod reactive;
14/// Signal implementation details.
15pub mod signal;
16/// State implementation details.
17pub mod state;
18/// View implementation details.
19pub mod view;
20
21pub use binding::Binding;
22pub use context::Context;
23pub use node::{Node, NodeKind};
24pub use props::Props;
25pub use signal::{Memo, Signal};
26pub use state::State;
27pub use view::{Component, ComponentNode, IntoView, IntoViewKeyExt, View, ViewKind, Widget};
28
29/// Builds a component [`View`] from cloneable props and a render function.
30///
31/// The render function is not invoked until reconciliation builds the component.
32/// Props are cloned on every build. This is shorthand for
33/// `Component::new(props, render).into_view()`.
34///
35/// # Examples
36///
37/// ```
38/// use ailloli_ui_runtime::component::{component, Context, View, ViewKind};
39/// fn render(_: &mut Context<()>, _: u8) -> View<()> { View::empty() }
40/// let view = component::<(), u8>(3, render);
41/// assert!(matches!(view.kind, ViewKind::Component(_)));
42/// ```
43pub fn component<A: 'static, P: Props>(
44 props: P,
45 render: impl Fn(&mut Context<A>, P) -> View<A> + 'static,
46) -> View<A> {
47 Component::new(props, render).into_view()
48}