macrosrc.rs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // #![allow(unused, non_upper_case_globals, non_snake_case)]
  2. // use bumpalo::Bump;
  3. // use dioxus_core::nodebuilder::*;
  4. // use dioxus_core::prelude::*;
  5. // use std::{collections::HashMap, future::Future, marker::PhantomData};
  6. fn main() {}
  7. // fn main() {
  8. // let mut vdom = VirtualDom::new_with_props(
  9. // component,
  10. // Props {
  11. // blah: false,
  12. // text: "blah".into(),
  13. // },
  14. // );
  15. // vdom.progress();
  16. // let somet = String::from("asd");
  17. // let text = somet.as_str();
  18. // /*
  19. // this could be auto-generated via the macro
  20. // this props is allocated in this
  21. // but the component and props would like need to be cached
  22. // we could box this fn, abstracting away the props requirement and just keep the entrance and allocator requirement
  23. // How do we keep cached things around?
  24. // Need some sort of caching mechanism
  25. // how do we enter into a childscope from a parent scope?
  26. // Problems:
  27. // 1: Comp props need to be stored somewhere so we can re-evalute components when they receive updates
  28. // 2: Trees are not evaluated
  29. // */
  30. // let example_caller = move |ctx: &Bump| {
  31. // todo!()
  32. // // let p = Props { blah: true, text };
  33. // // let c = Context { props: &p };
  34. // // let r = component(&c);
  35. // };
  36. // // check the edit list
  37. // }
  38. // // ~~~ Text shared between components via props can be done with lifetimes! ~~~
  39. // // Super duper efficient :)
  40. // struct Props {
  41. // blah: bool,
  42. // text: String,
  43. // // text: &'src str,
  44. // }
  45. // impl Properties for Props {
  46. // fn new() -> Self {
  47. // todo!()
  48. // }
  49. // }
  50. // fn component<'a>(ctx: Context<'a, Props>) -> VNode<'a> {
  51. // // Write asynchronous rendering code that immediately returns a "suspended" VNode
  52. // // The concurrent API will then progress this component when the future finishes
  53. // // You can suspend the entire component, or just parts of it
  54. // let product_list = ctx.suspend(async {
  55. // // Suspend the rendering that completes when the future is done
  56. // match fetch_data().await {
  57. // Ok(data) => html! { <div> "success!" </div>},
  58. // Err(_) => html! { <div> "failure :(" </div>},
  59. // }
  60. // });
  61. // // todo!()
  62. // ctx.render(html! {
  63. // <div>
  64. // <h1> "Products" </h1>
  65. // <button> "hello!" </button>
  66. // // Subnodes can even be suspended
  67. // // When completely rendered, they won't cause the component itself to re-render, just their slot
  68. // // <p> { product_list } </p>
  69. // </div>
  70. // })
  71. // }
  72. // fn BuilderComp<'a>(ctx: Context<'a, Props>) -> VNode<'a> {
  73. // // VNodes can be constructed via a builder or the html! macro
  74. // // However, both of these are "lazy" - they need to be evaluated (aka, "viewed")
  75. // // We can "view" them with Context for ultimate speed while inside components
  76. // ctx.render(|bump| {
  77. // div(bump)
  78. // .attr("class", "edit")
  79. // .child(text("Hello"))
  80. // .child(text(ctx.props.text.as_ref()))
  81. // .finish()
  82. // })
  83. // }
  84. // #[fc]
  85. // fn EffcComp(ctx: Context, name: &str) -> VNode {
  86. // // VNodes can be constructed via a builder or the html! macro
  87. // // However, both of these are "lazy" - they need to be evaluated (aka, "viewed")
  88. // // We can "view" them with Context for ultimate speed while inside components
  89. // // use "phase" style allocation;
  90. // ctx.render(html! {
  91. // <div>
  92. // // your template goes here
  93. // // feel free to directly use "name"
  94. // </div>
  95. // })
  96. // }
  97. // fn FullySuspended<'a>(ctx: &'a Context<Props>) -> VNode<'a> {
  98. // ctx.suspend(async {
  99. // let i: i32 = 0;
  100. // // full suspended works great with just returning VNodes!
  101. // // Feel free to capture the html! macro directly
  102. // // Anything returned here is automatically viewed
  103. // let tex = match i {
  104. // 1 => html! { <div> </div> },
  105. // 2 => html! { <div> </div> },
  106. // _ => html! { <div> </div> },
  107. // };
  108. // if ctx.props.blah {
  109. // html! { <div> </div> }
  110. // } else {
  111. // tex
  112. // }
  113. // })
  114. // }
  115. // /// An example of a datafetching service
  116. // async fn fetch_data() -> Result<String, ()> {
  117. // todo!()
  118. // }