mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-12-25 03:53:08 +00:00
55 lines
1.3 KiB
Rust
55 lines
1.3 KiB
Rust
use dioxus_core::*;
|
|
use std::{cell::RefCell, rc::Rc, time::Duration};
|
|
|
|
#[tokio::test]
|
|
async fn it_works() {
|
|
let mut dom = VirtualDom::new(app);
|
|
|
|
let mutations = dom.rebuild();
|
|
|
|
println!("mutations: {:?}", mutations);
|
|
|
|
dom.wait_for_work().await;
|
|
}
|
|
|
|
fn app(cx: Scope) -> Element {
|
|
println!("running root app");
|
|
|
|
VNode::single_component(
|
|
cx,
|
|
cx.component(suspense_boundary, (), "suspense_boundary"),
|
|
"app",
|
|
)
|
|
}
|
|
|
|
fn suspense_boundary(cx: Scope) -> Element {
|
|
println!("running boundary");
|
|
|
|
let _ = cx.use_hook(|| {
|
|
cx.provide_context(Rc::new(RefCell::new(SuspenseBoundary::new(cx.scope_id()))))
|
|
});
|
|
|
|
VNode::single_component(cx, cx.component(async_child, (), "async_child"), "app")
|
|
}
|
|
|
|
async fn async_child(cx: Scope<'_>) -> Element {
|
|
println!("rendering async child");
|
|
|
|
let fut = cx.use_hook(|| {
|
|
Box::pin(async {
|
|
println!("Starting sleep");
|
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
|
println!("Sleep ended");
|
|
})
|
|
});
|
|
|
|
fut.await;
|
|
|
|
println!("Future awaited and complete");
|
|
|
|
VNode::single_component(cx, cx.component(async_text, (), "async_text"), "app")
|
|
}
|
|
|
|
async fn async_text(cx: Scope<'_>) -> Element {
|
|
VNode::single_text(&cx, &[TemplateNode::Text("it works!")], "beauty")
|
|
}
|