euv_core/vdom/node/struct.rs
1use crate::*;
2
3/// Inner storage for a dynamic node render closure.
4///
5/// Boxes a `dyn FnMut() -> VirtualNode` so it can be stored behind `Rc<RefCell<>>`.
6#[derive(CustomDebug, Data, New)]
7pub(crate) struct RenderFnInner {
8 /// The boxed render closure.
9 #[debug(skip)]
10 #[get(pub(crate))]
11 #[set(pub(crate))]
12 pub(crate) render_fn: Box<dyn FnMut() -> VirtualNode>,
13}
14
15/// Represents a text node in the virtual DOM.
16///
17/// Text nodes may optionally be bound to a reactive signal for automatic updates.
18#[derive(Clone, CustomDebug, Data, New)]
19pub struct TextNode {
20 /// The text content.
21 #[get(pub(crate))]
22 #[set(pub(crate))]
23 pub(crate) content: String,
24 /// An optional signal that drives reactive text updates.
25 #[debug(skip)]
26 #[get(pub(crate))]
27 #[set(pub(crate))]
28 pub(crate) signal: Option<Signal<String>>,
29}
30
31/// A closure-based dynamic node that re-renders when its dependency signals change.
32///
33/// Holds a shared reference to a heap-allocated render closure that produces a fresh
34/// `VirtualNode` on each evaluation. The renderer subscribes to the closure's
35/// signals and patches the DOM automatically.
36/// Contains a `HookContext` that persists hook state (like `use_signal`) across
37/// re-renders, ensuring that signal values are not reset when the render function
38/// is called again.
39#[derive(CustomDebug, Data, New)]
40pub struct DynamicNode {
41 /// Shared reference to the heap-allocated render closure inner state.
42 #[debug(skip)]
43 #[get(pub(crate))]
44 #[set(pub(crate))]
45 pub(crate) render_fn: Rc<RefCell<RenderFnInner>>,
46 /// Persistent hook context for this dynamic node, storing signal
47 /// state and other hook values across render cycles.
48 #[get(pub(crate))]
49 #[set(pub(crate))]
50 pub(crate) hook_context: HookContext,
51}