[−][src]Struct virtual_node::VirtualNode
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: StringThe HTML tag, such as "div"
props: HashMap<String, String>HTML props such as id, class, style, etc
events: EventsEvents that will get added to your real DOM element via .addEventListener
children: Option<Vec<VirtualNode>>The children of this VirtualNode. So a
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]
F: Fn(&str) -> bool,
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); }
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
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
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
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 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?
fn into_iter(self) -> Self::IntoIter[src]
impl PartialEq<VirtualNode> for VirtualNode[src]
fn eq(&self, other: &VirtualNode) -> bool[src]
fn ne(&self, other: &VirtualNode) -> bool[src]
impl<'_> From<&'_ str> for VirtualNode[src]
impl From<String> for VirtualNode[src]
impl<'a> From<&'a String> for VirtualNode[src]
impl Debug for VirtualNode[src]
impl Display for VirtualNode[src]
Auto Trait Implementations
impl !Send for VirtualNode
impl !Sync for VirtualNode
Blanket Implementations
impl<I> IntoIterator for I where
I: Iterator, [src]
I: Iterator,
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?
fn into_iter(self) -> I[src]
impl<T, U> Into for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized, [src]
T: Display + ?Sized,
impl<T> From for T[src]
impl<T, U> TryFrom for T where
U: Into<T>, [src]
U: Into<T>,
type Error = !
try_from)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T> Borrow for T where
T: ?Sized, [src]
T: ?Sized,
impl<T, U> TryInto for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized, [src]
T: ?Sized,