nested.rs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #![allow(unused)]
  2. //! Example of components in
  3. use std::{borrow::Borrow, marker::PhantomData};
  4. use dioxus_core::prelude::*;
  5. fn main() {}
  6. static Header: FC<()> = |ctx| {
  7. let inner = use_ref(ctx, || 0);
  8. let handler1 = move || println!("Value is {}", inner.borrow());
  9. ctx.render(dioxus::prelude::LazyNodes::new(|nodectx| {
  10. builder::ElementBuilder::new(nodectx, "div")
  11. .child(VNode::Component(VComponent::new(Bottom, (), None)))
  12. .finish()
  13. }))
  14. };
  15. static Bottom: FC<()> = |ctx| {
  16. ctx.render(html! {
  17. <div>
  18. <h1> "bruh 1" </h1>
  19. <h1> "bruh 2" </h1>
  20. </div>
  21. })
  22. };
  23. fn Top(ctx: Context<()>) -> VNode {
  24. ctx.render(html! {
  25. <div>
  26. <h1> "bruh 1" </h1>
  27. <h1> "bruh 2" </h1>
  28. </div>
  29. })
  30. }
  31. struct Callback<T>(Box<T>);
  32. // impl<O, T: Fn() -> O> From<T> for Callback<T> {
  33. // fn from(_: T) -> Self {
  34. // todo!()
  35. // }
  36. // }
  37. impl<O, A> From<&dyn Fn(A) -> O> for Callback<&dyn Fn(A) -> O> {
  38. fn from(_: &dyn Fn(A) -> O) -> Self {
  39. todo!()
  40. }
  41. }
  42. impl<O, A, B> From<&dyn Fn(A, B) -> O> for Callback<&dyn Fn(A, B) -> O> {
  43. fn from(_: &dyn Fn(A, B) -> O) -> Self {
  44. todo!()
  45. }
  46. }
  47. // compile time reordering of arguments
  48. // Allows for transparently calling
  49. #[derive(Default)]
  50. pub struct Args<A, B, C> {
  51. pub a: CuOpt<A>,
  52. pub b: CuOpt<B>,
  53. pub c: CuOpt<C>,
  54. }
  55. pub enum CuOpt<T> {
  56. Some(T),
  57. None,
  58. }
  59. impl<T> Default for CuOpt<T> {
  60. fn default() -> Self {
  61. CuOpt::None
  62. }
  63. }
  64. impl<T> CuOpt<T> {
  65. fn unwrap(self) -> T {
  66. match self {
  67. CuOpt::Some(t) => t,
  68. CuOpt::None => panic!(""),
  69. }
  70. }
  71. }
  72. trait IsMemo {
  73. fn memo(&self, other: &Self) -> bool {
  74. false
  75. }
  76. }
  77. impl<T: PartialEq> IsMemo for CuOpt<T> {
  78. fn memo(&self, other: &Self) -> bool {
  79. self == other
  80. }
  81. }
  82. impl<T: PartialEq> PartialEq for CuOpt<T> {
  83. fn eq(&self, other: &Self) -> bool {
  84. match (self, other) {
  85. (CuOpt::Some(a), CuOpt::Some(b)) => a == b,
  86. (CuOpt::Some(_), CuOpt::None) => false,
  87. (CuOpt::None, CuOpt::Some(_)) => false,
  88. (CuOpt::None, CuOpt::None) => true,
  89. }
  90. }
  91. }
  92. impl<T> IsMemo for &CuOpt<T> {
  93. fn memo(&self, other: &Self) -> bool {
  94. false
  95. }
  96. }
  97. // #[test]
  98. #[test]
  99. fn try_test() {
  100. // test_poc()
  101. }
  102. // fn test_poc(ctx: Context) {
  103. // let b = Bump::new();
  104. // let h = Args {
  105. // a: CuOpt::Some("ASD"),
  106. // b: CuOpt::Some(123),
  107. // c: CuOpt::Some(|| {}),
  108. // // c: CuOpt::Some(b.alloc(|| {})),
  109. // // c: CuOpt::Some(Box::new(|| {}) as Box<dyn Fn()>),
  110. // };
  111. // let h2 = Args {
  112. // a: CuOpt::Some("ASD"),
  113. // b: CuOpt::Some(123),
  114. // c: CuOpt::Some(|| {}),
  115. // // c: CuOpt::Some(b.alloc(|| {})),
  116. // // c: CuOpt::Some(Box::new(|| {}) as Box<dyn Fn()>),
  117. // // c: CuOpt::Some(Box::new(|| {}) as Box<dyn Fn()>),
  118. // // c: CuOpt::Some(Box::new(|| {}) as Box<dyn Fn()>),
  119. // };
  120. // // dbg!((&h.a).memo((&&h2.a)));
  121. // // dbg!((&h.b).memo((&&h2.b)));
  122. // // dbg!((&h.c).memo((&&h2.c)));
  123. // //
  124. // // ctx: Context
  125. // Top(ctx, &h.a.unwrap(), &h.b.unwrap(), &h.c.unwrap());
  126. // }
  127. // fn test_realzies() {
  128. // let h = Args {
  129. // a: CuOpt::Some("ASD"),
  130. // b: CuOpt::Some(123),
  131. // c: CuOpt::Some(|| {}),
  132. // };
  133. // let g = |ctx: Context| {
  134. // //
  135. // Top(ctx, &h.a.unwrap(), &h.b.unwrap(), &h.c.unwrap())
  136. // };
  137. // }