wip: remove cx.children. start to move towards a "children" field

This commit is contained in:
Jonathan Kelley committed 2021-11-01 02:22:08 -04:00
1 parent 6b2645fd80
commit 7b97e009ec
14 files changed
+114 -276

No files matched your search

+30 -16
View File
@@ -22,13 +22,13 @@ fn new_dom<P: 'static + Send>(app: FC<P>, props: P) -> VirtualDom {
#[test]
fn test_original_diff() {
static APP: FC<()> = |(cx, props)| {
rsx! {
cx.render(rsx! {
div {
div {
"Hello, world!"
}
}
}
})
};
let mut dom = new_dom(APP, ());
@@ -58,7 +58,7 @@ fn test_original_diff() {
#[test]
fn create() {
static APP: FC<()> = |(cx, props)| {
rsx! {
cx.render(rsx! {
div {
div {
"Hello, world!"
@@ -72,7 +72,7 @@ fn create() {
}
}
}
}
})
};
let mut dom = new_dom(APP, ());
@@ -121,11 +121,11 @@ fn create() {
#[test]
fn create_list() {
static APP: FC<()> = |(cx, props)| {
rsx! {
cx.render(rsx! {
{(0..3).map(|f| rsx!{ div {
"hello"
}})}
}
})
};
let mut dom = new_dom(APP, ());
@@ -170,12 +170,12 @@ fn create_list() {
#[test]
fn create_simple() {
static APP: FC<()> = |(cx, props)| {
rsx! {
cx.render(rsx! {
div {}
div {}
div {}
div {}
}
})
};
let mut dom = new_dom(APP, ());
@@ -208,19 +208,19 @@ fn create_simple() {
#[test]
fn create_components() {
static App: FC<()> = |(cx, props)| {
rsx! {
cx.render(rsx! {
Child { "abc1" }
Child { "abc2" }
Child { "abc3" }
}
})
};
static Child: FC<()> = |(cx, props)| {
rsx! {
cx.render(rsx! {
h1 {}
div { {cx.children()} }
p {}
}
})
};
let mut dom = new_dom(App, ());
@@ -269,10 +269,10 @@ fn create_components() {
#[test]
fn anchors() {
static App: FC<()> = |(cx, props)| {
rsx! {
cx.render(rsx! {
{true.then(|| rsx!{ div { "hello" } })}
{false.then(|| rsx!{ div { "goodbye" } })}
}
})
};
let mut dom = new_dom(App, ());
@@ -303,9 +303,23 @@ fn suspended() {
|| async {
//
},
|cx, p| rsx! { "hi "},
|cx, p| todo!(),
// |cx, p| rsx! { "hi "},
);
rsx! { {val} }
// let prom = use_task(fetch());
// Value {
// a: value.await,
// b: value.await,
// f: a.await
// div {
// div {
// hidden: should_hide.await,
// }
// }
// }
cx.render(rsx! { {val} })
};
let mut dom = new_dom(App, ());
+15 -14
View File
@@ -433,11 +433,11 @@ fn keyed_diffing_order() {
let dom = new_dom();
let left = rsx!(
{(0..5).map(|f| {rsx! { div { key: "{f}" }}})}
// {(0..5).map(|f| {rsx! { div { key: "{f}" }}})}
p {"e"}
);
let right = rsx!(
{(0..2).map(|f| {rsx! { div { key: "{f}" }}})}
{(0..2).map(|f| rsx! { div { key: "{f}" }})}
p {"e"}
);
@@ -807,16 +807,17 @@ fn controlled_keyed_diffing_out_of_order_max_test() {
fn suspense() {
let dom = new_dom();
let edits = dom.create(Some(LazyNodes::new(|f| {
use std::cell::{Cell, RefCell};
VNode::Suspended(f.bump().alloc(VSuspended {
task_id: 0,
callback: RefCell::new(None),
dom_id: Cell::new(None),
}))
})));
assert_eq!(
edits.edits,
[CreatePlaceholder { root: 0 }, AppendChildren { many: 1 }]
);
todo!()
// let edits = dom.create(Some(LazyNodes::new(|f| {
// use std::cell::{Cell, RefCell};
// VNode::Suspended(f.bump().alloc(VSuspended {
// task_id: 0,
// callback: RefCell::new(None),
// dom_id: Cell::new(None),
// }))
// })));
// assert_eq!(
// edits.edits,
// [CreatePlaceholder { root: 0 }, AppendChildren { many: 1 }]
// );
}
+1 -1
View File
@@ -22,7 +22,7 @@ fn manual_diffing() {
static App: FC<AppProps> = |(cx, props)| {
let val = props.value.lock().unwrap();
rsx! { div { "{val}" } }
cx.render(rsx! { div { "{val}" } })
};
let value = Arc::new(Mutex::new("Hello"));
+2 -2
View File
@@ -15,12 +15,12 @@ fn shared_state_test() {
static App: FC<()> = |(cx, props)| {
cx.provide_state(MySharedState("world!"));
rsx!(Child {})
cx.render(rsx!(Child {}))
};
static Child: FC<()> = |(cx, props)| {
let shared = cx.consume_state::<MySharedState>()?;
rsx!("Hello, {shared.0}")
cx.render(rsx!("Hello, {shared.0}"))
};
let mut dom = VirtualDom::new(App);
+14 -13
View File
@@ -19,7 +19,7 @@ use dioxus_html as dioxus_elements;
fn app_runs() {
static App: FC<()> = |(cx, props)| {
//
rsx!( div{"hello"} )
cx.render(rsx!( div{"hello"} ))
};
let mut vdom = VirtualDom::new(App);
let edits = vdom.rebuild();
@@ -29,10 +29,10 @@ fn app_runs() {
#[test]
fn fragments_work() {
static App: FC<()> = |(cx, props)| {
rsx!(
cx.render(rsx!(
div{"hello"}
div{"goodbye"}
)
))
};
let mut vdom = VirtualDom::new(App);
let edits = vdom.rebuild();
@@ -43,10 +43,10 @@ fn fragments_work() {
#[test]
fn lists_work() {
static App: FC<()> = |(cx, props)| {
rsx!(
cx.render(rsx!(
h1 {"hello"}
{(0..6).map(|f| rsx!(span{ "{f}" }))}
)
))
};
let mut vdom = VirtualDom::new(App);
let edits = vdom.rebuild();
@@ -56,11 +56,11 @@ fn lists_work() {
#[test]
fn conditional_rendering() {
static App: FC<()> = |(cx, props)| {
rsx!(
cx.render(rsx!(
h1 {"hello"}
{true.then(|| rsx!(span{ "a" }))}
{false.then(|| rsx!(span{ "b" }))}
)
))
};
let mut vdom = VirtualDom::new(App);
@@ -73,16 +73,16 @@ fn conditional_rendering() {
#[test]
fn child_components() {
static App: FC<()> = |(cx, props)| {
rsx!(
cx.render(rsx!(
{true.then(|| rsx!(Child { }))}
{false.then(|| rsx!(Child { }))}
)
))
};
static Child: FC<()> = |(cx, props)| {
rsx!(
cx.render(rsx!(
h1 {"hello"}
h1 {"goodbye"}
)
))
};
let mut vdom = VirtualDom::new(App);
let edits = vdom.rebuild();
@@ -92,8 +92,9 @@ fn child_components() {
#[test]
fn suspended_works() {
static App: FC<()> = |(cx, props)| {
let title = use_suspense(cx, || async { "bob" }, move |cx, f| rsx! { "{f}"});
rsx!("hello" { title })
let title = use_suspense(cx, || async { "bob" }, move |cx, f| todo!());
// let title = use_suspense(cx, || async { "bob" }, move |cx, f| rsx! { "{f}"});
cx.render(rsx!("hello" { title }))
};
let mut vdom = VirtualDom::new(App);