[][src]Enum sauron_vdom::Patch

pub enum Patch<'a, T, ATT, EVENT, MSG> where
    MSG: 'static,
    EVENT: 'static,
    ATT: Clone
{ AppendChildren(&'a T, usizeVec<&'a Node<T, ATT, EVENT, MSG>>), TruncateChildren(&'a T, usizeusize), Replace(&'a T, usize, &'a Node<T, ATT, EVENT, MSG>), AddAttributes(&'a T, usizeVec<Attribute<ATT, EVENT, MSG>>), RemoveAttributes(&'a T, usizeVec<ATT>), AddEventListener(&'a T, usizeVec<&'a Attribute<ATT, EVENT, MSG>>), RemoveEventListener(&'a T, usizeVec<ATT>), ChangeText(usize, &'a Text), }

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 usize 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).

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

The patching process is tested in a real browser in tests/diff_patch.rs

Variants

AppendChildren(&'a T, usizeVec<&'a Node<T, ATT, EVENT, MSG>>)

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

TruncateChildren(&'a T, usizeusize)

For a node_i32, remove all children besides the first len

Replace(&'a T, usize, &'a Node<T, ATT, EVENT, MSG>)

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

becomes

AddAttributes(&'a T, usizeVec<Attribute<ATT, EVENT, MSG>>)

Add attributes that the new node has that the old node does not Note: the attributes is not a reference since attributes of same name are merged to produce a new unify attribute

RemoveAttributes(&'a T, usizeVec<ATT>)

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

AddEventListener(&'a T, usizeVec<&'a Attribute<ATT, EVENT, MSG>>)

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

RemoveEventListener(&'a T, usizeVec<ATT>)

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

ChangeText(usize, &'a Text)

Change the text of a Text node.

Implementations

impl<'a, T, ATT, EVENT, MSG> Patch<'a, T, ATT, EVENT, MSG> where
    ATT: Clone
[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.

pub fn tag(&self) -> Option<&T>[src]

return the tag of this patch

Trait Implementations

impl<'a, T: Debug, ATT: Debug, EVENT: Debug, MSG: Debug> Debug for Patch<'a, T, ATT, EVENT, MSG> where
    MSG: 'static,
    EVENT: 'static,
    ATT: Clone
[src]

impl<'a, T: PartialEq, ATT: PartialEq, EVENT: PartialEq, MSG: PartialEq> PartialEq<Patch<'a, T, ATT, EVENT, MSG>> for Patch<'a, T, ATT, EVENT, MSG> where
    MSG: 'static,
    EVENT: 'static,
    ATT: Clone
[src]

impl<'a, T, ATT, EVENT, MSG> StructuralPartialEq for Patch<'a, T, ATT, EVENT, MSG> where
    MSG: 'static,
    EVENT: 'static,
    ATT: Clone
[src]

Auto Trait Implementations

impl<'a, T, ATT, EVENT, MSG> !RefUnwindSafe for Patch<'a, T, ATT, EVENT, MSG>

impl<'a, T, ATT, EVENT, MSG> !Send for Patch<'a, T, ATT, EVENT, MSG>

impl<'a, T, ATT, EVENT, MSG> !Sync for Patch<'a, T, ATT, EVENT, MSG>

impl<'a, T, ATT, EVENT, MSG> Unpin for Patch<'a, T, ATT, EVENT, MSG> where
    ATT: Unpin

impl<'a, T, ATT, EVENT, MSG> !UnwindSafe for Patch<'a, T, ATT, EVENT, MSG>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.