syntax2.rs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. use std::borrow::BorrowMut;
  2. use std::cell::{Cell, RefCell};
  3. use std::marker::PhantomData;
  4. use dioxus::component::Scope;
  5. use dioxus::events::on::MouseEvent;
  6. use dioxus::nodes::{IntoVNode, VComponent, VFragment, VText};
  7. use dioxus_core as dioxus;
  8. use dioxus_core::prelude::*;
  9. use dioxus_core_macro::*;
  10. use dioxus_html as dioxus_elements;
  11. fn main() {}
  12. fn t() {
  13. let g = rsx! {
  14. div {
  15. div {
  16. }
  17. }
  18. };
  19. let g = {
  20. let ___p: Box<dyn FnOnce(NodeFactory) -> VNode> = Box::new(|__cx: NodeFactory| {
  21. use dioxus_elements::{GlobalAttributes, SvgAttributes};
  22. __cx.element(dioxus_elements::div, [], [], [], None)
  23. });
  24. // let __z = ___p as ;
  25. // __z
  26. };
  27. }
  28. // #[derive(PartialEq, Props)]
  29. // struct OurProps {
  30. // foo: String,
  31. // }
  32. // fn App<'a>((cx, props): Scope<'a, OurProps>) -> Element<'a> {
  33. // let a = rsx! {
  34. // div {
  35. // "asd"
  36. // "{props.foo}"
  37. // }
  38. // };
  39. // let p = (0..10).map(|f| {
  40. // rsx! {
  41. // div {
  42. // }
  43. // }
  44. // });
  45. // let g = match "text" {
  46. // "a" => {
  47. // rsx!("asd")
  48. // }
  49. // _ => {
  50. // rsx!("asd")
  51. // }
  52. // };
  53. // let items = ["bob", "bill", "jack"];
  54. // let f = items
  55. // .iter()
  56. // .filter(|f| f.starts_with('b'))
  57. // .map(|f| rsx!("hello {f}"));
  58. // // use dioxus_hooks;
  59. // // let g = use_state(|| "hello".to_string());
  60. // let s: &'a mut String = cx.use_hook(|_| String::new(), |f| f, |_| {});
  61. // /*
  62. // the final closure is allowed to borrow anything provided it
  63. // */
  64. // // cx.render({
  65. // // let p: Option<Box<dyn FnOnce(_) -> _>> = Some(Box::new(move |__cx: NodeFactory| {
  66. // // use dioxus_elements::{GlobalAttributes, SvgAttributes};
  67. // // let props = Child2Props { foo: s };
  68. // // let ch: VNode = __cx.component(Child2, props, None, []);
  69. // // __cx.element(
  70. // // dioxus_elements::div,
  71. // // [],
  72. // // [],
  73. // // [ch],
  74. // // // [__cx.component(Child2, fc_to_builder(Child2).foo(s).build(), None, [])],
  75. // // None,
  76. // // )
  77. // // }));
  78. // // p
  79. // // // let ___p: Box<dyn FnOnce(NodeFactory) -> VNode> = Box::new(move |__cx| {
  80. // // // use dioxus_elements::{GlobalAttributes, SvgAttributes};
  81. // // // let props = Child2Props { foo: s };
  82. // // // let ch: VNode = __cx.component(Child2, props, None, []);
  83. // // // __cx.element(
  84. // // // dioxus_elements::div,
  85. // // // [],
  86. // // // [],
  87. // // // [ch],
  88. // // // // [__cx.component(Child2, fc_to_builder(Child2).foo(s).build(), None, [])],
  89. // // // None,
  90. // // // )
  91. // // // });
  92. // // // Some(___p)
  93. // // })
  94. // let a = annotate_lazy(move |f| {
  95. // //
  96. // todo!()
  97. // });
  98. // let b = annotate_lazy(move |f| {
  99. // //
  100. // f.text(format_args!("{}", props.foo))
  101. // });
  102. // let c = annotate_lazy(move |f| {
  103. // //
  104. // f.component(
  105. // Child,
  106. // OurProps {
  107. // //
  108. // foo: "hello".to_string(),
  109. // },
  110. // None,
  111. // [],
  112. // )
  113. // });
  114. // let st: &'a String = cx.use_hook(|_| "hello".to_string(), |f| f, |_| {});
  115. // let d = annotate_lazy(move |f| {
  116. // //
  117. // f.component(
  118. // Child2,
  119. // Child2Props {
  120. // //
  121. // foo: st,
  122. // },
  123. // None,
  124. // [],
  125. // )
  126. // });
  127. // let e = match "asd" {
  128. // b => {
  129. // //
  130. // annotate_lazy(move |f| {
  131. // //
  132. // f.text(format_args!("{}", props.foo))
  133. // })
  134. // }
  135. // a => {
  136. // //
  137. // annotate_lazy(move |f| {
  138. // //
  139. // f.text(format_args!("{}", props.foo))
  140. // })
  141. // }
  142. // };
  143. // cx.render(annotate_lazy(move |f| {
  144. // //
  145. // f.raw_element(
  146. // "div",
  147. // None,
  148. // [],
  149. // [],
  150. // [
  151. // //
  152. // f.fragment_from_iter(a),
  153. // f.fragment_from_iter(b),
  154. // f.fragment_from_iter(c),
  155. // f.fragment_from_iter(e),
  156. // ],
  157. // None,
  158. // )
  159. // // todo!()
  160. // }))
  161. // // cx.render(rsx! {
  162. // // div {
  163. // // div {
  164. // // {a}
  165. // // // {p}
  166. // // // {g}
  167. // // // {f}
  168. // // }
  169. // // // div {
  170. // // // "asd"
  171. // // // div {
  172. // // // "asd"
  173. // // // }
  174. // // // }
  175. // // // Child {
  176. // // // foo: "asd".to_string(),
  177. // // // }
  178. // // Child2 {
  179. // // foo: s,
  180. // // }
  181. // // }
  182. // // })
  183. // }
  184. // fn Child((cx, props): Scope<OurProps>) -> Element {
  185. // cx.render(rsx! {
  186. // div {
  187. // div {}
  188. // }
  189. // })
  190. // }
  191. #[derive(Props)]
  192. struct Child2Props<'a> {
  193. foo: &'a String,
  194. }
  195. fn Child2<'a>((cx, props): Scope<'a, Child2Props>) -> Element<'a> {
  196. let node = cx
  197. .render(rsx! {
  198. div {
  199. }
  200. })
  201. .unwrap();
  202. cx.render(rsx! {
  203. div {
  204. ChildrenComp {
  205. div {}
  206. }
  207. }
  208. })
  209. }
  210. #[derive(Props)]
  211. struct ChildrenTest<'a> {
  212. children: ScopeChildren<'a>,
  213. }
  214. fn ChildrenComp<'a>((cx, props): Scope<'a, ChildrenTest<'a>>) -> Element<'a> {
  215. cx.render(rsx! {
  216. div {
  217. div {
  218. {&props.children}
  219. }
  220. }
  221. })
  222. }
  223. fn ChildrenMemo((cx, props): Scope<()>) -> Element {
  224. todo!()
  225. }