syntax2.rs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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::{annotate_lazy, 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. let b = cx.bump();
  203. let node: &'a VNode<'a> = b.alloc(node);
  204. let children = ChildList { pthru: node };
  205. // let c = VComponent {
  206. // key: todo!(),
  207. // associated_scope: todo!(),
  208. // is_static: todo!(),
  209. // user_fc: todo!(),
  210. // caller: todo!(),
  211. // children: todo!(),
  212. // comparator: todo!(),
  213. // drop_props: todo!(),
  214. // can_memoize: todo!(),
  215. // raw_props: todo!(),
  216. // };
  217. // Vcomp
  218. // - borrowed
  219. // - memoized
  220. // cx.render({
  221. // NodeFactory::annotate_lazy(move |__cx: NodeFactory| -> VNode {
  222. // use dioxus_elements::{GlobalAttributes, SvgAttributes};
  223. // __cx.element(
  224. // dioxus_elements::div,
  225. // [],
  226. // [],
  227. // [
  228. // __cx.component(ChildrenMemo, (), None, []),
  229. // __cx.component(
  230. // ChildrenComp,
  231. // //
  232. // ChildrenTest { node: children },
  233. // None,
  234. // [],
  235. // ),
  236. // // {
  237. // // let _props: &_ = __cx.bump().alloc(ChildrenTest { node: children });
  238. // // __cx.component_v2_borrowed(
  239. // // //
  240. // // move |c| ChildrenComp((c, _props)),
  241. // // ChildrenComp,
  242. // // _props,
  243. // // )
  244. // // },
  245. // // {
  246. // // let _props: &_ = __cx.bump().alloc(());
  247. // // __cx.component_v2_borrowed(move |c| ChildrenMemo((c, _props)))
  248. // // },
  249. // ],
  250. // None,
  251. // )
  252. // })
  253. // })
  254. cx.render(rsx! {
  255. div {
  256. ChildrenComp {
  257. ..ChildrenTest {
  258. node: children,
  259. }
  260. }
  261. }
  262. })
  263. }
  264. #[derive(Props)]
  265. struct ChildrenTest<'a> {
  266. node: ChildList<'a>,
  267. }
  268. struct ChildList<'a> {
  269. pthru: &'a VNode<'a>,
  270. }
  271. impl<'a> Clone for ChildList<'a> {
  272. fn clone(&self) -> Self {
  273. Self { pthru: self.pthru }
  274. }
  275. }
  276. impl<'a> Copy for ChildList<'a> {}
  277. impl<'a> IntoVNode<'a> for ChildList<'a> {
  278. fn into_vnode(self, _: NodeFactory<'a>) -> VNode<'a> {
  279. match self.pthru {
  280. VNode::Text(f) => VNode::Text(*f),
  281. VNode::Element(e) => VNode::Element(*e),
  282. VNode::Component(c) => VNode::Component(*c),
  283. VNode::Suspended(s) => VNode::Suspended(*s),
  284. VNode::Anchor(a) => VNode::Anchor(a),
  285. VNode::Fragment(f) => VNode::Fragment(VFragment {
  286. children: f.children,
  287. is_static: f.is_static,
  288. key: f.key,
  289. }),
  290. }
  291. }
  292. }
  293. fn ChildrenComp<'a>((cx, props): Scope<'a, ChildrenTest<'a>>) -> Element<'a> {
  294. cx.render(rsx! {
  295. div {
  296. div {
  297. // if the node's id is already assigned, then it's being passed in as a child
  298. // in these instances, we don't worry about re-checking the node?
  299. {Some(props.node)}
  300. }
  301. }
  302. })
  303. }
  304. fn ChildrenMemo((cx, props): Scope<()>) -> Element {
  305. todo!()
  306. }