[−][src]Enum sauron_vdom::Patch
A Patch encodes an operation that modifies a real DOM element.
To update the real DOM that a user sees you'll want to first diff your old virtual dom and new virtual dom.
This diff operation will generate Vec<Patch>
with zero or more patches that, when
applied to your real DOM, will make your real DOM look like your new virtual dom.
Each Patch has a u32 node index that helps us identify the real DOM node that it applies to.
Our old virtual dom's nodes are indexed depth first, as shown in this illustration (0 being the root node, 1 being it's first child, 2 being it's first child's first child).
.─.
( 0 )
`┬'
┌────┴──────┐
│ │
▼ ▼
.─. .─.
( 1 ) ( 4 )
`┬' `─'
┌────┴───┐ │
│ │ ├─────┬─────┐
▼ ▼ │ │ │
.─. .─. ▼ ▼ ▼
( 2 ) ( 3 ) .─. .─. .─.
`─' `─' ( 5 ) ( 6 ) ( 7 )
`─' `─' `─'
The patching process is tested in a real browser in tests/diff_patch.rs
Variants
AppendChildren(usize, Vec<&'a Node<T, CB>>)
Append a vector of child nodes to a parent node id.
TruncateChildren(usize, usize)
For a node_i32
, remove all children besides the first len
Replace(usize, &'a Node<T, CB>)
Replace a node with another node. This typically happens when a node's tag changes. ex:
AddAttributes(usize, BTreeMap<&'a str, &'a Value>)
Add attributes that the new node has that the old node does not
RemoveAttributes(usize, Vec<&'a str>)
Remove attributes that the old node had that the new node doesn't
AddEventListener(usize, BTreeMap<&'a str, &'a CB>)
Add attributes that the new node has that the old node does not
RemoveEventListener(usize, Vec<&'a str>)
Remove attributes that the old node had that the new node doesn't
ChangeText(usize, &'a Text)
Change the text of a Text node.
Methods
impl<'a, T, CB> Patch<'a, T, CB>
[src]
pub fn node_idx(&self) -> usize
[src]
Every Patch is meant to be applied to a specific node within the DOM. Get the index of the DOM node that this patch should apply to. DOM nodes are indexed depth first with the root node in the tree having index 0.
Trait Implementations
impl<'a, T: PartialEq, CB: PartialEq> PartialEq<Patch<'a, T, CB>> for Patch<'a, T, CB>
[src]
fn eq(&self, other: &Patch<'a, T, CB>) -> bool
[src]
fn ne(&self, other: &Patch<'a, T, CB>) -> bool
[src]
impl<'a, T: Debug, CB: Debug> Debug for Patch<'a, T, CB>
[src]
Auto Trait Implementations
impl<'a, T, CB> Send for Patch<'a, T, CB> where
CB: Sync,
T: Sync,
CB: Sync,
T: Sync,
impl<'a, T, CB> Sync for Patch<'a, T, CB> where
CB: Sync,
T: Sync,
CB: Sync,
T: Sync,
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,