Feat: wire up props macro

This commit is contained in:
Jonathan Kelley committed 2021-03-09 14:45:52 -05:00
1 parent 7158bc3575
commit 37f5a7ad33
6 files changed
+87 -59

No files matched your search

+11 -8
View File
@@ -9,7 +9,7 @@ fn main() {}
use std::fmt::Debug;
use dioxus_core::{component::Properties, prelude::*};
use dioxus_core::prelude::*;
struct Props {
items: Vec<ListItem>,
@@ -32,11 +32,12 @@ fn app(ctx: Context, props: &Props) -> DomTree {
// <ChildItem item=child hanldler=setter />
root = root.child(builder::virtual_child(
c,
ChildProps {
item: child,
item_handler: setter,
},
child_item,
ChildItem,
// create the props with nothing but the fc<T>
fc_to_builder(ChildItem)
.item(child)
.item_handler(setter)
.build(),
));
}
root.finish()
@@ -64,7 +65,9 @@ struct ChildProps<'a> {
impl PartialEq for ChildProps<'_> {
fn eq(&self, other: &Self) -> bool {
todo!()
// assume the dyn fn is never stable -
// wrap with use_callback if it's an issue for you
false
}
}
@@ -75,7 +78,7 @@ impl<'a> Properties for ChildProps<'a> {
}
}
fn child_item(ctx: Context, props: &ChildProps) -> DomTree {
fn ChildItem(ctx: Context, props: &ChildProps) -> DomTree {
todo!()
// ctx.render(rsx! {
// div {
+22 -26
View File
@@ -1,41 +1,37 @@
use dioxus_core::component::fc_to_builder;
use dioxus_core::prelude::*;
use dioxus_core_macro::fc;
use std::marker::PhantomData;
// #[derive(PartialEq)]
// pub struct Example<'a> {
// b: &'a str,
// ___p: std::marker::PhantomData<&'a ()>,
// }
// impl<'a> FC for Example<'a> {
// fn render(ctx: Context<'_>, props: &Example<'a>) -> DomTree {
// let Example { b, .. } = props;
// {
// ctx.render(rsx! {
// div { "abcd {b}" }
// })
// }
// }
// }
// always try to fill in with Default
// #[fc]
fn Example(ctx: Context, a: &str, b: &str, c: &str) -> DomTree {
static BLAH: FC<()> = |ctx, props| {
let g = "asd".to_string();
ctx.render(rsx! {
div {
SomeComponent {
a: "123"
some_field: g
abc123: 10,
}
}
})
};
#[derive(PartialEq, Props)]
pub struct ExampleProps {
some_field: String,
}
// #[fc]
fn SomeComponent(ctx: Context, a: &str, b: &str) -> DomTree {
todo!()
}
static SomeComponent: FC<ExampleProps> = |ctx, props| {
ctx.render(rsx! {
div { }
})
};
fn main() {}
impl Properties for ExampleProps {
type Builder = ExamplePropsBuilder<((),)>;
fn builder() -> Self::Builder {
ExampleProps::builder()
}
}