mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-23 20:53:06 +00:00
53 lines
1.2 KiB
Rust
53 lines
1.2 KiB
Rust
#![allow(non_snake_case)]
|
|
|
|
use dioxus::core::{ElementId, Mutation::*};
|
|
use dioxus::prelude::*;
|
|
|
|
#[test]
|
|
fn test_borrowed_state() {
|
|
let mut dom = VirtualDom::new(Parent);
|
|
|
|
assert_eq!(
|
|
dom.rebuild_to_vec().santize().edits,
|
|
[
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(1,) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(2,) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(3,) },
|
|
HydrateText { path: &[0,], value: "Hello w1!".to_string(), id: ElementId(4,) },
|
|
ReplacePlaceholder { path: &[1,], m: 1 },
|
|
ReplacePlaceholder { path: &[0,], m: 1 },
|
|
AppendChildren { m: 1, id: ElementId(0) },
|
|
]
|
|
);
|
|
}
|
|
|
|
fn Parent() -> Element {
|
|
let w1 = cx.use_hook(|| String::from("w1"));
|
|
|
|
render! {
|
|
div { Child { name: w1 } }
|
|
}
|
|
}
|
|
|
|
#[derive(Props)]
|
|
struct ChildProps<'a> {
|
|
name: &'a str,
|
|
}
|
|
|
|
fn Child<'a>(cx: ChildProps) -> Element {
|
|
render! {
|
|
div {
|
|
h1 { "it's nested" }
|
|
Child2 { name: cx.name }
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Props)]
|
|
struct Grandchild<'a> {
|
|
name: &'a str,
|
|
}
|
|
|
|
fn Child2<'a>(cx: Grandchild) -> Element {
|
|
render!( div { "Hello {cx.name}!" } )
|
|
}
|