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()
}))
};