Function mt_dom::diff::diff_with_key [−][src]
pub fn diff_with_key<'a, NS, TAG, ATT, VAL>(
old_node: &'a Node<NS, TAG, ATT, VAL>,
new_node: &'a Node<NS, TAG, ATT, VAL>,
key: &ATT
) -> Vec<Patch<'a, NS, TAG, ATT, VAL>> where
NS: PartialEq + Clone + Debug,
TAG: PartialEq + Clone + Debug,
ATT: PartialEq + Clone + Debug,
VAL: PartialEq + Clone + Debug,
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 mt_dom::{diff::*, patch::*, *}; pub type MyNode = Node<&'static str, &'static str, &'static str, &'static str>; let old: MyNode = element( "main", vec![attr("class", "container")], vec![ element("div", vec![attr("key", "1")], vec![]), element("div", vec![attr("key", "2")], vec![]), ], ); let new: MyNode = element( "main", vec![attr("class", "container")], vec![element("div", vec![attr("key", "2")], vec![])], ); let diff = diff_with_key(&old, &new, &"key"); assert_eq!( diff, vec![RemoveNode::new( Some(&"div"), TreePath::start_at(1, vec![0, 0]), ) .into()] );