Enum percy_dom::prelude::VirtualNode
source · 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§
source§impl VirtualNode
impl VirtualNode
sourcepub fn children_recursive<'a>(&'a self) -> Vec<&'a VirtualNode, Global>
pub fn children_recursive<'a>(&'a self) -> Vec<&'a VirtualNode, Global>
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 VirtualNode
impl VirtualNode
sourcepub fn element<S>(tag: S) -> VirtualNodewhere
S: Into<String>,
pub fn element<S>(tag: S) -> VirtualNodewhere S: Into<String>,
Create a new virtual element node with a given tag.
These get patched into the DOM using document.createElement
let _div = VirtualNode::element("div");
sourcepub fn text<S>(text: S) -> VirtualNodewhere
S: Into<String>,
pub fn text<S>(text: S) -> VirtualNodewhere S: Into<String>,
Create a new virtual text node with the given text.
These get patched into the DOM using document.createTextNode
let _text = VirtualNode::text("My text node");
sourcepub fn as_velement_ref(&self) -> Option<&VElement>
pub fn as_velement_ref(&self) -> Option<&VElement>
sourcepub fn as_velement_mut(&mut self) -> Option<&mut VElement>
pub fn as_velement_mut(&mut self) -> Option<&mut VElement>
sourcepub fn as_vtext_ref(&self) -> Option<&VText>
pub fn as_vtext_ref(&self) -> Option<&VText>
sourcepub fn as_vtext_mut(&mut self) -> Option<&mut VText>
pub fn as_vtext_mut(&mut self) -> Option<&mut VText>
sourcepub fn create_dom_node(
&self,
events: &mut VirtualEvents
) -> (Node, VirtualEventNode)
pub fn create_dom_node( &self, events: &mut VirtualEvents ) -> (Node, VirtualEventNode)
Create and return a web_sys::Node
along with its events.
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
Trait Implementations§
source§impl Debug for VirtualNode
impl Debug for VirtualNode
source§impl Display for VirtualNode
impl Display for VirtualNode
source§impl<V> From<&V> for VirtualNodewhere
V: View,
impl<V> From<&V> for VirtualNodewhere V: View,
source§fn from(v: &V) -> VirtualNode
fn from(v: &V) -> VirtualNode
source§impl From<&str> for VirtualNode
impl From<&str> for VirtualNode
source§fn from(other: &str) -> VirtualNode
fn from(other: &str) -> VirtualNode
source§impl From<String> for VirtualNode
impl From<String> for VirtualNode
source§fn from(other: String) -> VirtualNode
fn from(other: String) -> VirtualNode
source§impl From<VElement> for VirtualNode
impl From<VElement> for VirtualNode
source§fn from(other: VElement) -> VirtualNode
fn from(other: VElement) -> VirtualNode
source§impl From<VText> for VirtualNode
impl From<VText> for VirtualNode
source§fn from(other: VText) -> VirtualNode
fn from(other: VText) -> VirtualNode
source§impl From<VirtualNode> for IterableNodes
impl From<VirtualNode> for IterableNodes
source§fn from(other: VirtualNode) -> IterableNodes
fn from(other: VirtualNode) -> IterableNodes
source§impl Into<IntoIter<VirtualNode, Global>> for VirtualNode
impl Into<IntoIter<VirtualNode, Global>> for VirtualNode
source§impl IntoIterator for VirtualNode
impl IntoIterator for VirtualNode
§type Item = VirtualNode
type Item = VirtualNode
§type IntoIter = IntoIter<VirtualNode, Global>
type IntoIter = IntoIter<VirtualNode, Global>
source§fn into_iter(self) -> <VirtualNode as IntoIterator>::IntoIter
fn into_iter(self) -> <VirtualNode as IntoIterator>::IntoIter
source§impl PartialEq<VirtualNode> for VirtualNode
impl PartialEq<VirtualNode> for VirtualNode
source§fn eq(&self, other: &VirtualNode) -> bool
fn eq(&self, other: &VirtualNode) -> bool
self
and other
values to be equal, and is used
by ==
.