dioxus_native_core::real_dom

Struct 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:

  1. Implement crate::passes::State for each part of your state that you want to compute incrementally
  2. Create a RealDom RealDom::new, passing in each state you created
  3. Update the state of the RealDom by adding and modifying nodes
  4. 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>

Source

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

Source

pub fn tree_ref(&self) -> TreeRefView<'_>

Get a reference to the tree.

Source

pub fn tree_mut(&self) -> TreeMutView<'_>

Get a mutable reference to the tree.

Source

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.

Source

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.

Source

pub fn root_id(&self) -> NodeId

Returns the id of the root node.

Source

pub fn contains(&self, id: NodeId) -> bool

Check if a node exists in the dom.

Source

pub fn get(&self, id: NodeId) -> Option<NodeRef<'_, V>>

Get a reference to a node.

Source

pub fn get_mut(&mut self, id: NodeId) -> Option<NodeMut<'_, V>>

Get a mutable reference to a node.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn register_custom_element<E: CustomElement<V>>(&mut self)

Registers a new custom element.

Source

pub fn register_custom_element_with_factory<F, U>(&mut self)

Registers a new custom element with a custom factory.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.