pub enum VirtualNode<Dom>where
Dom: RealDom,{
Element(VirtualElement<Dom>),
Text(VirtualText),
}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.
§Examples
use virtual_node::VirtualNode;
let div = VirtualNode::<()>::new_element("div");
assert_eq!(div.to_string(), "<div></div>");Variants§
Element(VirtualElement<Dom>)
An element node (node type ELEMENT_NODE).
Text(VirtualText)
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§
Source§impl<Handle> VirtualNode<Handle>where
Handle: RealDom,
impl<Handle> VirtualNode<Handle>where
Handle: RealDom,
Sourcepub fn children_recursive<'a>(&'a self) -> Vec<&'a VirtualNode<Handle>>
pub fn children_recursive<'a>(&'a self) -> Vec<&'a VirtualNode<Handle>>
Get a vector of all of the VirtualNode children / grandchildren / etc of your virtual_node.
Children are visited recursively depth first.
§Examples
let component = html! {
<div>
<span> {"Hi!"} </span>
<em> {"There!!"} </em>
<div> {"My Friend"} </div>
</div>
};
let children = component.children_recursive();
assert_eq!(children[2].tag(), "em");Source§impl<Dom> VirtualNode<Dom>where
Dom: RealDom,
impl<Dom> VirtualNode<Dom>where
Dom: RealDom,
Sourcepub fn new_element<S>(tag: S) -> VirtualNode<Dom>
pub fn new_element<S>(tag: S) -> VirtualNode<Dom>
Create a new virtual element node with a given tag.
These get patched into the DOM using document.createElement
let _div = VirtualNode::<()>::new_element("div");Sourcepub fn new_text<S>(text: S) -> VirtualNode<Dom>
pub fn new_text<S>(text: S) -> VirtualNode<Dom>
Create a new virtual text node with the given text.
These get patched into the DOM using document.createTextNode
let _text = VirtualNode::<()>::new_text("My text node");Sourcepub fn as_elem(&self) -> Option<&VirtualElement<Dom>>
pub fn as_elem(&self) -> Option<&VirtualElement<Dom>>
Return a VirtualElement reference, if this is an Element variant.
Sourcepub fn as_elem_mut(&mut self) -> Option<&mut VirtualElement<Dom>>
pub fn as_elem_mut(&mut self) -> Option<&mut VirtualElement<Dom>>
Return a mutable VirtualElement reference, if this is an Element variant.
Sourcepub fn as_text(&self) -> Option<&VirtualText>
pub fn as_text(&self) -> Option<&VirtualText>
Return a VirtualText reference, if this is an Text variant.
Sourcepub fn as_text_mut(&mut self) -> Option<&mut VirtualText>
pub fn as_text_mut(&mut self) -> Option<&mut VirtualText>
Sourcepub fn map_real_dom<New>(
self,
convert_event: &dyn Fn(EventHandler<Dom>) -> EventHandler<New>,
) -> VirtualNode<New>where
New: RealDom,
pub fn map_real_dom<New>(
self,
convert_event: &dyn Fn(EventHandler<Dom>) -> EventHandler<New>,
) -> VirtualNode<New>where
New: RealDom,
Convert this VirtualNode<DomA> into a VirtualNode<DomB>.
Sourcepub fn insert_space_before_text(&mut self)
pub fn insert_space_before_text(&mut self)
Used by html-macro to insert space before text that is inside of a block that came after an open tag.
html! {
So that we end up with
Sourcepub fn insert_space_after_text(&mut self)
pub fn insert_space_after_text(&mut self)
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! {
So that we end up with
Source§impl VirtualNode<Window>
impl VirtualNode<Window>
Sourcepub fn create_dom_node(
&self,
events: &mut VirtualEvents<Window>,
) -> (Node, VirtualEventNode)
pub fn create_dom_node( &self, events: &mut VirtualEvents<Window>, ) -> (Node, VirtualEventNode)
Create and return a web_sys::Node along with its events.