2022-11-24 14:11:27 +00:00
|
|
|
use dioxus::core::{ElementId, Mutation::*};
|
|
|
|
use dioxus::prelude::*;
|
|
|
|
|
|
|
|
/// As we clean up old templates, the ID for the node should cycle
|
|
|
|
#[test]
|
|
|
|
fn cycling_elements() {
|
|
|
|
let mut dom = VirtualDom::new(|cx| {
|
|
|
|
cx.render(match cx.generation() % 2 {
|
|
|
|
0 => rsx! { div { "wasd" } },
|
|
|
|
1 => rsx! { div { "abcd" } },
|
|
|
|
_ => unreachable!(),
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
let edits = dom.rebuild().santize();
|
|
|
|
assert_eq!(
|
2022-12-01 04:54:30 +00:00
|
|
|
edits.dom_edits,
|
2022-11-24 14:11:27 +00:00
|
|
|
[
|
|
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(1,) },
|
|
|
|
AppendChildren { m: 1 },
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2022-11-29 21:31:04 +00:00
|
|
|
dom.mark_dirty(ScopeId(0));
|
2022-11-24 14:11:27 +00:00
|
|
|
assert_eq!(
|
2022-12-01 04:54:30 +00:00
|
|
|
dom.render_immediate().santize().dom_edits,
|
2022-11-24 14:11:27 +00:00
|
|
|
[
|
|
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(2,) },
|
|
|
|
ReplaceWith { id: ElementId(1,), m: 1 },
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
// notice that the IDs cycle back to ElementId(1), preserving a minimal memory footprint
|
2022-11-29 21:31:04 +00:00
|
|
|
dom.mark_dirty(ScopeId(0));
|
2022-11-24 14:11:27 +00:00
|
|
|
assert_eq!(
|
2022-12-01 04:54:30 +00:00
|
|
|
dom.render_immediate().santize().dom_edits,
|
2022-11-24 14:11:27 +00:00
|
|
|
[
|
|
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(1,) },
|
|
|
|
ReplaceWith { id: ElementId(2,), m: 1 },
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2022-11-29 21:31:04 +00:00
|
|
|
dom.mark_dirty(ScopeId(0));
|
2022-11-24 14:11:27 +00:00
|
|
|
assert_eq!(
|
2022-12-01 04:54:30 +00:00
|
|
|
dom.render_immediate().santize().dom_edits,
|
2022-11-24 14:11:27 +00:00
|
|
|
[
|
|
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(2,) },
|
|
|
|
ReplaceWith { id: ElementId(1,), m: 1 },
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|