Skip to main content

VirtualNode

Enum VirtualNode 

Source
pub enum VirtualNode {
    Element {
        tag: Tag,
        attributes: Vec<AttributeEntry>,
        children: Vec<VirtualNode>,
        key: Option<String>,
    },
    Text(TextNode),
    Fragment(Vec<VirtualNode>),
    Dynamic(DynamicNode),
    Empty,
}
Expand description

Represents a node in the virtual DOM tree.

The core enum representing elements, text, fragments, and empty nodes.

Variants§

§

Element

An element node with a tag, attributes, and children.

Fields

§tag: Tag

The tag type of this element.

§attributes: Vec<AttributeEntry>

The attributes attached to this element.

§children: Vec<VirtualNode>

The child nodes.

§key: Option<String>

An optional key for diffing.

§

Text(TextNode)

A text node.

§

Fragment(Vec<VirtualNode>)

A fragment of multiple nodes without a wrapper element.

§

Dynamic(DynamicNode)

A dynamic node that re-renders based on signal changes.

§

Empty

An empty placeholder node.

Implementations§

Source§

impl VirtualNode

Implementation of virtual node construction and property extraction.

Source

pub fn needs_patch(old: &VirtualNode, new: &VirtualNode) -> bool

Determines whether the DOM needs to be patched when transitioning from old to new.

Unlike PartialEq, this method treats two Dynamic variants as different so that the renderer always re-evaluates dynamic subtrees. This is essential for route-based match expressions where different pages may occupy the same DynamicNode slot.

§Arguments
  • &VirtualNode - The old virtual node.
  • &VirtualNode - The new virtual node.
§Returns
  • bool - true if the DOM needs to be patched.
Source

pub fn get_element_node(tag_name: &str) -> Self

Creates a new element node with the given tag name.

§Arguments
  • &str - The tag name for the element.
§Returns
  • Self - A new element virtual node.
Source

pub fn get_text_node(content: &str) -> Self

Creates a new text node with the given content.

§Arguments
  • &str - The text content.
§Returns
  • Self - A new text virtual node.
Source

pub fn with_attribute(self, name: &str, value: AttributeValue) -> Self

Adds an attribute to this node if it is an element.

§Arguments
  • &str - The attribute name.
  • AttributeValue - The attribute value.
§Returns
  • Self - This node with the attribute added.
Source

pub fn with_child(self, child: VirtualNode) -> Self

Adds a child node to this node if it is an element.

§Arguments
  • VirtualNode - The child node to add.
§Returns
  • Self - This node with the child added.
Source

pub fn is_component(&self) -> bool

Returns true if this node is a component node.

§Returns
  • bool - true if this is a component node.
Source

pub fn tag_name(&self) -> Option<String>

Returns the tag name if this is an element or component node.

§Returns
  • Option<String> - The tag name, or None if not an element node.
Source

pub fn try_get_prop(&self, name: &str) -> Option<String>

Extracts a string property from this node if it is an element with the named attribute.

§Arguments
  • &str - The attribute name to look up.
§Returns
  • Option<String> - The attribute value as a string, or None if not found.
Source

pub fn try_get_typed_prop<T>(&self, name: &str) -> Option<T>
where T: FromStr,

Extracts a typed property from this node by parsing the attribute value string.

Supports Text, Signal, and Dynamic attribute values. The string representation is parsed into the target type T via FromStr.

§Arguments
  • &str - The attribute name to look up.
§Returns
  • Option<T> - The parsed value, or None if not found or parsing fails.
Source

pub fn try_get_signal_prop(&self, name: &str) -> Option<Signal<String>>

Extracts a signal property from this node if it is an element with the named attribute.

Returns the raw Signal<String> so components can reactively read the current value and subscribe to future changes, rather than receiving a snapshot string.

§Arguments
  • &str - The attribute name to look up.
§Returns
  • Option<Signal<String>> - The signal if found, or None.
Source

pub fn get_children(&self) -> Vec<VirtualNode>

Extracts children from this node if it is an element.

§Returns
  • Vec<VirtualNode> - The children, or an empty vec if not an element.
Source

pub fn try_get_text(&self) -> Option<String>

Extracts text content from this node.

§Returns
  • Option<String> - The text content, or None if not a text node.
Source

pub fn try_get_event(&self, name: &str) -> Option<NativeEventHandler>

Extracts an event handler from this node if it is an element with the named event attribute.

§Arguments
  • &str - The event name to look up.
§Returns
  • Option<NativeEventHandler> - The event handler if found, or None.
Source

pub fn try_get_callback(&self, name: &str) -> Option<NativeEventHandler>

Extracts an event handler from this node by a custom attribute name.

§Arguments
  • &str - The custom attribute name to look up.
§Returns
  • Option<NativeEventHandler> - The event handler if found, or None.

Trait Implementations§

Source§

impl AsNode for &VirtualNode

Converts a VirtualNode reference into an owned node.

Source§

fn as_node(&self) -> Option<VirtualNode>

Clones this virtual node reference into an owned Option<VirtualNode>.

§Returns
  • Option<VirtualNode> - Always Some with the cloned node.
Source§

impl AsNode for VirtualNode

Converts a VirtualNode reference into an owned node.

Source§

fn as_node(&self) -> Option<VirtualNode>

Clones this virtual node into an owned Option<VirtualNode>.

§Returns
  • Option<VirtualNode> - Always Some with the cloned node.
Source§

impl Clone for VirtualNode

Source§

fn clone(&self) -> VirtualNode

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VirtualNode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for VirtualNode

Source§

fn default() -> VirtualNode

Returns the “default value” for a type. Read more
Source§

impl IntoNode for VirtualNode

Converts a VirtualNode into itself via IntoNode.

Source§

fn into_node(self) -> VirtualNode

Returns this virtual node as-is.

§Returns
  • VirtualNode - This same virtual node.
Source§

impl PartialEq for VirtualNode

Visual equality comparison for virtual DOM nodes.

Used by DynamicNode re-rendering to skip unnecessary DOM patches when the rendered output has not changed. Event attributes are always considered equal because re-binding event listeners is handled separately by the handler registry and does not affect visual output. Dynamic nodes manage their own subtree re-rendering, so two Dynamic variants are always considered equal — the inner renderer handles patching when the dynamic content actually changes.

Source§

fn eq(&self, other: &Self) -> bool

Compares two virtual nodes for visual equality.

§Arguments
  • &Self - The first virtual node.
  • &Self - The second virtual node.
§Returns
  • bool - true if the virtual nodes are visually equal.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more