mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-23 12:43:08 +00:00
feat: tests list
This commit is contained in:
parent
9c4abcbea0
commit
09b2ff2736
3 changed files with 53 additions and 8 deletions
1
packages/core/tests/bubble_error.rs
Normal file
1
packages/core/tests/bubble_error.rs
Normal file
|
@ -0,0 +1 @@
|
|||
|
46
packages/core/tests/lists.rs
Normal file
46
packages/core/tests/lists.rs
Normal file
|
@ -0,0 +1,46 @@
|
|||
use dioxus::core::Mutation::*;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::ElementId;
|
||||
|
||||
// A real-world usecase of templates at peak performance
|
||||
// In react, this would be a lot of node creation.
|
||||
//
|
||||
// In Dioxus, we memoize the rsx! body and simplify it down to a few template loads
|
||||
fn app(cx: Scope) -> Element {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
(0..3).map(|i| rsx! {
|
||||
div {
|
||||
h1 { "hello world! "}
|
||||
p { "{i}" }
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_renders() {
|
||||
let mut dom = VirtualDom::new(app);
|
||||
|
||||
let edits = dom.rebuild().santize();
|
||||
|
||||
assert_eq!(
|
||||
edits.edits,
|
||||
[
|
||||
// Load the outer div
|
||||
LoadTemplate { name: "template", index: 0 },
|
||||
// Load each template one-by-one, rehydrating it
|
||||
LoadTemplate { name: "template", index: 0 },
|
||||
HydrateText { path: &[1, 0], value: "0", id: ElementId(6) },
|
||||
LoadTemplate { name: "template", index: 0 },
|
||||
HydrateText { path: &[1, 0], value: "1", id: ElementId(7) },
|
||||
LoadTemplate { name: "template", index: 0 },
|
||||
HydrateText { path: &[1, 0], value: "2", id: ElementId(8) },
|
||||
// Replace the 0th childn on the div with the 3 templates on the stack
|
||||
ReplacePlaceholder { m: 3, path: &[0] },
|
||||
// Append the container div to the dom
|
||||
AppendChildren { m: 1 }
|
||||
]
|
||||
)
|
||||
}
|
|
@ -7,12 +7,10 @@ use dioxus_core::ElementId;
|
|||
fn nested_passthru_creates() {
|
||||
fn app(cx: Scope) -> Element {
|
||||
cx.render(rsx! {
|
||||
Child {
|
||||
Child {
|
||||
Child {
|
||||
div {
|
||||
"hi"
|
||||
}
|
||||
pass_thru {
|
||||
pass_thru {
|
||||
pass_thru {
|
||||
div { "hi" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +18,8 @@ fn nested_passthru_creates() {
|
|||
}
|
||||
|
||||
#[inline_props]
|
||||
fn Child<'a>(cx: Scope<'a>, children: Element<'a>) -> Element {
|
||||
cx.render(rsx! { children })
|
||||
fn pass_thru<'a>(cx: Scope<'a>, children: Element<'a>) -> Element {
|
||||
cx.render(rsx!(children))
|
||||
}
|
||||
|
||||
let mut dom = VirtualDom::new(app);
|
||||
|
|
Loading…
Reference in a new issue