[][src]Enum virtual_dom_rs::VirtualNode

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

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.

Methods

impl VirtualNode[src]

pub fn filter_label<F>(&'a self, filter: F) -> Vec<&'a VirtualNode> where
    F: Fn(&str) -> bool
[src]

Get a vector of all of the VirtualNode children / grandchildren / etc of your virtual_node that have a label that matches your filter.

Examples

This example is not tested

let component = html! {<div>
 <span label="hello",> {"Hi!"} </span>
 <em label="world",> {"There!!"} </em>
 <em label="hello",></em>
</div> };

let hello_nodes = component.filter_label(|label| {
    label.contains("hello")
});

assert_eq!(hello_nodes.len(), 2);
}

pub fn filter_label_equals(&'a self, label: &str) -> Vec<&'a VirtualNode>[src]

Get a vector of all of the descendants of this VirtualNode that have the provided filter.

Examples

This example is not tested

let component = html! {<div>
 <span label="hello",> {"Hi!"} </span>
 <em label="world",> {"There!!"} </em>
 <em label="hello",></em>
</div> };

let hello_nodes = component.filter_label_equals("hello");

assert_eq!(hello_nodes.len(), 2);
}

impl VirtualNode[src]

pub fn element<S>(tag: S) -> VirtualNode where
    S: Into<String>, 
[src]

Create a new virtual element node with a given tag.

These get patched into the DOM using document.createElement

This example is not tested
use virtual_dom_rs::VirtualNode;

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

pub fn text<S>(text: S) -> VirtualNode where
    S: Into<String>, 
[src]

Create a new virtual text node with the given text.

These get patched into the DOM using document.createTextNode

This example is not tested
use virtual_dom_rs::VirtualNode;

let div = VirtualNode::text("div");

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

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

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

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

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

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

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

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

pub fn create_dom_node(&self) -> CreatedNode<Node>[src]

Create and return a CreatedNode instance (containing a DOM Node together with potentially related closures) for this virtual node.

Trait Implementations

impl Display for VirtualNode[src]

impl IntoIterator for VirtualNode[src]

type Item = VirtualNode

The type of the elements being iterated over.

type IntoIter = IntoIter<VirtualNode>

Which kind of iterator are we turning this into?

impl From<VElement> for VirtualNode[src]

impl From<String> for VirtualNode[src]

impl<'_> From<&'_ str> for VirtualNode[src]

impl From<VirtualNode> for IterableNodes[src]

impl From<VText> for VirtualNode[src]

impl Into<IntoIter<VirtualNode>> for VirtualNode[src]

impl PartialEq<VirtualNode> for VirtualNode[src]

impl Debug for VirtualNode[src]

Auto Trait Implementations

impl !Send for VirtualNode

impl !Sync for VirtualNode

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]