syntax2.rs 5.0 KB

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