Enum dioxus_core::VNode [−][src]
pub enum VNode<'src> {
Text(&'src VText<'src>),
Element(&'src VElement<'src>),
Fragment(&'src VFragment<'src>),
Component(&'src VComponent<'src>),
Placeholder(&'src VPlaceholder),
}
Expand description
A composable “VirtualNode” to declare a User Interface in the Dioxus VirtualDOM.
VNodes are designed to be lightweight and used with with a bump allocator. To create a VNode, you can use either of:
- the
rsx!
macro - the
NodeFactory
API
Variants
Text(&'src VText<'src>)
Tuple Fields
0: &'src VText<'src>
Text VNodes simply bump-allocated (or static) string slices
Example
let mut vdom = VirtualDom::new();
let node = vdom.render_vnode(rsx!( "hello" ));
if let VNode::Text(vtext) = node {
assert_eq!(vtext.text, "hello");
assert_eq!(vtext.dom_id.get(), None);
assert_eq!(vtext.is_static, true);
}
Element(&'src VElement<'src>)
Tuple Fields
0: &'src VElement<'src>
Element VNodes are VNodes that may contain attributes, listeners, a key, a tag, and children.
Example
let mut vdom = VirtualDom::new();
let node = vdom.render_vnode(rsx!{
div {
key: "a",
onclick: |e| log::info!("clicked"),
hidden: "true",
style: { background_color: "red" },
"hello"
}
});
if let VNode::Element(velement) = node {
assert_eq!(velement.tag_name, "div");
assert_eq!(velement.namespace, None);
assert_eq!(velement.key, Some("a"));
}
Fragment(&'src VFragment<'src>)
Tuple Fields
0: &'src VFragment<'src>
Fragment nodes may contain many VNodes without a single root.
Example
rsx!{
a {}
link {}
style {}
"asd"
Example {}
}
Component(&'src VComponent<'src>)
Tuple Fields
0: &'src VComponent<'src>
Component nodes represent a mounted component with props, children, and a key.
Example
fn Example(cx: Scope) -> Element {
...
}
let mut vdom = VirtualDom::new();
let node = vdom.render_vnode(rsx!( Example {} ));
if let VNode::Component(vcomp) = node {
assert_eq!(vcomp.user_fc, Example as *const ());
}
Placeholder(&'src VPlaceholder)
Tuple Fields
0: &'src VPlaceholder
Placeholders are a type of placeholder VNode used when fragments don’t contain any children.
Placeholders cannot be directly constructed via public APIs.
Example
let mut vdom = VirtualDom::new();
let node = vdom.render_vnode(rsx!( Fragment {} ));
if let VNode::Fragment(frag) = node {
let root = &frag.children[0];
assert_eq!(root, VNode::Anchor);
}
Implementations
Get the VNode’s “key” used in the keyed diffing algorithm.
Get the ElementID of the mounted VNode.
Panics if the mounted ID is None or if the VNode is not represented by a single Element.
Try to get the ElementID of the mounted VNode.
Returns None if the VNode is not mounted, or if the VNode cannot be presented by a mounted ID (Fragment/Component)