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 varients.
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: &str) -> Vec<NodeRef<'_, V>>
pub fn get_listening_sorted(&self, event: &str) -> 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,
enter_shadow_dom: bool,
f: impl FnMut(NodeRef<'_, V>),
)
pub fn traverse_depth_first_advanced( &self, enter_shadow_dom: bool, f: impl FnMut(NodeRef<'_, V>), )
Traverses the dom in a depth first manner, calling the provided function on each node.
If enter_shadow_dom
is true, then the traversal will enter shadow doms in the tree.
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 traverse_breadth_first_advanced(
&self,
enter_shadow_doms: bool,
f: impl FnMut(NodeRef<'_, V>),
)
pub fn traverse_breadth_first_advanced( &self, enter_shadow_doms: bool, f: impl FnMut(NodeRef<'_, V>), )
Traverses the dom in a breadth first manner, calling the provided function on each node.
If enter_shadow_dom
is true, then the traversal will enter shadow doms in the tree.
Sourcepub fn traverse_breadth_first(&self, f: impl FnMut(NodeRef<'_, V>))
pub fn traverse_breadth_first(&self, f: impl FnMut(NodeRef<'_, V>))
Traverses the dom in a breadth first manner, calling the provided function on each node.
Sourcepub fn traverse_depth_first_mut_advanced(
&mut self,
enter_shadow_doms: bool,
f: impl FnMut(NodeMut<'_, V>),
)
pub fn traverse_depth_first_mut_advanced( &mut self, enter_shadow_doms: bool, f: impl FnMut(NodeMut<'_, V>), )
Traverses the dom in a depth first manner mutably, calling the provided function on each node.
If enter_shadow_dom
is true, then the traversal will enter shadow doms in the tree.
Sourcepub fn traverse_depth_first_mut(&mut self, f: impl FnMut(NodeMut<'_, V>))
pub fn traverse_depth_first_mut(&mut self, f: impl FnMut(NodeMut<'_, V>))
Traverses the dom in a depth first manner mutably, calling the provided function on each node.
Sourcepub fn traverse_breadth_first_mut_advanced(
&mut self,
enter_shadow_doms: bool,
f: impl FnMut(NodeMut<'_, V>),
)
pub fn traverse_breadth_first_mut_advanced( &mut self, enter_shadow_doms: bool, f: impl FnMut(NodeMut<'_, V>), )
Traverses the dom in a breadth first manner mutably, calling the provided function on each node.
If enter_shadow_dom
is true, then the traversal will enter shadow doms in the tree.
Sourcepub fn traverse_breadth_first_mut(&mut self, f: impl FnMut(NodeMut<'_, V>))
pub fn traverse_breadth_first_mut(&mut self, f: impl FnMut(NodeMut<'_, V>))
Traverses the dom in a breadth first manner mutably, calling the provided function on each node.
Sourcepub fn add_node_watcher(
&mut self,
watcher: impl NodeWatcher<V> + 'static + Send + Sync,
)
pub fn add_node_watcher( &mut self, watcher: impl NodeWatcher<V> + 'static + Send + Sync, )
Adds a NodeWatcher
to the dom. Node watchers are called whenever a node is created or removed.
Sourcepub fn add_attribute_watcher(
&mut self,
watcher: impl AttributeWatcher<V> + 'static + Send + Sync,
)
pub fn add_attribute_watcher( &mut self, watcher: impl AttributeWatcher<V> + 'static + Send + Sync, )
Adds an AttributeWatcher
to the dom. Attribute watchers are called whenever an attribute is changed.
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.
Sourcepub fn register_custom_element<E: CustomElement<V>>(&mut self)
pub fn register_custom_element<E: CustomElement<V>>(&mut self)
Registers a new custom element.
Sourcepub fn register_custom_element_with_factory<F, U>(&mut self)where
F: CustomElementFactory<U, V>,
U: CustomElementUpdater<V>,
pub fn register_custom_element_with_factory<F, U>(&mut self)where
F: CustomElementFactory<U, V>,
U: CustomElementUpdater<V>,
Registers a new custom element with a custom factory.