chore: tweak attributes to only set ID once

This commit is contained in:
Jonathan Kelley committed 2022-11-08 20:06:39 -08:00
1 parent fc9fe6e560
commit c096057dd3
6 files changed
+109 -90

No files matched your search

+3 -60
View File
@@ -1,5 +1,3 @@
use std::future::IntoFuture;
use dioxus::prelude::*;
fn basic_syntax_is_a_template(cx: Scope) -> Element {
@@ -25,63 +23,8 @@ fn basic_syntax_is_a_template(cx: Scope) -> Element {
})
}
#[inline_props]
fn suspense_boundary<'a>(cx: Scope<'a>, children: Element<'a>) -> Element {
cx.use_hook(|| cx.provide_context(SuspenseBoundary::new(cx.scope_id())));
cx.render(rsx! { children })
}
fn basic_child(cx: Scope) -> Element {
cx.render(rsx! {
div { "basic child 1" }
})
}
async fn async_child(cx: Scope<'_>) -> Element {
let username = use_future!(cx, || async {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
"async child 1"
});
let age = use_future!(cx, || async {
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
println!("long future completed");
1234
});
let (_user, _age) = use_future!(cx, || async {
tokio::join!(
tokio::time::sleep(std::time::Duration::from_secs(1)),
tokio::time::sleep(std::time::Duration::from_secs(2))
);
("async child 1", 1234)
})
.await;
let (username, age) = tokio::join!(username.into_future(), age.into_future());
cx.render(rsx!(
div { "Hello! {username}, you are {age}, {_user} {_age}" }
))
}
#[tokio::test]
async fn basic_prints() {
let mut dom = VirtualDom::new(|cx| {
cx.render(rsx! {
div {
h1 { "var" }
suspense_boundary {
basic_child { }
async_child { }
}
}
})
});
dbg!(dom.rebuild());
dom.wait_for_work().await;
#[test]
fn dual_stream() {
let mut dom = VirtualDom::new(basic_syntax_is_a_template);
dbg!(dom.rebuild());
}
+64
View File
@@ -0,0 +1,64 @@
use std::future::IntoFuture;
use dioxus::prelude::*;
#[inline_props]
fn suspense_boundary<'a>(cx: Scope<'a>, children: Element<'a>) -> Element {
cx.use_hook(|| cx.provide_context(SuspenseBoundary::new(cx.scope_id())));
cx.render(rsx! { children })
}
fn basic_child(cx: Scope) -> Element {
cx.render(rsx! {
div { "basic child 1" }
})
}
async fn async_child(cx: Scope<'_>) -> Element {
let username = use_future!(cx, || async {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
"async child 1"
});
let age = use_future!(cx, || async {
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
println!("long future completed");
1234
});
let (_user, _age) = use_future!(cx, || async {
tokio::join!(
tokio::time::sleep(std::time::Duration::from_secs(1)),
tokio::time::sleep(std::time::Duration::from_secs(2))
);
("async child 1", 1234)
})
.await;
let (username, age) = tokio::join!(username.into_future(), age.into_future());
cx.render(rsx!(
div { "Hello! {username}, you are {age}, {_user} {_age}" }
))
}
#[tokio::test]
async fn basic_prints() {
let mut dom = VirtualDom::new(|cx| {
cx.render(rsx! {
div {
h1 { "var" }
suspense_boundary {
basic_child { }
async_child { }
}
}
})
});
dbg!(dom.rebuild());
dom.wait_for_work().await;
dbg!(dom.rebuild());
}