Struct freya_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.
pub fn is_node_listening(&self, node_id: &NodeId, event: &EventName) -> bool
pub fn get_listeners(&self, event: &EventName) -> Vec<NodeRef<'_, V>>
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.
Auto Trait Implementations§
impl<V = ()> !Freeze for RealDom<V>
impl<V = ()> !RefUnwindSafe for RealDom<V>
impl<V> Send for RealDom<V>
impl<V> Sync for RealDom<V>
impl<V> Unpin for RealDom<V>where
V: Unpin,
impl<V = ()> !UnwindSafe for RealDom<V>
Blanket Implementations§
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more