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>
pub fn children_recursive<'a>(&'a self) -> Vec<&'a VirtualNode>
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) -> VirtualNode
pub fn element<S>(tag: S) -> VirtualNode
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) -> VirtualNode
pub fn text<S>(text: S) -> VirtualNode
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>> for VirtualNode
impl Into<IntoIter<VirtualNode>> for VirtualNode
Source§impl IntoIterator for VirtualNode
impl IntoIterator for VirtualNode
Source§type Item = VirtualNode
type Item = VirtualNode
Source§type IntoIter = IntoIter<VirtualNode>
type IntoIter = IntoIter<VirtualNode>
Source§fn into_iter(self) -> <VirtualNode as IntoIterator>::IntoIter
fn into_iter(self) -> <VirtualNode as IntoIterator>::IntoIter
Source§impl PartialEq for VirtualNode
impl PartialEq for VirtualNode
impl StructuralPartialEq for VirtualNode
Auto Trait Implementations§
impl !Freeze for VirtualNode
impl !RefUnwindSafe for VirtualNode
impl !Send for VirtualNode
impl !Sync for VirtualNode
impl Unpin for VirtualNode
impl !UnwindSafe for VirtualNode
Blanket Implementations§
Source§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> Self::Output
fn aggregate_filter<P>(self, f: P) -> Self::Output
Source§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self to an expression for Diesel’s query builder. Read more