fix: messed up how lifetimes worked, need to render once per component

This commit is contained in:
Jonathan Kelley committed 2021-10-29 21:43:21 -04:00
1 parent 0e9d5fc530
commit ba9e1dbb8f
33 files changed
+323 -184

No files matched your search

+1 -1
View File
@@ -9,7 +9,7 @@ fn main() {
pub static EXAMPLE: FC<()> = |(cx, _)| {
let list = (0..10).map(|_f| LazyNodes::new(move |_f| todo!()));
Some(LazyNodes::new(move |cx| {
cx.render(LazyNodes::new(move |cx| {
cx.raw_element(
"div",
None,
+2 -2
View File
@@ -23,7 +23,7 @@ struct ListItem {
fn app<'a>(cx: Context<'a>, props: &AppProps) -> Element<'a> {
// let (val, set_val) = use_state_classic(cx, || 0);
Some(LazyNodes::new(move |_nodecx| {
cx.render(LazyNodes::new(move |_nodecx| {
todo!()
// builder::ElementBuilder::new(_nodecx, "div")
// .iter_child({
@@ -57,7 +57,7 @@ struct ChildProps {
}
fn ChildItem<'a>(cx: Context<'a>, props: &'a ChildProps) -> Element<'a> {
Some(LazyNodes::new(move |__cx| todo!()))
cx.render(LazyNodes::new(move |__cx| todo!()))
}
impl PartialEq for ChildProps {
+1 -1
View File
@@ -26,7 +26,7 @@ fn app<'a>(cx: Context<'a>, props: &()) -> Element<'a> {
)
}));
Some(LazyNodes::new(move |f| {
cx.render(LazyNodes::new(move |f| {
f.raw_element(
"div",
None,
+7 -7
View File
@@ -1,6 +1,6 @@
#![allow(non_snake_case)]
use dioxus::component::Component;
use dioxus::component::Scope;
use dioxus::events::on::MouseEvent;
use dioxus_core as dioxus;
use dioxus_core::prelude::*;
@@ -15,7 +15,7 @@ fn main() {
assert!(g.edits.len() > 1);
}
fn App((cx, props): Component<()>) -> Element {
fn App((cx, props): Scope<()>) -> Element {
let mut rng = SmallRng::from_entropy();
let rows = (0..10_000_usize).map(|f| {
let label = Label::new(&mut rng);
@@ -26,13 +26,13 @@ fn App((cx, props): Component<()>) -> Element {
}
}
});
rsx! {
cx.render(rsx! {
table {
tbody {
{rows}
}
}
}
})
}
#[derive(PartialEq, Props)]
@@ -41,11 +41,11 @@ struct RowProps {
label: Label,
}
fn Row((cx, props): Component<RowProps>) -> Element {
fn Row((cx, props): Scope<RowProps>) -> Element {
let handler = move |evt: MouseEvent| {
let g = evt.button;
};
rsx! {
cx.render(rsx! {
tr {
td { class:"col-md-1", "{props.row_id}" }
td { class:"col-md-1", onclick: move |_| { /* run onselect */ }
@@ -58,7 +58,7 @@ fn Row((cx, props): Component<RowProps>) -> Element {
}
td { class: "col-md-6" }
}
}
})
}
#[derive(PartialEq)]
+93 -13
View File
@@ -1,5 +1,8 @@
use dioxus::component::Component;
use std::marker::PhantomData;
use dioxus::component::Scope;
use dioxus::events::on::MouseEvent;
use dioxus::nodes::{IntoVNode, IntoVNodeList};
use dioxus_core as dioxus;
use dioxus_core::prelude::*;
use dioxus_core_macro::*;
@@ -20,20 +23,97 @@ fn html_usage() {
let items = ["bob", "bill", "jack"];
let f = items.iter().filter(|f| f.starts_with("b")).map(|f| {
rsx! {
"hello {f}"
}
});
let f = items
.iter()
.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!"));
static App: FC<()> = |(cx, props)| {
//
rsx!(div {})
let name = cx.use_state(|| 0);
cx.render(rsx!(div {
h1 {}
h2 {}
}))
};
pub trait UseState<'a, T: 'static> {
fn use_state(self, f: impl FnOnce() -> T) -> &'a T;
}
impl<'a, T: 'static> UseState<'a, T> for Context<'a> {
fn use_state(self, f: impl FnOnce() -> T) -> &'a T {
todo!()
}
}
fn App3((cx, props): Scope<()>) -> Element {
let p = rsx! {
Child {
bame: 10,
}
};
cx.render(rsx!(Child {
bame: 102,
..ChildProps { bame: 10 }
}))
}
#[derive(Props, PartialEq, Debug)]
struct ChildProps {
bame: i32, // children: Children<'a>,
}
fn Child<'a>((cx, props): Scope<'a, ChildProps>) -> Element<'a> {
cx.render(rsx!(div {
// {props.children}
}))
}
// Some(LazyNodes::new(|f| {
// //
// // let r = f.fragment_from_iter(&props.children);
// r
// // todo!()
// }))
// todo!()
// rsx!({ Some(p) })
// todo!()
pub struct Children<'a> {
children: VNode<'static>,
_p: PhantomData<&'a ()>,
}
impl<'a> Children<'a> {
pub fn new(children: VNode<'a>) -> Self {
Self {
children: unsafe { std::mem::transmute(children) },
_p: PhantomData,
}
}
}
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);
cx.render(rsx!(
div {
div {
}
div {
}
}
))
};
+1 -1
View File
@@ -4,7 +4,7 @@ use dioxus_core::prelude::*;
#[async_std::main]
async fn main() {
static App: FC<()> = |(cx, props)| Some(LazyNodes::new(|f| f.text(format_args!("hello"))));
static App: FC<()> = |(cx, props)| cx.render(LazyNodes::new(|f| f.text(format_args!("hello"))));
let mut dom = VirtualDom::new(App);