jsframework.rs 2.4 KB

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