2022-11-29 21:31:04 +00:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn app_drops() {
|
2023-09-15 14:13:36 +00:00
|
|
|
#[component]
|
|
|
|
fn App(cx: Scope) -> Element {
|
2022-11-29 21:31:04 +00:00
|
|
|
cx.render(rsx! {
|
|
|
|
div {}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-09-15 14:13:36 +00:00
|
|
|
let mut dom = VirtualDom::new(App);
|
2022-11-29 21:31:04 +00:00
|
|
|
|
|
|
|
_ = dom.rebuild();
|
2023-08-25 13:31:23 +00:00
|
|
|
dom.mark_dirty(ScopeId::ROOT);
|
2022-11-29 21:31:04 +00:00
|
|
|
_ = dom.render_immediate();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hooks_drop() {
|
2023-09-15 14:13:36 +00:00
|
|
|
#[component]
|
|
|
|
fn App(cx: Scope) -> Element {
|
2022-11-29 21:31:04 +00:00
|
|
|
cx.use_hook(|| String::from("asd"));
|
|
|
|
cx.use_hook(|| String::from("asd"));
|
|
|
|
cx.use_hook(|| String::from("asd"));
|
|
|
|
cx.use_hook(|| String::from("asd"));
|
|
|
|
|
|
|
|
cx.render(rsx! {
|
|
|
|
div {}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-09-15 14:13:36 +00:00
|
|
|
let mut dom = VirtualDom::new(App);
|
2022-11-29 21:31:04 +00:00
|
|
|
|
|
|
|
_ = dom.rebuild();
|
2023-08-25 13:31:23 +00:00
|
|
|
dom.mark_dirty(ScopeId::ROOT);
|
2022-11-29 21:31:04 +00:00
|
|
|
_ = dom.render_immediate();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn contexts_drop() {
|
2023-09-15 14:13:36 +00:00
|
|
|
#[component]
|
|
|
|
fn App(cx: Scope) -> Element {
|
2022-11-29 21:31:04 +00:00
|
|
|
cx.provide_context(String::from("asd"));
|
|
|
|
|
|
|
|
cx.render(rsx! {
|
|
|
|
div {
|
2023-09-15 14:13:36 +00:00
|
|
|
ChildComp {}
|
2022-11-29 21:31:04 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-09-15 14:13:36 +00:00
|
|
|
#[component]
|
|
|
|
fn ChildComp(cx: Scope) -> Element {
|
2022-11-29 21:31:04 +00:00
|
|
|
let el = cx.consume_context::<String>().unwrap();
|
|
|
|
|
|
|
|
cx.render(rsx! {
|
|
|
|
div { "hello {el}" }
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-09-15 14:13:36 +00:00
|
|
|
let mut dom = VirtualDom::new(App);
|
2022-11-29 21:31:04 +00:00
|
|
|
|
|
|
|
_ = dom.rebuild();
|
2023-08-25 13:31:23 +00:00
|
|
|
dom.mark_dirty(ScopeId::ROOT);
|
2022-11-29 21:31:04 +00:00
|
|
|
_ = dom.render_immediate();
|
|
|
|
}
|
|
|
|
|
2022-12-17 04:26:04 +00:00
|
|
|
#[test]
|
|
|
|
fn tasks_drop() {
|
2023-09-15 14:13:36 +00:00
|
|
|
#[component]
|
|
|
|
fn App(cx: Scope) -> Element {
|
2022-11-29 21:31:04 +00:00
|
|
|
cx.spawn(async {
|
2022-12-17 04:26:04 +00:00
|
|
|
// tokio::time::sleep(std::time::Duration::from_millis(100000)).await;
|
2022-11-29 21:31:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
cx.render(rsx! {
|
|
|
|
div { }
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-09-15 14:13:36 +00:00
|
|
|
let mut dom = VirtualDom::new(App);
|
2022-11-29 21:31:04 +00:00
|
|
|
|
|
|
|
_ = dom.rebuild();
|
2023-08-25 13:31:23 +00:00
|
|
|
dom.mark_dirty(ScopeId::ROOT);
|
2022-11-29 21:31:04 +00:00
|
|
|
_ = dom.render_immediate();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn root_props_drop() {
|
|
|
|
struct RootProps(String);
|
|
|
|
|
|
|
|
let mut dom = VirtualDom::new_with_props(
|
|
|
|
|cx| cx.render(rsx!( div { "{cx.props.0}" } )),
|
|
|
|
RootProps("asdasd".to_string()),
|
|
|
|
);
|
|
|
|
|
|
|
|
_ = dom.rebuild();
|
2023-08-25 13:31:23 +00:00
|
|
|
dom.mark_dirty(ScopeId::ROOT);
|
2022-11-29 21:31:04 +00:00
|
|
|
_ = dom.render_immediate();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn diffing_drops_old() {
|
2023-09-15 14:13:36 +00:00
|
|
|
#[component]
|
|
|
|
fn App(cx: Scope) -> Element {
|
2022-11-29 21:31:04 +00:00
|
|
|
cx.render(rsx! {
|
|
|
|
div {
|
|
|
|
match cx.generation() % 2 {
|
2023-09-15 14:13:36 +00:00
|
|
|
0 => rsx!( ChildComp1 { name: "asdasd".to_string() }),
|
|
|
|
1 => rsx!( ChildComp2 { name: "asdasd".to_string() }),
|
2022-11-29 21:31:04 +00:00
|
|
|
_ => todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-09-15 14:13:36 +00:00
|
|
|
#[component]
|
|
|
|
fn ChildComp1(cx: Scope, name: String) -> Element {
|
2022-11-29 21:31:04 +00:00
|
|
|
cx.render(rsx! { "Hello {name}" })
|
|
|
|
}
|
|
|
|
|
2023-09-15 14:13:36 +00:00
|
|
|
#[component]
|
|
|
|
fn ChildComp2(cx: Scope, name: String) -> Element {
|
2022-11-29 21:31:04 +00:00
|
|
|
cx.render(rsx! { "Goodbye {name}" })
|
|
|
|
}
|
|
|
|
|
2023-09-15 14:13:36 +00:00
|
|
|
let mut dom = VirtualDom::new(App);
|
2022-11-29 21:31:04 +00:00
|
|
|
_ = dom.rebuild();
|
2023-08-25 13:31:23 +00:00
|
|
|
dom.mark_dirty(ScopeId::ROOT);
|
2022-11-29 21:31:04 +00:00
|
|
|
|
|
|
|
_ = dom.render_immediate();
|
|
|
|
}
|