[−][src]Enum virtual_dom_rs::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 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]
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 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 element<S>(tag: S) -> VirtualNode where
S: Into<String>,
[src]
S: Into<String>,
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");
pub fn text<S>(text: S) -> VirtualNode where
S: Into<String>,
[src]
S: Into<String>,
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");
pub fn as_velement_ref(&self) -> Option<&VElement>
[src]
pub fn as_velement_mut(&mut self) -> Option<&mut VElement>
[src]
pub fn as_vtext_ref(&self) -> Option<&VText>
[src]
pub fn as_vtext_mut(&mut self) -> Option<&mut VText>
[src]
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?
fn into_iter(self) -> <VirtualNode as IntoIterator>::IntoIter
[src]
impl From<VElement> for VirtualNode
[src]
fn from(other: VElement) -> VirtualNode
[src]
impl From<String> for VirtualNode
[src]
fn from(other: String) -> VirtualNode
[src]
impl<'_> From<&'_ str> for VirtualNode
[src]
fn from(other: &str) -> VirtualNode
[src]
impl From<VirtualNode> for IterableNodes
[src]
fn from(other: VirtualNode) -> IterableNodes
[src]
impl From<VText> for VirtualNode
[src]
fn from(other: VText) -> VirtualNode
[src]
impl Into<IntoIter<VirtualNode>> for VirtualNode
[src]
ⓘImportant traits for IntoIter<T>fn into(self) -> IntoIter<VirtualNode>
[src]
impl PartialEq<VirtualNode> for VirtualNode
[src]
fn eq(&self, other: &VirtualNode) -> bool
[src]
fn ne(&self, other: &VirtualNode) -> bool
[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]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
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> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
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> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
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,