fix: use annotation method from rust/58052 to fix closure lifetimes

This commit is contained in:
Jonathan Kelley committed 2021-10-30 18:23:28 -04:00
1 parent 9ee2bfb010
commit 27d891934a
15 files changed
+333 -180

No files matched your search

+11 -3
View File
@@ -1,4 +1,7 @@
use dioxus_core::prelude::*;
use dioxus_core_macro::format_args_f;
use dioxus_core_macro::rsx;
use dioxus_html as dioxus_elements;
fn main() {
let mut dom = VirtualDom::new(EXAMPLE);
@@ -7,9 +10,14 @@ fn main() {
}
pub static EXAMPLE: FC<()> = |(cx, _)| {
let list = (0..10).map(|_f| LazyNodes::new(move |_f| todo!()));
let list = (0..10).map(|_f| {
rsx! {
"{_f}"
}
});
// let list = (0..10).map(|_f| Some(Box::new(move |_f| todo!())));
cx.render(LazyNodes::new(move |cx| {
cx.render(Some(Box::new(move |cx| {
cx.raw_element(
"div",
None,
@@ -22,5 +30,5 @@ pub static EXAMPLE: FC<()> = |(cx, _)| {
],
None,
)
}))
})))
};
+24 -23
View File
@@ -23,28 +23,29 @@ struct ListItem {
fn app<'a>(cx: Context<'a>, props: &AppProps) -> Element<'a> {
// let (val, set_val) = use_state_classic(cx, || 0);
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()
}))
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()
// }))
}
// props should derive a partialeq implementation automatically, but implement ptr compare for & fields
@@ -57,7 +58,7 @@ struct ChildProps {
}
fn ChildItem<'a>(cx: Context<'a>, props: &'a ChildProps) -> Element<'a> {
cx.render(LazyNodes::new(move |__cx| todo!()))
todo!()
}
impl PartialEq for ChildProps {
+38 -37
View File
@@ -3,43 +3,44 @@ use dioxus_core::prelude::*;
fn main() {}
fn app<'a>(cx: Context<'a>, props: &()) -> Element<'a> {
let vak = use_suspense(
cx,
|| async {},
|c, _res| c.render(LazyNodes::new(move |f| f.text(format_args!("")))),
);
// let vak = use_suspense(
// cx,
// || async {},
// |c, _res| c.render(LazyNodes::new(move |f| f.text(format_args!("")))),
// );
let d1 = cx.render(LazyNodes::new(move |f| {
f.raw_element(
"div",
None,
[],
[],
[
f.fragment_from_iter(vak),
f.text(format_args!("")),
f.text(format_args!("")),
f.text(format_args!("")),
f.text(format_args!("")),
],
None,
)
}));
// let d1 = cx.render(to_lazy_nodes(move |f| {
// f.raw_element(
// "div",
// None,
// [],
// [],
// [
// // f.fragment_from_iter(vak),
// f.text(format_args!("")),
// f.text(format_args!("")),
// f.text(format_args!("")),
// f.text(format_args!("")),
// ],
// None,
// )
// }));
cx.render(LazyNodes::new(move |f| {
f.raw_element(
"div",
None,
[],
[],
[
f.text(format_args!("")),
f.text(format_args!("")),
f.text(format_args!("")),
f.text(format_args!("")),
d1.unwrap(),
],
None,
)
}))
todo!()
// cx.render(LazyNodes::new(move |f| {
// f.raw_element(
// "div",
// None,
// [],
// [],
// [
// f.text(format_args!("")),
// f.text(format_args!("")),
// f.text(format_args!("")),
// f.text(format_args!("")),
// d1.unwrap(),
// ],
// None,
// )
// }))
}
+2 -7
View File
@@ -2,7 +2,7 @@ use std::marker::PhantomData;
use dioxus::component::Scope;
use dioxus::events::on::MouseEvent;
use dioxus::nodes::{IntoVNode, IntoVNodeList};
use dioxus::nodes::IntoVNode;
use dioxus_core as dioxus;
use dioxus_core::prelude::*;
use dioxus_core_macro::*;
@@ -28,7 +28,7 @@ fn html_usage() {
.filter(|f| f.starts_with('b'))
.map(|f| rsx!("hello {f}"));
let p = rsx!(div { {f} });
// let p = rsx!(div { {f} });
}
static App2: FC<()> = |(cx, _)| cx.render(rsx!("hello world!"));
@@ -98,11 +98,6 @@ impl<'a> Children<'a> {
}
}
}
// impl<'a> IntoVNodeList<'a> for &Children<'a> {
// fn into_vnode_list(self, cx: NodeFactory<'a>) -> &'a [VNode<'a>] {
// todo!()
// }
// }
static Bapp: FC<()> = |(cx, props)| {
let name = cx.use_state(|| 0);
+169 -11
View File
@@ -2,7 +2,7 @@ use std::marker::PhantomData;
use dioxus::component::Scope;
use dioxus::events::on::MouseEvent;
use dioxus::nodes::{IntoVNode, IntoVNodeList};
use dioxus::nodes::{annotate_lazy, IntoVNode};
use dioxus_core as dioxus;
use dioxus_core::prelude::*;
use dioxus_core_macro::*;
@@ -29,10 +29,16 @@ fn t() {
};
}
fn App((cx, props): Scope<()>) -> Element {
#[derive(PartialEq, Props)]
struct OurProps {
foo: String,
}
fn App<'a>((cx, props): Scope<'a, OurProps>) -> Element<'a> {
let a = rsx! {
div {
"asd"
"{props.foo}"
}
};
@@ -45,8 +51,12 @@ fn App((cx, props): Scope<()>) -> Element {
});
let g = match "text" {
"a" => rsx!("asd"),
b => rsx!("asd"),
"a" => {
rsx!("asd")
}
_ => {
rsx!("asd")
}
};
let items = ["bob", "bill", "jack"];
@@ -56,16 +66,164 @@ fn App((cx, props): Scope<()>) -> Element {
.filter(|f| f.starts_with('b'))
.map(|f| rsx!("hello {f}"));
// use dioxus_hooks;
// let g = use_state(|| "hello".to_string());
let s: &'a mut String = cx.use_hook(|_| String::new(), |f| f, |_| {});
/*
the final closure is allowed to borrow anything provided it
*/
// cx.render({
// let p: Option<Box<dyn FnOnce(_) -> _>> = Some(Box::new(move |__cx: NodeFactory| {
// use dioxus_elements::{GlobalAttributes, SvgAttributes};
// let props = Child2Props { foo: s };
// let ch: VNode = __cx.component(Child2, props, None, []);
// __cx.element(
// dioxus_elements::div,
// [],
// [],
// [ch],
// // [__cx.component(Child2, fc_to_builder(Child2).foo(s).build(), None, [])],
// None,
// )
// }));
// p
// // let ___p: Box<dyn FnOnce(NodeFactory) -> VNode> = Box::new(move |__cx| {
// // use dioxus_elements::{GlobalAttributes, SvgAttributes};
// // let props = Child2Props { foo: s };
// // let ch: VNode = __cx.component(Child2, props, None, []);
// // __cx.element(
// // dioxus_elements::div,
// // [],
// // [],
// // [ch],
// // // [__cx.component(Child2, fc_to_builder(Child2).foo(s).build(), None, [])],
// // None,
// // )
// // });
// // Some(___p)
// })
let a = annotate_lazy(move |f| {
//
todo!()
});
let b = annotate_lazy(move |f| {
//
f.text(format_args!("{}", props.foo))
});
let c = annotate_lazy(move |f| {
//
f.component(
Child,
OurProps {
//
foo: "hello".to_string(),
},
None,
[],
)
});
let st: &'a String = cx.use_hook(|_| "hello".to_string(), |f| f, |_| {});
let d = annotate_lazy(move |f| {
//
f.component(
Child2,
Child2Props {
//
foo: st,
},
None,
[],
)
});
let e = match "asd" {
b => {
//
annotate_lazy(move |f| {
//
f.text(format_args!("{}", props.foo))
})
}
a => {
//
annotate_lazy(move |f| {
//
f.text(format_args!("{}", props.foo))
})
}
};
cx.render(annotate_lazy(move |f| {
//
f.raw_element(
"div",
None,
[],
[],
[
//
f.fragment_from_iter(a),
f.fragment_from_iter(b),
f.fragment_from_iter(c),
f.fragment_from_iter(e),
],
None,
)
// todo!()
}))
// cx.render(rsx! {
// div {
// div {
// {a}
// // {p}
// // {g}
// // {f}
// }
// // div {
// // "asd"
// // div {
// // "asd"
// // }
// // }
// // Child {
// // foo: "asd".to_string(),
// // }
// Child2 {
// foo: s,
// }
// }
// })
}
fn Child((cx, props): Scope<OurProps>) -> Element {
cx.render(rsx! {
div {
div {
{a}
{p}
{g}
{f}
}
div {}
}
})
}
// std::boxed::Box<dyn for<'r> std::ops::FnOnce(dioxus_core::NodeFactory<'r>) -> dioxus_core::VNode<'_>>
#[derive(Props)]
struct Child2Props<'a> {
foo: &'a String,
}
fn Child2<'a>((cx, props): Scope<'a, Child2Props>) -> Element<'a> {
cx.render(rsx! {
div {
// div {}
}
})
}
+2 -1
View File
@@ -4,7 +4,8 @@ use dioxus_core::prelude::*;
#[async_std::main]
async fn main() {
static App: FC<()> = |(cx, props)| cx.render(LazyNodes::new(|f| f.text(format_args!("hello"))));
static App: FC<()> =
|(cx, props)| cx.render(Some(Box::new(move |f| f.text(format_args!("hello")))));
let mut dom = VirtualDom::new(App);