Fix the router and stub out a number of crates to get compiling

This commit is contained in:
Jonathan Kelley committed 2024-01-13 20:51:37 -08:00
1 parent 4c6e515da4
commit fae0b08e61
226 files changed
+1057 -1482

No files matched your search

+13 -13
View File
@@ -49,7 +49,7 @@ fn main() {
// The #[component] attribute streamlines component creation.
// It's not required, but highly recommended. For example, UpperCamelCase components will not generate a warning.
#[component]
fn App(cx: Scope) -> Element {
fn App() -> Element {
cx.render(rsx!("hello world!"))
}
```
@@ -98,7 +98,7 @@ render nodes in match statements.
```rust, ignore
#[component[
fn Example(cx: Scope) -> Element {
fn Example() -> Element {
// both of these are equivalent
cx.render(rsx!("hello world"))
@@ -112,7 +112,7 @@ elements:
```rust, ignore
#[component]
fn App(cx: Scope) -> Element {
fn App() -> Element {
let name = "dave";
cx.render(rsx!(
h1 { "Hello, {name}!" }
@@ -141,7 +141,7 @@ In Dioxus, all properties are memoized by default!
```rust, ignore
#[component]
fn App(cx: Scope) -> Element {
fn App() -> Element {
cx.render(rsx!(
Header {
title: "My App",
@@ -178,7 +178,7 @@ struct from function arguments:
```rust, ignore
#[component]
fn Header(cx: Scope, title: String, color: String) -> Element {
fn Header(title: String, color: String) -> Element {
cx.render(rsx!(
div {
background_color: "{color}"
@@ -201,7 +201,7 @@ struct HeaderProps<'a> {
}
#[component]
fn Header<'a>(cx: Scope<'a, HeaderProps<'a>>) -> Element {
fn Header(props: HeaderProps -> Element {
cx.render(rsx!(
div {
background_color: "{cx.props.color}"
@@ -243,8 +243,8 @@ use hooks to define the state and modify it from within listeners.
```rust, ignore
#[component]
fn App(cx: Scope) -> Element {
let name = use_state(cx, || "world");
fn App() -> Element {
let name = use_state(|| "world");
render!("hello {name}!")
}
@@ -264,8 +264,8 @@ order. If that order is wrong, then the hook will pick the wrong state and panic
Most hooks you'll write are simply compositions of other hooks:
```rust, ignore
fn use_username(cx: &ScopeState, id: Uuid) -> bool {
let users = use_context::<Users>(cx);
fn use_username(d: Uuid) -> bool {
let users = use_context::<Users>();
users.get(&id).map(|user| user.logged_in).ok_or(false)
}
```
@@ -273,7 +273,7 @@ fn use_username(cx: &ScopeState, id: Uuid) -> bool {
To create entirely new foundational hooks, we can use the `use_hook` method on `ScopeState`.
```rust, ignore
fn use_mut_string(cx: &ScopeState) -> &mut String {
fn use_mut_string() -> &mut String {
cx.use_hook(|_| "Hello".to_string())
}
```
@@ -292,8 +292,8 @@ fn main() {
}
#[component]
fn App(cx: Scope) -> Element {
let count = use_state(cx, || 0);
fn App() -> Element {
let count = use_state(|| 0);
cx.render(rsx!(
div { "Count: {count}" }
+26 -23
View File
@@ -25,42 +25,45 @@ criterion_group!(mbenches, create_rows);
criterion_main!(mbenches);
fn create_rows(c: &mut Criterion) {
fn app(cx: Scope) -> Element {
let mut rng = SmallRng::from_entropy();
render!(
table {
tbody {
(0..10_000_usize).map(|f| {
let label = Label::new(&mut rng);
rsx!( Row { row_id: f, label: label } )
})
}
}
)
}
c.bench_function("create rows", |b| {
let mut dom = VirtualDom::new(app);
let _ = dom.rebuild(&mut dioxus_core::NoOpMutations);
b.iter(|| {
let g = dom.rebuild();
let g = dom.rebuild(&mut ());
assert!(g.edits.len() > 1);
})
});
}
#[derive(PartialEq, Props)]
fn app() -> Element {
let mut rng = SmallRng::from_entropy();
rsx! (
table {
tbody {
for f in 0..10_000_usize {
table_row {
row_id: f,
label: Label::new(&mut rng)
}
}
}
}
)
}
#[derive(PartialEq, Props, Clone, Copy)]
struct RowProps {
row_id: usize,
label: Label,
}
fn Row(cx: Scope<RowProps>) -> Element {
let [adj, col, noun] = cx.props.label.0;
cx.render(rsx! {
fn table_row(props: RowProps) -> Element {
let [adj, col, noun] = props.label.0;
rsx! {
tr {
td { class:"col-md-1", "{cx.props.row_id}" }
td { class:"col-md-1", "{props.row_id}" }
td { class:"col-md-1", onclick: move |_| { /* run onselect */ },
a { class: "lbl", "{adj}" "{col}" "{noun}" }
}
@@ -71,10 +74,10 @@ fn Row(cx: Scope<RowProps>) -> Element {
}
td { class: "col-md-6" }
}
})
}
}
#[derive(PartialEq)]
#[derive(PartialEq, Clone, Copy)]
struct Label([&'static str; 3]);
impl Label {
-103
View File
@@ -1,103 +0,0 @@
use dioxus::prelude::*;
use rand::prelude::*;
fn main() {
let mut dom = VirtualDom::new(app);
_ = dom.rebuild(&mut dioxus_core::NoOpMutations);
for _ in 0..1000 {
_ = dom.rebuild(&mut dioxus_core::NoOpMutations);
}
}
fn app(cx: Scope) -> Element {
let mut rng = SmallRng::from_entropy();
cx.render(rsx! (
table {
tbody {
for f in 0..10_000_usize {
table_row {
row_id: f,
label: Label::new(&mut rng)
}
}
}
}
))
}
#[derive(PartialEq, Props)]
struct RowProps {
row_id: usize,
label: Label,
}
fn table_row(cx: Scope<RowProps>) -> Element {
let [adj, col, noun] = cx.props.label.0;
cx.render(rsx! {
tr {
td { class:"col-md-1", "{cx.props.row_id}" }
td { class:"col-md-1", onclick: move |_| { /* run onselect */ },
a { class: "lbl", "{adj}" "{col}" "{noun}" }
}
td { class: "col-md-1",
a { class: "remove", onclick: move |_| {/* remove */},
span { class: "glyphicon glyphicon-remove remove", aria_hidden: "true" }
}
}
td { class: "col-md-6" }
}
})
}
#[derive(PartialEq)]
struct Label([&'static str; 3]);
impl Label {
fn new(rng: &mut SmallRng) -> Self {
Label([
ADJECTIVES.choose(rng).unwrap(),
COLOURS.choose(rng).unwrap(),
NOUNS.choose(rng).unwrap(),
])
}
}
static ADJECTIVES: &[&str] = &[
"pretty",
"large",
"big",
"small",
"tall",
"short",
"long",
"handsome",
"plain",
"quaint",
"clean",
"elegant",
"easy",
"angry",
"crazy",
"helpful",
"mushy",
"odd",
"unsightly",
"adorable",
"important",
"inexpensive",
"cheap",
"expensive",
"fancy",
];
static COLOURS: &[&str] = &[
"red", "yellow", "blue", "green", "pink", "brown", "purple", "brown", "white", "black",
"orange",
];
static NOUNS: &[&str] = &[
"table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger",
"pizza", "mouse", "keyboard",
];