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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#![deny(
warnings,
missing_docs,
missing_copy_implementations,
trivial_casts,
trivial_numeric_casts,
unstable_features,
unused_import_braces
)]
use html::attributes::{self, AttributeValue};
#[macro_use]
extern crate doc_comment;
use cfg_if::cfg_if;
cfg_if! {if #[cfg(feature = "with-dom")] {
pub mod dom;
pub use dom::*;
pub use web_sys;
pub use wasm_bindgen;
pub use js_sys;
}}
pub use serde_json;
cfg_if! {if #[cfg(not(feature = "with-dom"))] {
pub type Event = ();
}}
#[macro_use]
pub mod html;
#[macro_use]
pub mod svg;
#[macro_use]
pub mod jss;
mod map_msg;
mod render;
pub use render::Render;
pub use mt_dom;
pub mod prelude {
pub use crate::{
html::{
attributes::{attr, *},
tags::{commons::*, *},
units::*,
*,
},
svg::{attributes::*, tags::commons::*, *},
*,
};
pub use map_msg::{
AttValueMapMsg, AttributeMapMsg, ElementMapMsg, NodeMapMsg,
};
pub use render::Render;
pub use serde_json;
#[cfg(feature = "with-dom")]
pub use wasm_bindgen::prelude::*;
#[cfg(feature = "with-dom")]
pub use web_sys;
}
pub use mt_dom::Text;
pub type Namespace = &'static str;
pub type Tag = &'static str;
pub type AttributeName = &'static str;
pub type Node<MSG> = mt_dom::Node<
Namespace,
Tag,
AttributeName,
AttributeValue,
attributes::Callback<Event, MSG>,
>;
pub type Element<MSG> = mt_dom::Element<
Namespace,
Tag,
AttributeName,
AttributeValue,
attributes::Callback<Event, MSG>,
>;
pub type Patch<'a, MSG> = mt_dom::Patch<
'a,
Namespace,
Tag,
AttributeName,
AttributeValue,
attributes::Callback<Event, MSG>,
>;
pub type Attribute<MSG> = mt_dom::Attribute<
Namespace,
AttributeName,
AttributeValue,
attributes::Callback<Event, MSG>,
>;
pub type AttValue<MSG> =
mt_dom::AttValue<AttributeValue, attributes::Callback<Event, MSG>>;
pub type Callback<MSG> = attributes::Callback<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;
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>| {
new_node
.get_value("replace")
.map(|v| v.as_bool())
.flatten()
.unwrap_or(false)
};
mt_dom::diff::diff_with_functions(old, new, &"key", &skip, &replace)
}