[][src]Struct virtual_node::VirtualNode

pub struct VirtualNode {
    pub tag: String,
    pub props: HashMap<String, String>,
    pub events: Events,
    pub children: Option<Vec<VirtualNode>>,
    pub text: Option<String>,
}

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

Fields

tag: String

The HTML tag, such as "div"

props: HashMap<String, String>

HTML props such as id, class, style, etc

events: Events

Events that will get added to your real DOM element via .addEventListener

children: Option<Vec<VirtualNode>>

The children of this VirtualNode. So a

structure would have a parent div and one child, em.

text: Option<String>

Some(String) if this is a text node. When patching these into a real DOM these use document.createTextNode(text)

Methods

impl VirtualNode[src]

pub fn filter_label<'a, 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>(&'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 new(tag: &str) -> VirtualNode[src]

Create a new virtual 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::new("div");

pub fn text(text: &str) -> VirtualNode[src]

Create a text node.

These get patched into the DOM using document.createTextNode

This example is not tested
use virtual_dom_rs::VirtualNode;

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

impl VirtualNode[src]

pub fn create_element(&self) -> CreatedElement[src]

Build a DOM element by recursively creating DOM nodes for this element and it's children, it's children's children, etc.

pub fn create_text_node(&self) -> Text[src]

Return a Text element from a VirtualNode, typically right before adding it into the DOM.

pub fn is_text_node(&self) -> bool[src]

Whether or not this VirtualNode is representing a Text node

Trait Implementations

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

impl From<String> for VirtualNode[src]

impl<'a> From<&'a String> for VirtualNode[src]

impl PartialEq<VirtualNode> 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 Debug for VirtualNode[src]

impl Display 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> From for T[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> ToString for T where
    T: Display + ?Sized
[src]

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

impl<T> Any for T where
    T: 'static + ?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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.