Enum percy_dom::Patch [−][src]
pub enum Patch<'a> { AppendChildren(usize, Vec<&'a VirtualNode>), TruncateChildren(usize, usize), Replace(usize, &'a VirtualNode), AddAttributes(usize, HashMap<&'a str, &'a str>), RemoveAttributes(usize, Vec<&'a str>), ChangeText(usize, &'a VText), }
Expand description
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 crates/percy-dom/tests/diff_patch.rs
Variants
AppendChildren(usize, Vec<&'a VirtualNode>)
Append a vector of child nodes to a parent node id.
For a node_i32
, remove all children besides the first len
Replace(usize, &'a VirtualNode)
Replace a node with another node. This typically happens when a node’s tag changes. ex:
Add attributes that the new node has that the old node does not
Remove attributes that the old node had that the new node doesn’t
Change the text of a Text node.
Implementations
Trait Implementations
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Patch<'a>
impl<'a> !UnwindSafe for Patch<'a>