feat: split apart template mutations
This commit is contained in:
1 parent
203935834d
commit
fc9fe6e560
21 files changed
+431
-222
No files matched your search
@@ -32,6 +32,7 @@ rand = { version = "0.8.4", features = ["small_rng"] }
|
||||
criterion = "0.3.5"
|
||||
thiserror = "1.0.30"
|
||||
env_logger = "0.9.0"
|
||||
tokio = { version = "1.21.2", features = ["full"] }
|
||||
# dioxus-edit-stream = { path = "../edit-stream" }
|
||||
|
||||
[[bench]]
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::future::IntoFuture;
|
||||
|
||||
use dioxus::prelude::*;
|
||||
|
||||
fn basic_syntax_is_a_template(cx: Scope) -> Element {
|
||||
@@ -23,41 +25,63 @@ fn basic_syntax_is_a_template(cx: Scope) -> Element {
|
||||
})
|
||||
}
|
||||
|
||||
fn basic_template(cx: Scope) -> Element {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
basic_child { }
|
||||
async_child { }
|
||||
}
|
||||
})
|
||||
#[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 {
|
||||
todo!()
|
||||
cx.render(rsx! {
|
||||
div { "basic child 1" }
|
||||
})
|
||||
}
|
||||
|
||||
async fn async_child(cx: Scope<'_>) -> Element {
|
||||
todo!()
|
||||
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}" }
|
||||
))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn basic_prints() {
|
||||
let mut dom = VirtualDom::new(basic_template);
|
||||
#[tokio::test]
|
||||
async fn basic_prints() {
|
||||
let mut dom = VirtualDom::new(|cx| {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
h1 { "var" }
|
||||
suspense_boundary {
|
||||
basic_child { }
|
||||
async_child { }
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
let mut edits = Vec::new();
|
||||
dom.rebuild(&mut edits);
|
||||
dbg!(edits);
|
||||
dbg!(dom.rebuild());
|
||||
|
||||
let mut edits = Vec::new();
|
||||
dom.rebuild(&mut edits);
|
||||
dom.wait_for_work().await;
|
||||
|
||||
dbg!(edits);
|
||||
// let renderer = dioxus_edit_stream::Mutations::default();
|
||||
//
|
||||
// dbg!(renderer.edits);
|
||||
|
||||
// takes_it(basic_child);
|
||||
dbg!(dom.rebuild());
|
||||
}
|
||||
|
||||
// fn takes_it(f: fn(Scope) -> Element) {}
|
||||
// fn takes_it(f: fn(Scope) -> Element) {}
|
||||
Reference in new issue
Block a user