Struct sauron_core::dom::DomUpdater
source · [−]pub struct DomUpdater<MSG> {
pub current_vdom: Node<MSG>,
pub root_node: Option<Node>,
pub mount_node: Node,
pub active_closures: HashMap<usize, Vec<(&'static str, Closure<dyn FnMut(Event)>)>>,
pub focused_node: Option<Node>,
pub replace: bool,
pub use_shadow: bool,
}
Expand description
Used for keeping a real DOM node up to date based on the current Node and a new incoming Node that represents our latest DOM state.
Fields
current_vdom: Node<MSG>
the current vdom representation
root_node: Option<Node>
the first element of the app view, where the patch is generated is relative to
mount_node: Node
the actual DOM element where the APP is mounted to.
active_closures: HashMap<usize, Vec<(&'static str, Closure<dyn FnMut(Event)>)>>
The closures that are currently attached to elements in the page.
We keep these around so that they don’t get dropped (and thus stop working);
focused_node: Option<Node>
after mounting or update dispatch call, the element will be focused
replace: bool
if the mount node is replaced by the root_node
use_shadow: bool
whether or not to use shadow root of the mount_node
Implementations
sourceimpl<MSG> DomUpdater<MSG>
impl<MSG> DomUpdater<MSG>
sourcepub fn active_closure_len(&self) -> usize
pub fn active_closure_len(&self) -> usize
count the total active closures regardless of which element it attached to.
sourceimpl<MSG> DomUpdater<MSG> where
MSG: 'static,
impl<MSG> DomUpdater<MSG> where
MSG: 'static,
sourcepub fn mount<DSP>(&mut self, program: &DSP) where
DSP: Dispatch<MSG> + Clone + 'static,
pub fn mount<DSP>(&mut self, program: &DSP) where
DSP: Dispatch<MSG> + Clone + 'static,
each element and it’s descendant in the vdom is created into an actual DOM node.
sourcepub fn inject_style_to_mount<DSP>(&self, program: &DSP, style: &str) where
DSP: Dispatch<MSG> + Clone + 'static,
pub fn inject_style_to_mount<DSP>(&self, program: &DSP, style: &str) where
DSP: Dispatch<MSG> + Clone + 'static,
inject style element to the mount node
sourcepub fn new_append_to_mount<DSP>(
program: &DSP,
current_vdom: Node<MSG>,
mount: &Element
) -> DomUpdater<MSG> where
DSP: Dispatch<MSG> + Clone + 'static,
pub fn new_append_to_mount<DSP>(
program: &DSP,
current_vdom: Node<MSG>,
mount: &Element
) -> DomUpdater<MSG> where
DSP: Dispatch<MSG> + Clone + 'static,
Create a new DomUpdater
.
A root Node
will be created and appended (as a child) to your passed
in mount element.
sourcepub fn update_dom<DSP>(&mut self, program: &DSP, new_vdom: Node<MSG>) -> usize where
DSP: Dispatch<MSG> + Clone + 'static,
pub fn update_dom<DSP>(&mut self, program: &DSP, new_vdom: Node<MSG>) -> usize where
DSP: Dispatch<MSG> + Clone + 'static,
Diff the current virtual dom with the new virtual dom that is being passed in.
Then use that diff to patch the real DOM in the user’s browser so that they are seeing the latest state of the application.
Return the total number of patches applied
sourcepub fn patch_dom<DSP>(&mut self, program: &DSP, patches: Vec<Patch<'_, MSG>>) where
DSP: Dispatch<MSG> + Clone + 'static,
pub fn patch_dom<DSP>(&mut self, program: &DSP, patches: Vec<Patch<'_, MSG>>) where
DSP: Dispatch<MSG> + Clone + 'static,
Apply patches blindly to the root_node
in this DomUpdater.
Warning: only used this for debugging purposes
sourcepub fn root_node(&self) -> Node
pub fn root_node(&self) -> Node
Return the root node of your application, the highest ancestor of all other nodes in your real DOM tree.
sourcepub fn mount_node(&self) -> Node
pub fn mount_node(&self) -> Node
Return the root node of your application, the highest ancestor of all other nodes in your real DOM tree.
Auto Trait Implementations
impl<MSG> !RefUnwindSafe for DomUpdater<MSG>
impl<MSG> !Send for DomUpdater<MSG>
impl<MSG> !Sync for DomUpdater<MSG>
impl<MSG> Unpin for DomUpdater<MSG>
impl<MSG> !UnwindSafe for DomUpdater<MSG>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more