2022-09-30 19:03:06 +00:00
|
|
|
use dioxus::core::{self as dioxus_core, GlobalNodeId};
|
2022-06-25 13:27:10 +00:00
|
|
|
use dioxus::prelude::*;
|
2022-03-31 01:45:41 +00:00
|
|
|
use dioxus_native_core::real_dom::RealDom;
|
2022-04-12 23:46:16 +00:00
|
|
|
use dioxus_native_core::state::State;
|
2022-04-12 12:51:57 +00:00
|
|
|
use dioxus_native_core_macro::State;
|
2022-03-27 01:10:15 +00:00
|
|
|
|
2022-04-12 12:51:57 +00:00
|
|
|
#[derive(State, Default, Clone)]
|
|
|
|
struct Empty {}
|
|
|
|
|
2022-03-27 01:10:15 +00:00
|
|
|
#[test]
|
2022-04-04 17:19:21 +00:00
|
|
|
fn remove_node() {
|
2022-03-27 01:10:15 +00:00
|
|
|
#[allow(non_snake_case)]
|
|
|
|
fn Base(cx: Scope) -> Element {
|
2022-09-25 08:05:16 +00:00
|
|
|
render!(div {})
|
2022-03-27 01:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let vdom = VirtualDom::new(Base);
|
|
|
|
|
2022-04-12 12:51:57 +00:00
|
|
|
let mut dom: RealDom<Empty> = RealDom::new();
|
2022-09-30 19:03:06 +00:00
|
|
|
let (create, edit) = vdom.diff_lazynodes(
|
2022-03-27 01:10:15 +00:00
|
|
|
rsx! {
|
|
|
|
div{
|
|
|
|
div{}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
rsx! {
|
|
|
|
div{}
|
|
|
|
},
|
|
|
|
);
|
2022-09-30 19:03:06 +00:00
|
|
|
|
|
|
|
println!("create: {:#?}", create);
|
|
|
|
println!("edit: {:#?}", edit);
|
|
|
|
|
|
|
|
let _to_update = dom.apply_mutations(vec![create]);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
dom[GlobalNodeId::TemplateId {
|
|
|
|
template_ref_id: dioxus_core::ElementId(1),
|
|
|
|
template_node_id: dioxus::prelude::TemplateNodeId(0),
|
|
|
|
}]
|
|
|
|
.node_data
|
|
|
|
.height,
|
|
|
|
1
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
dom[GlobalNodeId::TemplateId {
|
|
|
|
template_ref_id: dioxus_core::ElementId(1),
|
|
|
|
template_node_id: dioxus::prelude::TemplateNodeId(1),
|
|
|
|
}]
|
|
|
|
.node_data
|
|
|
|
.height,
|
|
|
|
2
|
|
|
|
);
|
|
|
|
|
|
|
|
dom.apply_mutations(vec![edit]);
|
2022-03-27 01:10:15 +00:00
|
|
|
|
2022-04-04 18:37:04 +00:00
|
|
|
assert_eq!(dom.size(), 1);
|
2022-09-30 19:03:06 +00:00
|
|
|
assert_eq!(
|
|
|
|
dom[GlobalNodeId::TemplateId {
|
|
|
|
template_ref_id: dioxus_core::ElementId(2),
|
|
|
|
template_node_id: dioxus::prelude::TemplateNodeId(0),
|
|
|
|
}]
|
|
|
|
.node_data
|
|
|
|
.height,
|
|
|
|
1
|
|
|
|
);
|
2022-03-27 01:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-04-04 17:19:21 +00:00
|
|
|
fn add_node() {
|
2022-03-27 01:10:15 +00:00
|
|
|
#[allow(non_snake_case)]
|
|
|
|
fn Base(cx: Scope) -> Element {
|
2022-09-25 08:05:16 +00:00
|
|
|
render!(div {})
|
2022-03-27 01:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let vdom = VirtualDom::new(Base);
|
|
|
|
|
2022-09-30 19:03:06 +00:00
|
|
|
let (create, update) = vdom.diff_lazynodes(
|
2022-03-27 01:10:15 +00:00
|
|
|
rsx! {
|
|
|
|
div{}
|
|
|
|
},
|
|
|
|
rsx! {
|
|
|
|
div{
|
|
|
|
p{}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2022-09-30 19:03:06 +00:00
|
|
|
|
|
|
|
let mut dom: RealDom<Empty> = RealDom::new();
|
|
|
|
|
|
|
|
let _to_update = dom.apply_mutations(vec![create]);
|
|
|
|
|
|
|
|
assert_eq!(dom.size(), 1);
|
|
|
|
assert_eq!(
|
|
|
|
dom[GlobalNodeId::TemplateId {
|
|
|
|
template_ref_id: dioxus_core::ElementId(1),
|
|
|
|
template_node_id: dioxus::prelude::TemplateNodeId(0),
|
|
|
|
}]
|
|
|
|
.node_data
|
|
|
|
.height,
|
|
|
|
1
|
|
|
|
);
|
|
|
|
|
|
|
|
dom.apply_mutations(vec![update]);
|
|
|
|
|
|
|
|
assert_eq!(dom.size(), 1);
|
|
|
|
assert_eq!(
|
|
|
|
dom[GlobalNodeId::TemplateId {
|
|
|
|
template_ref_id: dioxus_core::ElementId(2),
|
|
|
|
template_node_id: dioxus::prelude::TemplateNodeId(0),
|
|
|
|
}]
|
|
|
|
.node_data
|
|
|
|
.height,
|
|
|
|
1
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
dom[GlobalNodeId::TemplateId {
|
|
|
|
template_ref_id: dioxus_core::ElementId(2),
|
|
|
|
template_node_id: dioxus::prelude::TemplateNodeId(1),
|
|
|
|
}]
|
|
|
|
.node_data
|
|
|
|
.height,
|
|
|
|
2
|
|
|
|
);
|
2022-03-27 01:10:15 +00:00
|
|
|
}
|