Enum patternfly_dioxus::VNode
[−]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
NodeFactoryAPI
Variants
Text(&'src VText<'src>)
Text VNodes are 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>)
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>)
Fragment nodes may contain many VNodes without a single root.
Example
rsx!{
a {}
link {}
style {}
"asd"
Example {}
}Component(&'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)
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
impl<'src> VNode<'src>
impl<'src> VNode<'src>
pub fn mounted_id(&self) -> ElementId
pub fn mounted_id(&self) -> ElementId
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.
pub fn try_mounted_id(&self) -> Option<ElementId>
pub fn try_mounted_id(&self) -> Option<ElementId>
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)
Trait Implementations
impl<'a> IntoIterator for VNode<'a>
impl<'a> IntoIterator for VNode<'a>
impl<'a> IntoVNode<'a> for &VNode<'a>
impl<'a> IntoVNode<'a> for &VNode<'a>
fn into_vnode(self, _cx: NodeFactory<'a>) -> VNode<'a>
fn into_vnode(self, _cx: NodeFactory<'a>) -> VNode<'a>
VNode, using the NodeFactory as a source of allocationimpl<'a> IntoVNode<'a> for VNode<'a>
impl<'a> IntoVNode<'a> for VNode<'a>
fn into_vnode(self, NodeFactory<'a>) -> VNode<'a>
fn into_vnode(self, NodeFactory<'a>) -> VNode<'a>
VNode, using the NodeFactory as a source of allocation