alternative.rs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //! An alternative function syntax
  2. //!
  3. use std::marker::PhantomData;
  4. use bumpalo::Bump;
  5. use dioxus_core::prelude::{DomTree, VNode};
  6. fn main() {}
  7. struct Context2<'a, P> {
  8. props: &'a P, // _p: PhantomData<&'a ()>,
  9. }
  10. impl<'a, P> Context2<'a, P> {
  11. fn view(&self, f: impl FnOnce(&'a Bump) -> VNode<'a>) -> DTree {
  12. DTree {}
  13. }
  14. pub fn use_hook<'scope, InternalHookState: 'static, Output: 'a>(
  15. &'scope self,
  16. initializer: impl FnOnce() -> InternalHookState,
  17. runner: impl FnOnce(&'a mut InternalHookState) -> Output,
  18. cleanup: impl FnOnce(InternalHookState),
  19. ) -> Output {
  20. todo!()
  21. }
  22. }
  23. struct DTree;
  24. type FC2<'a, T: 'a> = fn(&'a Context2<T>) -> DTree;
  25. struct Props {
  26. c: String,
  27. }
  28. static Example: FC2<Props> = |ctx| {
  29. let val = use_state(&ctx, || String::from("asd"));
  30. ctx.view(move |b| {
  31. let g: VNode<'_> = virtual_child(b, Props2 { a: val }, alt_child);
  32. //
  33. dioxus_core::nodebuilder::div(b)
  34. .child(dioxus_core::nodebuilder::text(ctx.props.c.as_str()))
  35. .child(g)
  36. .finish()
  37. })
  38. };
  39. fn virtual_child<'a, T: 'a>(bump: &'a Bump, props: T, f: FC2<T>) -> VNode<'a> {
  40. todo!()
  41. }
  42. struct Props2<'a> {
  43. a: &'a String,
  44. }
  45. fn alt_child<'a>(ctx: &Context2<'a, Props2<'_>>) -> DomTree {
  46. todo!()
  47. }
  48. static CHILD: FC2<Props2> = |ctx| {
  49. //
  50. todo!()
  51. };
  52. fn use_state<'a, 'c, P, T: 'static, F: FnOnce() -> T>(
  53. ctx: &'a Context2<'a, P>,
  54. initial_state_fn: F,
  55. ) -> (&'a T) {
  56. todo!()
  57. }