Feat: building large apps, revamp macro

This commit is contained in:
Jonathan Kelley committed 2021-03-22 23:52:54 -04:00
1 parent 5791e49700
commit 9f7f43b661
20 files changed
+386 -293

No files matched your search

+14 -90
View File
@@ -1,93 +1,17 @@
// //! An alternative function syntax
// //!
// use bumpalo::Bump;
// use dioxus_core::prelude::VNode;
fn main() {}
// struct Context2<'a, P> {
// _props: &'a P, // _p: PhantomData<&'a ()>,
// rops: &'a P, // _p: PhantomData<&'a ()>,
// }
// impl<'a, P> Context2<'a, P> {
// fn render(self, _f: impl FnOnce(&'a Bump) -> VNode<'a>) -> DTree {
// DTree {}
// }
use dioxus_core::prelude::*;
// fn props(&self) -> &'a P {
// todo!()
// }
// pub fn use_hook<'scope, InternalHookState: 'static, Output: 'a>(
// &'scope self,
// _initializer: impl FnOnce() -> InternalHookState,
// _runner: impl FnOnce(&'a mut InternalHookState) -> Output,
// _cleanup: impl FnOnce(InternalHookState),
// ) -> Output {
// todo!()
// }
// }
// trait Properties {}
// struct DTree;
// // type FC2<'a, T: 'a> = fn(Context2<T>) -> DTree;
// fn virtual_child<'a, T: 'a>(_bump: &'a Bump, _props: T, _f: FC2<T>) -> VNode<'a> {
// todo!()
// }
// struct Props {
// c: String,
// }
// fn Example(ctx: Context2<Props>) -> DTree {
// let val = use_state(&ctx, || String::from("asd"));
// let props = ctx.props();
// ctx.render(move |b| {
// dioxus_core::nodebuilder::div(b)
// .child(dioxus_core::nodebuilder::text(props.c.as_str()))
// .child(virtual_child(b, Props2 { a: val }, AltChild))
// .finish()
// })
// }
// // #[fc]
// fn Example2(ctx: Context2<()>, name: &str, _blah: &str) -> DTree {
// let val = use_state(&ctx, || String::from("asd"));
// ctx.render(move |ctx| {
// dioxus_core::builder::ElementBuilder::new(b, "div")
// .child(dioxus_core::nodebuilder::text(name))
// .child(virtual_child(b, Props2 { a: val }, AltChild))
// .finish()
// })
// }
// type FC2<'a, T> = fn(Context2<T>) -> DTree;
// // still works if you don't take any references in your props (ie, something copy or cloneable)
// static CHILD: FC2<Props2> = |_ctx: Context2<Props2>| {
// //
// todo!()
// };
// struct Props2<'a> {
// a: &'a String,
// }
// impl Properties for Props2<'_> {}
// fn AltChild(ctx: Context2<Props2>) -> DTree {
// ctx.render(|_b| {
// //
// todo!()
// })
// }
// fn use_state<'a, 'c, P, T: 'static, F: FnOnce() -> T>(
// _ctx: &'_ Context2<'a, P>,
// _initial_state_fn: F,
// ) -> &'a T {
// todo!()
// }
static Example: FC<()> = |ctx, props| {
ctx.render(dioxus_core::prelude::LazyNodes::new(move |ctx| {
let bump = ctx.bump;
dioxus::builder::ElementBuilder::new(ctx, "h1")
.children([{
use bumpalo::core_alloc::fmt::Write;
let mut s = bumpalo::collections::String::new_in(bump);
write!(s, "hello");
dioxus::builder::text2(s)
}])
.finish()
}))
};
+2 -2
View File
@@ -22,7 +22,7 @@ struct ListItem {
fn app(ctx: Context, props: &Props) -> DomTree {
let (_f, setter) = use_state(&ctx, || 0);
ctx.render(move |c| {
ctx.render(dioxus::prelude::LazyNodes::new(move |c| {
let mut root = builder::ElementBuilder::new(c, "div");
for child in &props.items {
// notice that the child directly borrows from our vec
@@ -39,7 +39,7 @@ fn app(ctx: Context, props: &Props) -> DomTree {
));
}
root.finish()
})
}))
}
type StateSetter<T> = dyn Fn(T);
+2 -2
View File
@@ -13,7 +13,7 @@ struct Props {
static Example: FC<Props> = |ctx, props| {
let value = ctx.use_context(|c: &SomeContext| c.items.last().unwrap());
ctx.render(move |bump| {
ctx.render(LazyNodes::new(move |bump| {
builder::ElementBuilder::new(bump, "button")
.on("click", move |_| {
println!("Value is {}", props.name);
@@ -24,7 +24,7 @@ static Example: FC<Props> = |ctx, props| {
println!("Value is {}", props.name);
})
.finish()
})
}))
// ctx.render(html! {
// <div>
// <button onclick={move |_| println!("Value is {}", value)} />
+47 -1
View File
@@ -18,8 +18,54 @@ pub struct ExampleProps {
}
static SomeComponent: FC<ExampleProps> = |ctx, _props| {
let blah = rsx! {
div {}
};
let data = match 1 {
1 => ctx.render(rsx! (
div {
h1 {}
h3 {}
}
)),
1 => ctx.render(rsx!( div { "abc" } )),
2 => ctx.render(rsx!( div { "abc" } )),
3 => ctx.render(rsx!( div { "abc" } )),
_ => todo!(),
};
let data = match 1 {
1 => ctx.render(rsx! (
div {
h1 {}
h3 {}
}
)),
1 => ctx.render(rsx!(
div { "abc" }
)),
2 => ctx.render(rsx!(
div { "abc" }
)),
3 => ctx.render(rsx!(
div { "abc" }
)),
_ => todo!(),
};
let i = (0..10).map(|v| {
rsx! {
div {
"{v}"
}
}
});
ctx.render(rsx! {
div { }
div {
""
}
})
};
+2 -2
View File
@@ -12,7 +12,7 @@ static Header: FC<()> = |ctx, props| {
let handler1 = move || println!("Value is {}", inner.current());
ctx.render(|c| {
ctx.render(dioxus::prelude::LazyNodes::new(|c| {
builder::ElementBuilder::new(c, "div")
.child(VNode::Component(VComponent::new(
Bottom,
@@ -20,7 +20,7 @@ static Header: FC<()> = |ctx, props| {
c.bump.alloc(()),
)))
.finish()
})
}))
};
static Bottom: FC<()> = |ctx, props| {
-1
View File
@@ -1,4 +1,3 @@
use dioxus_core::prelude::*;
fn main() {}