Function sauron::diff

source ·
pub fn diff<'a, MSG>(
    old_node: &'a Node<MSG>,
    new_node: &'a Node<MSG>
) -> Vec<Patch<'a, MSG>>
Expand description

Return the patches needed for old_node to have the same DOM as new_node

§Agruments

  • old_node - the old virtual dom node
  • new_node - the new virtual dom node
  • key - the literal name of key attribute, ie: “key”

§Example

use sauron::{diff::*, vdom::element, *};


let old: Node<()> = element(
    "main",
    vec![attr("class", "container")],
    vec![
        element("div", vec![attr("key", "1")], vec![]),
        element("div", vec![attr("key", "2")], vec![]),
    ],
);

let new: Node<()> = element(
    "main",
    vec![attr("class", "container")],
    vec![element("div", vec![attr("key", "2")], vec![])],
);

let diff = diff(&old, &new);
assert_eq!(
    diff,
    vec![Patch::remove_node(
        Some(&"div"),
        TreePath::new(vec![ 0]),
    )
    ]
);