pub enum Patch<'a> {
    AppendChildren(usizeVec<&'a VirtualNode>),
    TruncateChildren(usizeusize),
    Replace(usize, &'a VirtualNode),
    AddAttributes(usizeHashMap<&'a str, &'a str>),
    RemoveAttributes(usizeVec<&'a str>),
    ChangeText(usize, &'a VirtualNode),
}
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 )
                  `─'   `─'   `─'

We’ll revisit our indexing in the future when we optimize our diff/patch process.

Variants§

§

AppendChildren(usizeVec<&'a VirtualNode>)

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

§

TruncateChildren(usizeusize)

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:

becomes

§

AddAttributes(usizeHashMap<&'a str, &'a str>)

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

§

RemoveAttributes(usizeVec<&'a str>)

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

§

ChangeText(usize, &'a VirtualNode)

Change the text of a Text node.

Implementations§

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§

Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.