1
0

jsframework.rs 2.5 KB

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