Struct sauron::DomUpdater
source · [−]pub struct DomUpdater<MSG> {
pub current_vdom: Node<&'static str, &'static str, Leaf, &'static str, AttributeValue<MSG>>,
pub root_node: Node,
pub active_closures: HashMap<usize, Vec<(&'static str, Closure<dyn FnMut(Event) + 'static>), Global>, RandomState>,
pub focused_node: Option<Node>,
}
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<&'static str, &'static str, Leaf, &'static str, AttributeValue<MSG>>
the current vdom representation
root_node: Node
the equivalent actual DOM element where the App is mounted into
active_closures: HashMap<usize, Vec<(&'static str, Closure<dyn FnMut(Event) + 'static>), Global>, RandomState>
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
Implementations
sourceimpl<MSG> DomUpdater<MSG>
impl<MSG> DomUpdater<MSG>
sourcepub fn new(
current_vdom: Node<&'static str, &'static str, Leaf, &'static str, AttributeValue<MSG>>,
mount: &Node
) -> DomUpdater<MSG>
pub fn new(
current_vdom: Node<&'static str, &'static str, Leaf, &'static str, AttributeValue<MSG>>,
mount: &Node
) -> DomUpdater<MSG>
Creates and instance of this DOM updater, but doesn’t mount the current_vdom to the DOM just yet.
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 append_to_mount<DSP>(&mut self, program: &DSP) where
DSP: 'static + Dispatch<MSG> + Clone,
pub fn append_to_mount<DSP>(&mut self, program: &DSP) where
DSP: 'static + Dispatch<MSG> + Clone,
Mount the current_vdom appending to the actual browser DOM specified in the root_node This also gets the closures that was created when mounting the vdom to their actual DOM counterparts.
sourcepub fn replace_mount<DSP>(&mut self, program: &DSP) where
DSP: 'static + Dispatch<MSG> + Clone,
pub fn replace_mount<DSP>(&mut self, program: &DSP) where
DSP: 'static + Dispatch<MSG> + Clone,
Mount the current_vdom replacing the actual browser DOM specified in the root_node This also gets the closures that was created when mounting the vdom to their actual DOM counterparts.
sourcepub fn new_append_to_mount<DSP>(
program: &DSP,
current_vdom: Node<&'static str, &'static str, Leaf, &'static str, AttributeValue<MSG>>,
mount: &Element
) -> DomUpdater<MSG> where
DSP: 'static + Dispatch<MSG> + Clone,
pub fn new_append_to_mount<DSP>(
program: &DSP,
current_vdom: Node<&'static str, &'static str, Leaf, &'static str, AttributeValue<MSG>>,
mount: &Element
) -> DomUpdater<MSG> where
DSP: 'static + Dispatch<MSG> + Clone,
Create a new DomUpdater
.
A root Node
will be created and appended (as a child) to your passed
in mount element.
sourcepub fn new_replace_mount<DSP>(
program: &DSP,
current_vdom: Node<&'static str, &'static str, Leaf, &'static str, AttributeValue<MSG>>,
mount: Element
) -> DomUpdater<MSG> where
DSP: 'static + Dispatch<MSG> + Clone,
pub fn new_replace_mount<DSP>(
program: &DSP,
current_vdom: Node<&'static str, &'static str, Leaf, &'static str, AttributeValue<MSG>>,
mount: Element
) -> DomUpdater<MSG> where
DSP: 'static + Dispatch<MSG> + Clone,
Create a new DomUpdater
.
A root Node
will be created and it will replace your passed in mount
element.
sourcepub fn update_dom<DSP>(
&mut self,
program: &DSP,
new_vdom: Node<&'static str, &'static str, Leaf, &'static str, AttributeValue<MSG>>
) -> usize where
DSP: 'static + Dispatch<MSG> + Clone,
pub fn update_dom<DSP>(
&mut self,
program: &DSP,
new_vdom: Node<&'static str, &'static str, Leaf, &'static str, AttributeValue<MSG>>
) -> usize where
DSP: 'static + Dispatch<MSG> + Clone,
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<'_, &'static str, &'static str, Leaf, &'static str, AttributeValue<MSG>>, Global>
) where
DSP: 'static + Dispatch<MSG> + Clone,
pub fn patch_dom<DSP>(
&mut self,
program: &DSP,
patches: Vec<Patch<'_, &'static str, &'static str, Leaf, &'static str, AttributeValue<MSG>>, Global>
) where
DSP: 'static + Dispatch<MSG> + Clone,
Apply patches blindly to the root_node
in this DomUpdater.
Warning: only used this for debugging purposes
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