Enum percy_vdom::VirtualNode[][src]

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

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

Examples


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);
}

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

Examples


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);
}

Create a new virtual element node with a given tag.

These get patched into the DOM using document.createElement

use virtual_dom_rs::VirtualNode;

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

Create a new virtual text node with the given text.

These get patched into the DOM using document.createTextNode

use virtual_dom_rs::VirtualNode;

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

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

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

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

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

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

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.

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

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.