Enum percy_dom::Patch

source ·
pub enum Patch<'a> {
Show 14 variants AppendChildren { parent_old_node_idx: u32, new_nodes: Vec<&'a VirtualNode>, }, MoveToEndOfSiblings { parent_old_node_idx: u32, siblings_to_move: Vec<u32>, }, RemoveChildren { parent_old_node_idx: u32, to_remove: Vec<u32>, }, Replace { old_idx: u32, new_node: &'a VirtualNode, }, InsertBefore { anchor_old_node_idx: u32, new_nodes: Vec<&'a VirtualNode>, }, MoveNodesBefore { anchor_old_node_idx: u32, to_move: Vec<u32>, }, ValueAttributeUnchanged(u32, &'a AttributeValue), AddAttributes(u32, HashMap<&'a str, &'a AttributeValue>), RemoveAttributes(u32, Vec<&'a str>), ChangeText(u32, &'a VText), SpecialAttribute(PatchSpecialAttribute<'a>), AddEvents(u32, HashMap<&'a EventName, &'a EventHandler>), RemoveEvents(u32, Vec<(&'a EventName, &'a EventHandler)>), RemoveAllVirtualEventsWithNodeIdx(u32),
}
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 breadth first, as shown in this illustration (0 being the root node, 1 being it’s first child, 2 being it’s second child).

            .─.
           ( 0 )
            `┬'
        ┌────┴──────┐
        │           │
        ▼           ▼
       .─.         .─.
      ( 1 )       ( 2 )
       `┬'         `─'
   ┌────┴───┐       │
   │        │       ├─────┬─────┐
   ▼        ▼       │     │     │
  .─.      .─.      ▼     ▼     ▼
 ( 3 )    ( 4 )    .─.   .─.   .─.
  `─'      `─'    ( 5 ) ( 6 ) ( 7 )
                   `─'   `─'   `─'

The patching process is tested in a real browser in crates/percy-dom/tests/diff_patch.rs

Variants§

§

AppendChildren

Fields

§parent_old_node_idx: u32
§new_nodes: Vec<&'a VirtualNode>

Append a vector of child nodes to a parent node id.

§

MoveToEndOfSiblings

Fields

§parent_old_node_idx: u32
§siblings_to_move: Vec<u32>

Move the nodes to be the last of their parent’s children.

§

RemoveChildren

Fields

§parent_old_node_idx: u32

The parent of the node that is being removed.

§to_remove: Vec<u32>

The nodes to remove.

Remove child nodes.

§

Replace

Fields

§old_idx: u32
§new_node: &'a VirtualNode

Replace a node with another node. This typically happens when a node’s tag changes. ex:

becomes

§

InsertBefore

Fields

§anchor_old_node_idx: u32

The node that isn’t moving and is having another node inserted before it.

§new_nodes: Vec<&'a VirtualNode>

Insert a new element before some other sibling element.

§

MoveNodesBefore

Fields

§anchor_old_node_idx: u32

The node that we are moving other nodes to come before. This node is NOT moving during this patch.

§to_move: Vec<u32>

The old node indices of the nodes that are being moved.

Move nodes to be before some other node.

§

ValueAttributeUnchanged(u32, &'a AttributeValue)

The value attribute of a textarea or input element has not changed, but we will still patch it anyway in case something was typed into the field.

§

AddAttributes(u32, HashMap<&'a str, &'a AttributeValue>)

Add attributes that the new node has that the old node does not

§

RemoveAttributes(u32, Vec<&'a str>)

Remove attributes that the old node had that the new node doesn’t

§

ChangeText(u32, &'a VText)

Change the text of a Text node.

§

SpecialAttribute(PatchSpecialAttribute<'a>)

Patches that apply to [SpecialAttributes].

§

AddEvents(u32, HashMap<&'a EventName, &'a EventHandler>)

Insert events in the EventsByNodeIdx. If it is a non-delegated event the event will also get added to the DOM node.

§

RemoveEvents(u32, Vec<(&'a EventName, &'a EventHandler)>)

Remove events from the EventsByNodeIdx. If it is a non-delegated event the event will also get removed from the DOM node.

§

RemoveAllVirtualEventsWithNodeIdx(u32)

Delete all events in the EventsByNodeIdx for the given index, since the node has been removed from the DOM.

Trait Implementations§

source§

impl<'a> Debug for Patch<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Patch<'a>

§

impl<'a> !Send for Patch<'a>

§

impl<'a> !Sync for Patch<'a>

§

impl<'a> Unpin for Patch<'a>

§

impl<'a> !UnwindSafe for Patch<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.