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, Debug, 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(CustomDebug, Data)]
26pub struct DynamicNode {
27 /// The closure that generates the dynamic virtual node tree.
28 #[debug(skip)]
29 #[get(pub)]
30 #[set(pub)]
31 pub(crate) render_fn: Rc<RefCell<dyn FnMut() -> VirtualNode>>,
32 /// Persistent hook context for this dynamic node, storing signal
33 /// state and other hook values across render cycles.
34 ///
35 /// Implements `Copy`; all copies share the same underlying state.
36 /// When the `arm_changed` flag inside is toggled (by `match` arm switching),
37 /// the hooks array is cleared to prevent signal leakage between arms.
38 #[get(pub, type(copy))]
39 #[set(pub)]
40 pub(crate) hook_context: HookContext,
41}