feat: transition to cx, props
This commit is contained in:
1 parent
f1cff845ce
commit
bfdcb20437
14 files changed
+88
-50
No files matched your search
@@ -0,0 +1,45 @@
|
||||
use dioxus::{nodes::VSuspended, prelude::*, DomEdit, TestDom};
|
||||
use dioxus_core as dioxus;
|
||||
use dioxus_html as dioxus_elements;
|
||||
|
||||
static Parent: FC<()> = |cx, props| {
|
||||
//
|
||||
let value = cx.use_hook(|_| String::new(), |f| &*f, |_| {});
|
||||
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
Child { name: value }
|
||||
Child { name: value }
|
||||
Child { name: value }
|
||||
Child { name: value }
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
#[derive(Props)]
|
||||
struct ChildProps<'a> {
|
||||
name: &'a String,
|
||||
}
|
||||
|
||||
fn Child<'a>(cx: Context<'a>, props: &'a ChildProps) -> DomTree<'a> {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
h1 { "it's nested" }
|
||||
Child2 { name: props.name }
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Props)]
|
||||
struct Grandchild<'a> {
|
||||
name: &'a String,
|
||||
}
|
||||
|
||||
fn Child2<'a>(cx: Context<'a>, props: &Grandchild) -> DomTree<'a> {
|
||||
cx.render(rsx! {
|
||||
div { "Hello {props.name}!" }
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_borrowed_state() {}
|
||||
@@ -18,7 +18,7 @@ fn new_dom<P: Properties + 'static>(app: FC<P>, props: P) -> VirtualDom {
|
||||
|
||||
#[test]
|
||||
fn test_original_diff() {
|
||||
static APP: FC<()> = |cx| {
|
||||
static APP: FC<()> = |cx, props| {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
div {
|
||||
@@ -48,7 +48,7 @@ fn test_original_diff() {
|
||||
|
||||
#[test]
|
||||
fn create() {
|
||||
static APP: FC<()> = |cx| {
|
||||
static APP: FC<()> = |cx, props| {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
div {
|
||||
@@ -99,7 +99,7 @@ fn create() {
|
||||
|
||||
#[test]
|
||||
fn create_list() {
|
||||
static APP: FC<()> = |cx| {
|
||||
static APP: FC<()> = |cx, props| {
|
||||
cx.render(rsx! {
|
||||
{(0..3).map(|f| rsx!{ div {
|
||||
"hello"
|
||||
@@ -139,7 +139,7 @@ fn create_list() {
|
||||
|
||||
#[test]
|
||||
fn create_simple() {
|
||||
static APP: FC<()> = |cx| {
|
||||
static APP: FC<()> = |cx, props| {
|
||||
cx.render(rsx! {
|
||||
div {}
|
||||
div {}
|
||||
@@ -165,7 +165,7 @@ fn create_simple() {
|
||||
}
|
||||
#[test]
|
||||
fn create_components() {
|
||||
static App: FC<()> = |cx| {
|
||||
static App: FC<()> = |cx, props| {
|
||||
cx.render(rsx! {
|
||||
Child { "abc1" }
|
||||
Child { "abc2" }
|
||||
@@ -173,7 +173,7 @@ fn create_components() {
|
||||
})
|
||||
};
|
||||
|
||||
static Child: FC<()> = |cx| {
|
||||
static Child: FC<()> = |cx, props| {
|
||||
cx.render(rsx! {
|
||||
h1 {}
|
||||
div { {cx.children()} }
|
||||
@@ -217,7 +217,7 @@ fn create_components() {
|
||||
}
|
||||
#[test]
|
||||
fn anchors() {
|
||||
static App: FC<()> = |cx| {
|
||||
static App: FC<()> = |cx, props| {
|
||||
cx.render(rsx! {
|
||||
{true.then(|| rsx!{ div { "hello" } })}
|
||||
{false.then(|| rsx!{ div { "goodbye" } })}
|
||||
@@ -243,7 +243,7 @@ fn anchors() {
|
||||
|
||||
#[test]
|
||||
fn suspended() {
|
||||
static App: FC<()> = |cx| {
|
||||
static App: FC<()> = |cx, props| {
|
||||
let val = use_suspense(
|
||||
cx,
|
||||
|| async {
|
||||
|
||||
@@ -15,7 +15,7 @@ const IS_LOGGING_ENABLED: bool = true;
|
||||
|
||||
#[test]
|
||||
fn please_work() {
|
||||
static App: FC<()> = |cx| {
|
||||
static App: FC<()> = |cx, props| {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
hidden: "true"
|
||||
@@ -29,7 +29,7 @@ fn please_work() {
|
||||
})
|
||||
};
|
||||
|
||||
static Child: FC<()> = |cx| {
|
||||
static Child: FC<()> = |cx, props| {
|
||||
cx.render(rsx! {
|
||||
div { "child" }
|
||||
})
|
||||
|
||||
@@ -7,7 +7,7 @@ use dioxus_html as dioxus_elements;
|
||||
|
||||
#[async_std::test]
|
||||
async fn event_queue_works() {
|
||||
static App: FC<()> = |cx| {
|
||||
static App: FC<()> = |cx, props| {
|
||||
cx.render(rsx! {
|
||||
div { "hello world" }
|
||||
})
|
||||
|
||||
@@ -20,8 +20,8 @@ fn manual_diffing() {
|
||||
value: Shared<&'static str>,
|
||||
}
|
||||
|
||||
static App: FC<AppProps> = |cx| {
|
||||
let val = cx.value.borrow();
|
||||
static App: FC<AppProps> = |cx, props| {
|
||||
let val = props.value.borrow();
|
||||
cx.render(rsx! { div { "{val}" } })
|
||||
};
|
||||
|
||||
|
||||
@@ -15,12 +15,12 @@ fn new_dom() -> TestDom {
|
||||
fn shared_state_test() {
|
||||
struct MySharedState(&'static str);
|
||||
|
||||
static App: FC<()> = |cx| {
|
||||
static App: FC<()> = |cx, props| {
|
||||
cx.use_provide_state(|| MySharedState("world!"));
|
||||
rsx!(cx, Child {})
|
||||
};
|
||||
|
||||
static Child: FC<()> = |cx| {
|
||||
static Child: FC<()> = |cx, props| {
|
||||
let shared = cx.use_consume_state::<MySharedState>()?;
|
||||
rsx!(cx, "Hello, {shared.0}")
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@ use dioxus_html as dioxus_elements;
|
||||
|
||||
#[test]
|
||||
fn app_runs() {
|
||||
static App: FC<()> = |cx| {
|
||||
static App: FC<()> = |cx, props| {
|
||||
//
|
||||
cx.render(rsx!( div{"hello"} ))
|
||||
};
|
||||
@@ -25,7 +25,7 @@ fn app_runs() {
|
||||
|
||||
#[test]
|
||||
fn fragments_work() {
|
||||
static App: FC<()> = |cx| {
|
||||
static App: FC<()> = |cx, props| {
|
||||
cx.render(rsx!(
|
||||
div{"hello"}
|
||||
div{"goodbye"}
|
||||
@@ -39,7 +39,7 @@ fn fragments_work() {
|
||||
|
||||
#[test]
|
||||
fn lists_work() {
|
||||
static App: FC<()> = |cx| {
|
||||
static App: FC<()> = |cx, props| {
|
||||
cx.render(rsx!(
|
||||
h1 {"hello"}
|
||||
{(0..6).map(|f| rsx!(span{ "{f}" }))}
|
||||
@@ -52,7 +52,7 @@ fn lists_work() {
|
||||
|
||||
#[test]
|
||||
fn conditional_rendering() {
|
||||
static App: FC<()> = |cx| {
|
||||
static App: FC<()> = |cx, props| {
|
||||
cx.render(rsx!(
|
||||
h1 {"hello"}
|
||||
{true.then(|| rsx!(span{ "a" }))}
|
||||
@@ -69,13 +69,13 @@ fn conditional_rendering() {
|
||||
|
||||
#[test]
|
||||
fn child_components() {
|
||||
static App: FC<()> = |cx| {
|
||||
static App: FC<()> = |cx, props| {
|
||||
cx.render(rsx!(
|
||||
{true.then(|| rsx!(Child { }))}
|
||||
{false.then(|| rsx!(Child { }))}
|
||||
))
|
||||
};
|
||||
static Child: FC<()> = |cx| {
|
||||
static Child: FC<()> = |cx, props| {
|
||||
cx.render(rsx!(
|
||||
h1 {"hello"}
|
||||
h1 {"goodbye"}
|
||||
@@ -88,7 +88,7 @@ fn child_components() {
|
||||
|
||||
#[test]
|
||||
fn suspended_works() {
|
||||
static App: FC<()> = |cx| {
|
||||
static App: FC<()> = |cx, props| {
|
||||
let title = use_suspense(cx, || async { "bob" }, |cx, f| cx.render(rsx! { "{f}"}));
|
||||
cx.render(rsx!("hello" { title }))
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user