Struct dioxus_native_core::real_dom::RealDom
source · pub struct RealDom<V: FromAnyValue + Send + Sync = ()> { /* private fields */ }
Expand description
A Dom that can sync with the VirtualDom mutations intended for use in lazy renderers. The render state passes from parent to children and or accumulates state from children to parents. To get started:
- Implement crate::passes::State for each part of your state that you want to compute incrementally
- Create a RealDom RealDom::new, passing in each state you created
- Update the state of the RealDom by adding and modifying nodes
- Call RealDom::update_state to update the state of incrementally computed values on each node
§Custom attribute values
To allow custom values to be passed into attributes implement FromAnyValue on a type that can represent your custom value and specify the V generic to be that type. If you have many different custom values, it can be useful to use a enum type to represent the variants.
Implementations§
source§impl<V: FromAnyValue + Send + Sync> RealDom<V>
impl<V: FromAnyValue + Send + Sync> RealDom<V>
sourcepub fn new(tracked_states: impl Into<Box<[TypeErasedState<V>]>>) -> RealDom<V>
pub fn new(tracked_states: impl Into<Box<[TypeErasedState<V>]>>) -> RealDom<V>
Create a new RealDom with the given states that will be inserted and updated when needed
sourcepub fn tree_ref(&self) -> TreeRefView<'_>
pub fn tree_ref(&self) -> TreeRefView<'_>
Get a reference to the tree.
sourcepub fn tree_mut(&self) -> TreeMutView<'_>
pub fn tree_mut(&self) -> TreeMutView<'_>
Get a mutable reference to the tree.
sourcepub fn create_node(&mut self, node: impl Into<NodeType<V>>) -> NodeMut<'_, V>
pub fn create_node(&mut self, node: impl Into<NodeType<V>>) -> NodeMut<'_, V>
Create a new node of the given type in the dom and return a mutable reference to it.
sourcepub fn get_listening_sorted(&self, event: &EventName) -> Vec<NodeRef<'_, V>>
pub fn get_listening_sorted(&self, event: &EventName) -> Vec<NodeRef<'_, V>>
Find all nodes that are listening for an event, sorted by there height in the dom progressing starting at the bottom and progressing up. This can be useful to avoid creating duplicate events.
sourcepub fn get_mut(&mut self, id: NodeId) -> Option<NodeMut<'_, V>>
pub fn get_mut(&mut self, id: NodeId) -> Option<NodeMut<'_, V>>
Get a mutable reference to a node.
sourcepub fn update_state(
&mut self,
ctx: SendAnyMap
) -> (FxDashSet<NodeId>, FxHashMap<NodeId, NodeMask>)
pub fn update_state( &mut self, ctx: SendAnyMap ) -> (FxDashSet<NodeId>, FxHashMap<NodeId, NodeMask>)
Update the state of the dom, after appling some mutations. This will keep the nodes in the dom up to date with their VNode counterparts.
sourcepub fn traverse_depth_first_advanced(
&self,
f: impl FnMut(NodeRef<'_, V>) -> bool
)
pub fn traverse_depth_first_advanced( &self, f: impl FnMut(NodeRef<'_, V>) -> bool )
Traverses the dom in a depth first manner,
calling the provided function on each node only when the parent function returns true
.
This is useful to not traverse through text nodes for instance.
sourcepub fn traverse_depth_first(&self, f: impl FnMut(NodeRef<'_, V>))
pub fn traverse_depth_first(&self, f: impl FnMut(NodeRef<'_, V>))
Traverses the dom in a depth first manner, calling the provided function on each node.
sourcepub fn raw_world(&self) -> &World
pub fn raw_world(&self) -> &World
Returns a reference to the underlying world. Any changes made to the world will not update the reactive system.
sourcepub fn raw_world_mut(&mut self) -> &mut World
pub fn raw_world_mut(&mut self) -> &mut World
Returns a mutable reference to the underlying world. Any changes made to the world will not update the reactive system.