syntax.rs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. use std::marker::PhantomData;
  2. use dioxus::component::Scope;
  3. use dioxus::events::on::MouseEvent;
  4. use dioxus::nodes::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 html_usage() {
  11. let mo = move |_| {};
  12. let r = rsx! {
  13. div {
  14. onclick: move |_| {}
  15. onmouseover: {mo}
  16. "type": "bar",
  17. "hello world"
  18. }
  19. };
  20. let items = ["bob", "bill", "jack"];
  21. let f = items
  22. .iter()
  23. .filter(|f| f.starts_with('b'))
  24. .map(|f| rsx!("hello {f}"));
  25. // let p = rsx!(div { {f} });
  26. }
  27. static App2: FC<()> = |(cx, _)| cx.render(rsx!("hello world!"));
  28. static App: FC<()> = |(cx, props)| {
  29. let name = cx.use_state(|| 0);
  30. cx.render(rsx!(div {
  31. h1 {}
  32. h2 {}
  33. }))
  34. };
  35. pub trait UseState<'a, T: 'static> {
  36. fn use_state(self, f: impl FnOnce() -> T) -> &'a T;
  37. }
  38. impl<'a, T: 'static> UseState<'a, T> for Context<'a> {
  39. fn use_state(self, f: impl FnOnce() -> T) -> &'a T {
  40. todo!()
  41. }
  42. }
  43. fn App3((cx, props): Scope<()>) -> Element {
  44. let p = rsx! {
  45. Child {
  46. bame: 10,
  47. }
  48. };
  49. todo!()
  50. // cx.render(rsx!(Child {
  51. // bame: 102,
  52. // ..ChildProps { bame: 10 }
  53. // }))
  54. }
  55. #[derive(Props, PartialEq, Debug)]
  56. struct ChildProps {
  57. bame: i32, // children: Children<'a>,
  58. }
  59. fn Child<'a>((cx, props): Scope<'a, ChildProps>) -> Element<'a> {
  60. cx.render(rsx!(div {
  61. // {props.children}
  62. }))
  63. }
  64. // Some(LazyNodes::new(|f| {
  65. // //
  66. // // let r = f.fragment_from_iter(&props.children);
  67. // r
  68. // // todo!()
  69. // }))
  70. // todo!()
  71. // rsx!({ Some(p) })
  72. // todo!()
  73. pub struct Children<'a> {
  74. children: VNode<'static>,
  75. _p: PhantomData<&'a ()>,
  76. }
  77. impl<'a> Children<'a> {
  78. pub fn new(children: VNode<'a>) -> Self {
  79. Self {
  80. children: unsafe { std::mem::transmute(children) },
  81. _p: PhantomData,
  82. }
  83. }
  84. }
  85. static Bapp: FC<()> = |(cx, props)| {
  86. let name = cx.use_state(|| 0);
  87. cx.render(rsx!(
  88. div {
  89. div {
  90. }
  91. div {
  92. }
  93. }
  94. ))
  95. };
  96. static Match: FC<()> = |(cx, props)| {
  97. //
  98. let b: Box<dyn Fn(NodeFactory) -> VNode> = Box::new(|f| todo!());
  99. let b = match "ag" {
  100. "a" => {
  101. let __b: Box<dyn FnOnce(NodeFactory) -> VNode> = Box::new(|f: NodeFactory| todo!());
  102. __b
  103. }
  104. _ => {
  105. let __b: Box<dyn FnOnce(NodeFactory) -> VNode> = Box::new(|f: NodeFactory| todo!());
  106. __b
  107. }
  108. };
  109. // let b: Box<dyn Fn(NodeFactory) -> VNode> = match "alph" {
  110. // "beta" => Box::new(|f: NodeFactory| {
  111. // //
  112. // todo!()
  113. // }),
  114. // _ => Box::new(|f: NodeFactory| {
  115. // //
  116. // todo!()
  117. // }),
  118. // };
  119. cx.render(rsx! {
  120. div {
  121. }
  122. })
  123. };