jsframework.rs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #![allow(non_snake_case)]
  2. use dioxus::component::Scope;
  3. use dioxus::events::on::MouseEvent;
  4. use dioxus_core as dioxus;
  5. use dioxus_core::prelude::*;
  6. use dioxus_core_macro::*;
  7. use dioxus_html as dioxus_elements;
  8. use rand::prelude::*;
  9. use std::fmt::Display;
  10. fn main() {
  11. let mut dom = VirtualDom::new(App);
  12. let g = dom.rebuild();
  13. assert!(g.edits.len() > 1);
  14. }
  15. fn App((cx, props): Scope<()>) -> Element {
  16. let mut rng = SmallRng::from_entropy();
  17. let rows = (0..10_000_usize).map(|f| {
  18. let label = Label::new(&mut rng);
  19. rsx! {
  20. Row {
  21. row_id: f,
  22. label: label
  23. }
  24. }
  25. });
  26. cx.render(rsx! {
  27. table {
  28. tbody {
  29. {rows}
  30. }
  31. }
  32. })
  33. }
  34. #[derive(PartialEq, Props)]
  35. struct RowProps {
  36. row_id: usize,
  37. label: Label,
  38. }
  39. fn Row<'a>((cx, props): Scope<'a, RowProps>) -> Element<'a> {
  40. let handler = move |evt: MouseEvent| {
  41. let g = evt.button;
  42. };
  43. cx.render(rsx! {
  44. tr {
  45. // td { class:"col-md-1", "{cx.props.row_id}" }
  46. // td { class:"col-md-1", onclick: move |_| { /* run onselect */ }
  47. // a { class: "lbl", "{cx.props.label}" }
  48. // }
  49. // td { class: "col-md-1"
  50. // a { class: "remove", onclick: {handler}
  51. // span { class: "glyphicon glyphicon-remove remove" aria_hidden: "true" }
  52. // }
  53. // }
  54. // td { class: "col-md-6" }
  55. }
  56. })
  57. }
  58. #[derive(PartialEq)]
  59. struct Label([&'static str; 3]);
  60. impl Label {
  61. fn new(rng: &mut SmallRng) -> Self {
  62. Label([
  63. ADJECTIVES.choose(rng).unwrap(),
  64. COLOURS.choose(rng).unwrap(),
  65. NOUNS.choose(rng).unwrap(),
  66. ])
  67. }
  68. }
  69. impl Display for Label {
  70. fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
  71. write!(f, "{} {} {}", self.0[0], self.0[1], self.0[2])
  72. }
  73. }
  74. static ADJECTIVES: &[&str] = &[
  75. "pretty",
  76. "large",
  77. "big",
  78. "small",
  79. "tall",
  80. "short",
  81. "long",
  82. "handsome",
  83. "plain",
  84. "quaint",
  85. "clean",
  86. "elegant",
  87. "easy",
  88. "angry",
  89. "crazy",
  90. "helpful",
  91. "mushy",
  92. "odd",
  93. "unsightly",
  94. "adorable",
  95. "important",
  96. "inexpensive",
  97. "cheap",
  98. "expensive",
  99. "fancy",
  100. ];
  101. static COLOURS: &[&str] = &[
  102. "red", "yellow", "blue", "green", "pink", "brown", "purple", "brown", "white", "black",
  103. "orange",
  104. ];
  105. static NOUNS: &[&str] = &[
  106. "table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger",
  107. "pizza", "mouse", "keyboard",
  108. ];