jsframework.rs 2.4 KB

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