2021-02-21 03:57:13 +00:00
|
|
|
//! Demonstrate that borrowed data is possible as a property type
|
|
|
|
//! Borrowing (rather than cloning) is very important for speed and ergonomics.
|
2021-02-22 18:10:36 +00:00
|
|
|
//!
|
|
|
|
//! It's slightly more advanced than just cloning, but well worth the investment.
|
|
|
|
//!
|
|
|
|
//! If you use the FC macro, we handle the lifetimes automatically, making it easy to write efficient & performant components.
|
2021-02-21 03:57:13 +00:00
|
|
|
fn main() {}
|
|
|
|
|
2021-03-09 19:45:52 +00:00
|
|
|
use dioxus_core::prelude::*;
|
2021-07-13 20:52:25 +00:00
|
|
|
|
2021-06-17 22:00:32 +00:00
|
|
|
use std::rc::Rc;
|
2021-02-21 03:57:13 +00:00
|
|
|
|
2021-06-17 22:00:32 +00:00
|
|
|
struct AppProps {
|
2021-05-31 22:55:56 +00:00
|
|
|
items: Vec<Rc<ListItem>>,
|
2021-02-21 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
2021-03-09 05:58:20 +00:00
|
|
|
#[derive(PartialEq)]
|
2021-02-21 03:57:13 +00:00
|
|
|
struct ListItem {
|
|
|
|
name: String,
|
|
|
|
age: u32,
|
|
|
|
}
|
|
|
|
|
2021-10-29 21:12:30 +00:00
|
|
|
fn app<'a>(cx: Context<'a>, props: &AppProps) -> Element<'a> {
|
2021-07-09 15:54:07 +00:00
|
|
|
// let (val, set_val) = use_state_classic(cx, || 0);
|
2021-03-01 02:21:17 +00:00
|
|
|
|
2021-10-30 22:23:28 +00:00
|
|
|
todo!()
|
|
|
|
// cx.render(LazyNodes::new(move |_nodecx| {
|
|
|
|
// todo!()
|
|
|
|
// // builder::ElementBuilder::new(_nodecx, "div")
|
|
|
|
// // .iter_child({
|
|
|
|
// // cx.items.iter().map(|child| {
|
|
|
|
// // builder::virtual_child(
|
|
|
|
// // _nodecx,
|
|
|
|
// // ChildItem,
|
|
|
|
// // ChildProps {
|
|
|
|
// // item: child.clone(),
|
|
|
|
// // item_handler: set_val.clone(),
|
|
|
|
// // },
|
|
|
|
// // None,
|
|
|
|
// // &[],
|
|
|
|
// // )
|
|
|
|
// // })
|
|
|
|
// // })
|
|
|
|
// // .iter_child([builder::ElementBuilder::new(_nodecx, "div")
|
|
|
|
// // .iter_child([builder::text3(_nodecx.bump(), format_args!("{}", val))])
|
|
|
|
// // .finish()])
|
|
|
|
// // .finish()
|
|
|
|
// }))
|
2021-02-21 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
2021-03-09 05:58:20 +00:00
|
|
|
// props should derive a partialeq implementation automatically, but implement ptr compare for & fields
|
2021-05-31 22:55:56 +00:00
|
|
|
struct ChildProps {
|
2021-03-01 02:21:17 +00:00
|
|
|
// Pass down complex structs
|
2021-05-31 22:55:56 +00:00
|
|
|
item: Rc<ListItem>,
|
2021-03-01 02:21:17 +00:00
|
|
|
|
|
|
|
// Even pass down handlers!
|
2021-06-17 22:00:32 +00:00
|
|
|
item_handler: Rc<dyn Fn(i32)>,
|
2021-03-09 05:58:20 +00:00
|
|
|
}
|
|
|
|
|
2021-10-29 21:12:30 +00:00
|
|
|
fn ChildItem<'a>(cx: Context<'a>, props: &'a ChildProps) -> Element<'a> {
|
2021-10-30 22:23:28 +00:00
|
|
|
todo!()
|
2021-03-01 02:21:17 +00:00
|
|
|
}
|
2021-05-31 22:55:56 +00:00
|
|
|
|
2021-06-17 22:00:32 +00:00
|
|
|
impl PartialEq for ChildProps {
|
2021-07-13 20:52:25 +00:00
|
|
|
fn eq(&self, _other: &Self) -> bool {
|
2021-06-17 22:00:32 +00:00
|
|
|
false
|
2021-05-31 22:55:56 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-22 21:20:54 +00:00
|
|
|
impl Properties for ChildProps {
|
2021-06-17 22:00:32 +00:00
|
|
|
type Builder = ();
|
2021-08-08 19:15:16 +00:00
|
|
|
const IS_STATIC: bool = true;
|
2021-06-17 22:00:32 +00:00
|
|
|
fn builder() -> Self::Builder {
|
|
|
|
()
|
2021-05-31 22:55:56 +00:00
|
|
|
}
|
2021-06-22 21:20:54 +00:00
|
|
|
unsafe fn memoize(&self, other: &Self) -> bool {
|
|
|
|
self == other
|
|
|
|
}
|
2021-05-31 22:55:56 +00:00
|
|
|
}
|