[][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.

Implementations

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.

pub fn insert_space_before_text(&mut self)[src]

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.

pub fn insert_space_after_text(&mut self)[src]

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

impl Debug for VirtualNode[src]

impl Display for VirtualNode[src]

impl<'_, V> From<&'_ V> for VirtualNode where
    V: View
[src]

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

impl From<String> for VirtualNode[src]

impl From<VElement> for VirtualNode[src]

impl From<VText> for VirtualNode[src]

impl From<VirtualNode> for IterableNodes[src]

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

impl StructuralPartialEq for VirtualNode[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<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<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.