jsframework.rs 2.5 KB

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