wip: clean up, use old approach to components
This commit is contained in:
1 parent
289d2f2518
commit
2559740463
18 files changed
+180
-247
No files matched your search
@@ -10,7 +10,7 @@ fn test_borrowed_state() {
|
||||
let _ = VirtualDom::new(Parent);
|
||||
}
|
||||
|
||||
fn Parent((cx, _): Scope<()>) -> Element {
|
||||
fn Parent(cx: Context, props: &()) -> Element {
|
||||
let value = cx.use_hook(|_| String::new(), |f| &*f);
|
||||
|
||||
cx.render(rsx! {
|
||||
@@ -28,7 +28,7 @@ struct ChildProps<'a> {
|
||||
name: &'a str,
|
||||
}
|
||||
|
||||
fn Child((cx, props): Scope<ChildProps>) -> Element {
|
||||
fn Child(cx: Context, props: &ChildProps) -> Element {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
h1 { "it's nested" }
|
||||
@@ -42,7 +42,7 @@ struct Grandchild<'a> {
|
||||
name: &'a str,
|
||||
}
|
||||
|
||||
fn Child2((cx, props): Scope<Grandchild>) -> Element {
|
||||
fn Child2(cx: Context, props: &Grandchild) -> Element {
|
||||
cx.render(rsx! {
|
||||
div { "Hello {props.name}!" }
|
||||
})
|
||||
|
||||
@@ -21,7 +21,7 @@ fn new_dom<P: 'static + Send>(app: FC<P>, props: P) -> VirtualDom {
|
||||
|
||||
#[test]
|
||||
fn test_original_diff() {
|
||||
static APP: FC<()> = |(cx, props)| {
|
||||
static APP: FC<()> = |cx, props| {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
div {
|
||||
@@ -57,7 +57,7 @@ fn test_original_diff() {
|
||||
|
||||
#[test]
|
||||
fn create() {
|
||||
static APP: FC<()> = |(cx, props)| {
|
||||
static APP: FC<()> = |cx, props| {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
div {
|
||||
@@ -120,7 +120,7 @@ fn create() {
|
||||
|
||||
#[test]
|
||||
fn create_list() {
|
||||
static APP: FC<()> = |(cx, props)| {
|
||||
static APP: FC<()> = |cx, props| {
|
||||
cx.render(rsx! {
|
||||
{(0..3).map(|f| rsx!{ div {
|
||||
"hello"
|
||||
@@ -169,7 +169,7 @@ fn create_list() {
|
||||
|
||||
#[test]
|
||||
fn create_simple() {
|
||||
static APP: FC<()> = |(cx, props)| {
|
||||
static APP: FC<()> = |cx, props| {
|
||||
cx.render(rsx! {
|
||||
div {}
|
||||
div {}
|
||||
@@ -207,7 +207,7 @@ fn create_simple() {
|
||||
}
|
||||
#[test]
|
||||
fn create_components() {
|
||||
static App: FC<()> = |(cx, props)| {
|
||||
static App: FC<()> = |cx, props| {
|
||||
cx.render(rsx! {
|
||||
Child { "abc1" }
|
||||
Child { "abc2" }
|
||||
@@ -220,7 +220,7 @@ fn create_components() {
|
||||
children: ScopeChildren<'a>,
|
||||
}
|
||||
|
||||
fn Child<'a>((cx, props): Scope<'a, ChildProps<'a>>) -> Element {
|
||||
fn Child<'a>(cx: Context<'a>, props: &ChildProps<'a>) -> Element {
|
||||
cx.render(rsx! {
|
||||
h1 {}
|
||||
div { {&props.children} }
|
||||
@@ -273,7 +273,7 @@ fn create_components() {
|
||||
}
|
||||
#[test]
|
||||
fn anchors() {
|
||||
static App: FC<()> = |(cx, props)| {
|
||||
static App: FC<()> = |cx, props| {
|
||||
cx.render(rsx! {
|
||||
{true.then(|| rsx!{ div { "hello" } })}
|
||||
{false.then(|| rsx!{ div { "goodbye" } })}
|
||||
@@ -302,17 +302,18 @@ fn anchors() {
|
||||
|
||||
#[test]
|
||||
fn suspended() {
|
||||
static App: FC<()> = |(cx, props)| {
|
||||
let val = use_suspense(cx, || async {}, |p| todo!());
|
||||
todo!()
|
||||
// static App: FC<()> = |cx, props| {
|
||||
// let val = use_suspense(cx, || async {}, |p| todo!());
|
||||
|
||||
cx.render(rsx! { {val} })
|
||||
};
|
||||
// cx.render(rsx! { {val} })
|
||||
// };
|
||||
|
||||
let mut dom = new_dom(App, ());
|
||||
let mutations = dom.rebuild();
|
||||
// let mut dom = new_dom(App, ());
|
||||
// let mutations = dom.rebuild();
|
||||
|
||||
assert_eq!(
|
||||
mutations.edits,
|
||||
[CreatePlaceholder { root: 0 }, AppendChildren { many: 1 },]
|
||||
);
|
||||
// assert_eq!(
|
||||
// mutations.edits,
|
||||
// [CreatePlaceholder { root: 0 }, AppendChildren { many: 1 },]
|
||||
// );
|
||||
}
|
||||
@@ -13,7 +13,7 @@ mod test_logging;
|
||||
|
||||
#[test]
|
||||
fn please_work() {
|
||||
static App: FC<()> = |(cx, props)| {
|
||||
static App: FC<()> = |cx, props| {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
hidden: "true"
|
||||
@@ -27,7 +27,7 @@ fn please_work() {
|
||||
})
|
||||
};
|
||||
|
||||
static Child: FC<()> = |(cx, props)| {
|
||||
static Child: FC<()> = |cx, props| {
|
||||
cx.render(rsx! {
|
||||
div { "child" }
|
||||
})
|
||||
@@ -35,6 +35,4 @@ fn please_work() {
|
||||
|
||||
let mut dom = VirtualDom::new(App);
|
||||
dom.rebuild();
|
||||
|
||||
println!("{}", dom);
|
||||
}
|
||||
@@ -20,7 +20,7 @@ fn manual_diffing() {
|
||||
value: Shared<&'static str>,
|
||||
}
|
||||
|
||||
static App: FC<AppProps> = |(cx, props)| {
|
||||
static App: FC<AppProps> = |cx, props| {
|
||||
let val = props.value.lock().unwrap();
|
||||
cx.render(rsx! { div { "{val}" } })
|
||||
};
|
||||
@@ -37,7 +37,7 @@ fn manual_diffing() {
|
||||
|
||||
*value.lock().unwrap() = "goodbye";
|
||||
|
||||
let edits = dom.diff();
|
||||
let edits = dom.rebuild();
|
||||
|
||||
log::debug!("edits: {:?}", edits);
|
||||
}
|
||||
@@ -13,12 +13,12 @@ mod test_logging;
|
||||
fn shared_state_test() {
|
||||
struct MySharedState(&'static str);
|
||||
|
||||
static App: FC<()> = |(cx, props)| {
|
||||
static App: FC<()> = |cx, props| {
|
||||
cx.provide_state(MySharedState("world!"));
|
||||
cx.render(rsx!(Child {}))
|
||||
};
|
||||
|
||||
static Child: FC<()> = |(cx, props)| {
|
||||
static Child: FC<()> = |cx, props| {
|
||||
let shared = cx.consume_state::<MySharedState>()?;
|
||||
cx.render(rsx!("Hello, {shared.0}"))
|
||||
};
|
||||
|
||||
@@ -17,7 +17,7 @@ use dioxus_html as dioxus_elements;
|
||||
|
||||
#[test]
|
||||
fn app_runs() {
|
||||
static App: FC<()> = |(cx, props)| {
|
||||
static App: FC<()> = |cx, props| {
|
||||
//
|
||||
cx.render(rsx!( div{"hello"} ))
|
||||
};
|
||||
@@ -28,7 +28,7 @@ fn app_runs() {
|
||||
|
||||
#[test]
|
||||
fn fragments_work() {
|
||||
static App: FC<()> = |(cx, props)| {
|
||||
static App: FC<()> = |cx, props| {
|
||||
cx.render(rsx!(
|
||||
div{"hello"}
|
||||
div{"goodbye"}
|
||||
@@ -42,7 +42,7 @@ fn fragments_work() {
|
||||
|
||||
#[test]
|
||||
fn lists_work() {
|
||||
static App: FC<()> = |(cx, props)| {
|
||||
static App: FC<()> = |cx, props| {
|
||||
cx.render(rsx!(
|
||||
h1 {"hello"}
|
||||
{(0..6).map(|f| rsx!(span{ "{f}" }))}
|
||||
@@ -55,7 +55,7 @@ fn lists_work() {
|
||||
|
||||
#[test]
|
||||
fn conditional_rendering() {
|
||||
static App: FC<()> = |(cx, props)| {
|
||||
static App: FC<()> = |cx, props| {
|
||||
cx.render(rsx!(
|
||||
h1 {"hello"}
|
||||
{true.then(|| rsx!(span{ "a" }))}
|
||||
@@ -72,13 +72,13 @@ fn conditional_rendering() {
|
||||
|
||||
#[test]
|
||||
fn child_components() {
|
||||
static App: FC<()> = |(cx, props)| {
|
||||
static App: FC<()> = |cx, props| {
|
||||
cx.render(rsx!(
|
||||
{true.then(|| rsx!(Child { }))}
|
||||
{false.then(|| rsx!(Child { }))}
|
||||
))
|
||||
};
|
||||
static Child: FC<()> = |(cx, props)| {
|
||||
static Child: FC<()> = |cx, props| {
|
||||
cx.render(rsx!(
|
||||
h1 {"hello"}
|
||||
h1 {"goodbye"}
|
||||
@@ -91,13 +91,14 @@ fn child_components() {
|
||||
|
||||
#[test]
|
||||
fn suspended_works() {
|
||||
static App: FC<()> = |(cx, props)| {
|
||||
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 }))
|
||||
};
|
||||
todo!()
|
||||
// static App: FC<()> = |cx, props| {
|
||||
// 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);
|
||||
let edits = vdom.rebuild();
|
||||
dbg!(edits);
|
||||
// let mut vdom = VirtualDom::new(App);
|
||||
// let edits = vdom.rebuild();
|
||||
// dbg!(edits);
|
||||
}
|
||||
Reference in new issue
Block a user