1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use crate::html::attributes::{self, AttributeValue};
use crate::Event;
pub use leaf::Leaf;
pub use node_trait::NodeTrait;
pub mod leaf;
pub(crate) mod map_msg;
mod node_trait;
pub type Namespace = &'static str;
pub type Tag = &'static str;
pub type AttributeName = &'static str;
pub type Node<MSG> =
mt_dom::Node<Namespace, Tag, Leaf, AttributeName, AttributeValue<MSG>>;
pub type Element<MSG> =
mt_dom::Element<Namespace, Tag, Leaf, AttributeName, AttributeValue<MSG>>;
pub type Patch<'a, MSG> =
mt_dom::Patch<'a, Namespace, Tag, Leaf, AttributeName, AttributeValue<MSG>>;
pub type Attribute<MSG> =
mt_dom::Attribute<Namespace, AttributeName, AttributeValue<MSG>>;
pub type Listener<MSG> = attributes::Listener<Event, MSG>;
pub fn diff<'a, MSG>(
old: &'a Node<MSG>,
new: &'a Node<MSG>,
) -> Vec<Patch<'a, MSG>>
where
MSG: 'static,
{
use crate::html::attributes::Special;
use map_msg::NodeMapMsg;
let skip = |_old_node: &'a Node<MSG>, new_node: &'a Node<MSG>| {
new_node
.get_value("skip")
.map(|v| v.as_bool())
.flatten()
.unwrap_or(false)
};
let replace = |old_node: &'a Node<MSG>, new_node: &'a Node<MSG>| {
let explicit_replace_attr = new_node
.get_value("replace")
.map(|v| v.as_bool())
.flatten()
.unwrap_or(false);
let old_node_has_event = !old_node.get_callbacks().is_empty();
let new_node_has_event = !new_node.get_callbacks().is_empty();
let forbid_recycle = old_node_has_event && !new_node_has_event;
explicit_replace_attr || forbid_recycle
};
mt_dom::diff::diff_with_functions(old, new, &"key", &skip, &replace)
}