pub enum VirtualNode {
    Element(VElement),
    Text(VText),
}
Expand description

When building your views you’ll typically use the html! macro to generate VirtualNode’s.

html! { <div> <span></span> </div> } really generates a VirtualNode with one child (span).

Later, on the client side, you’ll use the diff and patch modules to update the real DOM with your latest tree of virtual nodes (virtual dom).

Or on the server side you’ll just call .to_string() on your root virtual node in order to recursively render the node and all of its children.

TODO: Make all of these fields private and create accessor methods TODO: Create a builder to create instances of VirtualNode::Element with attrs and children without having to explicitly create a VElement

Variants§

§

Element(VElement)

An element node (node type ELEMENT_NODE).

§

Text(VText)

A text node (node type TEXT_NODE).

Note: This wraps a VText instead of a plain String in order to enable custom methods like create_text_node() on the wrapped type.

Implementations§

source§

impl VirtualNode

source

pub fn children_recursive<'a>(&'a self) -> Vec<&'a VirtualNode, Global>

Get a vector of all of the VirtualNode children / grandchildren / etc of your virtual_node.

Children are visited recursively depth first.

Examples
let component = html! {
 <div>
   <span> {"Hi!"} </span>
   <em> {"There!!"} </em>
   <div> {"My Friend"} </div>
 </div>
};

let children = component.children_recursive();

assert_eq!(children[2].tag(), "em");
source§

impl VirtualNode

source

pub fn element<S>(tag: S) -> VirtualNodewhere S: Into<String>,

Create a new virtual element node with a given tag.

These get patched into the DOM using document.createElement

let _div = VirtualNode::element("div");
source

pub fn text<S>(text: S) -> VirtualNodewhere S: Into<String>,

Create a new virtual text node with the given text.

These get patched into the DOM using document.createTextNode

let _text = VirtualNode::text("My text node");
source

pub fn as_velement_ref(&self) -> Option<&VElement>

Return a VElement reference, if this is an Element variant.

source

pub fn as_velement_mut(&mut self) -> Option<&mut VElement>

Return a mutable VElement reference, if this is an Element variant.

source

pub fn as_vtext_ref(&self) -> Option<&VText>

Return a VText reference, if this is an Text variant.

source

pub fn as_vtext_mut(&mut self) -> Option<&mut VText>

Return a mutable VText reference, if this is an Text variant.

source

pub fn create_dom_node( &self, events: &mut VirtualEvents ) -> (Node, VirtualEventNode)

Create and return a web_sys::Node along with its events.

source

pub fn insert_space_before_text(&mut self)

Used by html-macro to insert space before text that is inside of a block that came after an open tag.

html! {

{world}
}

So that we end up with

world
when we’re finished parsing.

source

pub fn insert_space_after_text(&mut self)

Used by html-macro to insert space after braced text if we know that the next block is another block or a closing tag.

html! {

{Hello} {world}
} ->
Hello world
html! {
{Hello}
} ->
Hello

So that we end up with

Hello world
when we’re finished parsing.

Trait Implementations§

source§

impl Debug for VirtualNode

source§

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

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

impl Display for VirtualNode

source§

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

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

impl<V> From<&V> for VirtualNodewhere V: View,

source§

fn from(v: &V) -> VirtualNode

Converts to this type from the input type.
source§

impl From<&str> for VirtualNode

source§

fn from(other: &str) -> VirtualNode

Converts to this type from the input type.
source§

impl From<String> for VirtualNode

source§

fn from(other: String) -> VirtualNode

Converts to this type from the input type.
source§

impl From<VElement> for VirtualNode

source§

fn from(other: VElement) -> VirtualNode

Converts to this type from the input type.
source§

impl From<VText> for VirtualNode

source§

fn from(other: VText) -> VirtualNode

Converts to this type from the input type.
source§

impl From<VirtualNode> for IterableNodes

source§

fn from(other: VirtualNode) -> IterableNodes

Converts to this type from the input type.
source§

impl Into<IntoIter<VirtualNode, Global>> for VirtualNode

source§

fn into(self) -> IntoIter<VirtualNode, Global>

Converts this type into the (usually inferred) input type.
source§

impl IntoIterator for VirtualNode

§

type Item = VirtualNode

The type of the elements being iterated over.
§

type IntoIter = IntoIter<VirtualNode, Global>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> <VirtualNode as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
source§

impl PartialEq<VirtualNode> for VirtualNode

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for VirtualNode

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.