123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- //! 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 view(self, _f: impl FnOnce(&'a Bump) -> VNode<'a>) -> DTree {
- DTree {}
- }
- 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 |b| {
- dioxus_core::nodebuilder::div(b)
- .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!()
- }
|