euv_core/vdom/node/struct.rs
1use crate::*;
2
3/// Represents a text node in the virtual DOM.
4///
5/// Text nodes may optionally be bound to a reactive signal for automatic updates.
6#[derive(Clone, Data, New)]
7pub struct TextNode {
8 /// The text content.
9 #[get(pub(crate))]
10 #[set(pub(crate))]
11 pub(crate) content: String,
12 /// An optional signal that drives reactive text updates.
13 #[get(pub(crate))]
14 #[set(pub(crate))]
15 pub(crate) signal: Option<Signal<String>>,
16}
17
18/// A closure-based dynamic node that re-renders when its dependency signals change.
19///
20/// Holds a boxed closure that produces a fresh `VirtualNode` on each evaluation.
21/// The renderer subscribes to the closure's signals and patches the DOM automatically.
22/// Contains a `HookContext` that persists hook state (like `use_signal`) across
23/// re-renders, ensuring that signal values are not reset when the render function
24/// is called again.
25#[derive(Data)]
26pub struct DynamicNode {
27 /// The closure that generates the dynamic virtual node tree.
28 #[get(pub)]
29 #[set(pub)]
30 pub(crate) render_fn: Rc<RefCell<dyn FnMut() -> VirtualNode>>,
31 /// Persistent hook context for this dynamic node, storing signal
32 /// state and other hook values across render cycles.
33 ///
34 /// Implements `Copy`; all copies share the same underlying state.
35 /// When the `arm_changed` flag inside is toggled (by `match` arm switching),
36 /// the hooks array is cleared to prevent signal leakage between arms.
37 #[get(pub, type(copy))]
38 #[set(pub)]
39 pub(crate) hook_context: HookContext,
40}