Feat: revert FC changes (like the old style).

This commit reverts to the old style of props + FC. The old style is desirable
because people comfortable with react can automatically be comfortable with
dioxus. It's also nice in that the same props can be used to drive two different
components - something the trait version couldn't do. Now, our trait bound forces
implementations to have the #[derive(Props)] flag. This will need to implement the
Properties trait as well as PartialEq (using ptr::equal for closure fields).
This commit is contained in:
Jonathan Kelley committed 2021-03-09 00:58:20 -05:00
1 parent 55a5541dba
commit 7158bc3575
15 files changed
+1339 -137

No files matched your search

+30 -5
View File
@@ -7,12 +7,15 @@
fn main() {}
use dioxus_core::prelude::*;
use std::fmt::Debug;
use dioxus_core::{component::Properties, prelude::*};
struct Props {
items: Vec<ListItem>,
}
#[derive(PartialEq)]
struct ListItem {
name: String,
age: u32,
@@ -21,18 +24,18 @@ struct ListItem {
fn app(ctx: Context, props: &Props) -> DomTree {
let (f, setter) = use_state(&ctx, || 0);
ctx.render(move |b| {
let mut root = builder::ElementBuilder::new(b, "div");
ctx.render(move |c| {
let mut root = builder::ElementBuilder::new(c, "div");
for child in &props.items {
// notice that the child directly borrows from our vec
// this makes lists very fast (simply views reusing lifetimes)
// <ChildItem item=child hanldler=setter />
root = root.child(builder::virtual_child(
b.bump,
c,
ChildProps {
item: child,
item_handler: setter,
},
// <ChildItem item=child hanldler=setter />
child_item,
));
}
@@ -41,7 +44,16 @@ fn app(ctx: Context, props: &Props) -> DomTree {
}
type StateSetter<T> = dyn Fn(T);
// struct StateSetter<T>(dyn Fn(T));
// impl<T> PartialEq for StateSetter<T> {
// fn eq(&self, other: &Self) -> bool {
// self as *const _ == other as *const _
// }
// }
// props should derive a partialeq implementation automatically, but implement ptr compare for & fields
#[derive(Props)]
struct ChildProps<'a> {
// Pass down complex structs
item: &'a ListItem,
@@ -50,6 +62,19 @@ struct ChildProps<'a> {
item_handler: &'a StateSetter<i32>,
}
impl PartialEq for ChildProps<'_> {
fn eq(&self, other: &Self) -> bool {
todo!()
}
}
impl<'a> Properties for ChildProps<'a> {
type Builder = ChildPropsBuilder<'a, ((), ())>;
fn builder() -> <Self as Properties>::Builder {
ChildProps::builder()
}
}
fn child_item(ctx: Context, props: &ChildProps) -> DomTree {
todo!()
// ctx.render(rsx! {