Skip to content

Commit a85b8c4

Browse files
committed
wip: apply formatting
1 parent df8bb61 commit a85b8c4

File tree

5 files changed

+36
-41
lines changed

5 files changed

+36
-41
lines changed

Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,15 @@ core = []
4646
futures = "0.3.15"
4747
log = "0.4.14"
4848
num-format = "0.4.0"
49-
rand = "0.8.4"
5049
separator = "0.4.1"
5150
serde = { version = "1.0.126", features = ["derive"] }
5251
surf = "2.2.0"
5352
env_logger = "*"
5453
async-std = { version = "1.9.0", features = ["attributes"] }
54+
im-rc = "15.0.0"
55+
rand = { version = "0.8.4", features = ["small_rng"] }
56+
fxhash = "0.2.1"
57+
5558

5659
[workspace]
5760
members = [

examples/_examples/framework_benchmark.rs renamed to examples/framework_benchmark.rs

+32-34
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,45 @@
66
//!
77
//!
88
9-
use std::rc::Rc;
10-
11-
use dioxus::events::on::MouseEvent;
12-
use dioxus_core as dioxus;
13-
use dioxus_core::prelude::*;
14-
use dioxus_web::WebsysRenderer;
9+
use dioxus::{events::on::MouseEvent, prelude::*};
1510
use dioxus_html as dioxus_elements;
16-
17-
11+
use fxhash::{FxBuildHasher, FxHasher32};
12+
use std::rc::Rc;
1813

1914
fn main() {
20-
wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
21-
console_error_panic_hook::set_once();
2215
log::debug!("starting!");
23-
wasm_bindgen_futures::spawn_local(WebsysRenderer::start(App));
16+
dioxus::desktop::launch(App, |c| c);
2417
}
2518

2619
// We use a special immutable hashmap to make hashmap operations efficient
2720
type RowList = im_rc::HashMap<usize, Rc<str>, FxBuildHasher>;
28-
// type RowList = im_rc::HashMap<usize, Rc<str>, nohash_hasher::BuildNoHashHasher<usize>>;
2921

3022
static App: FC<()> = |cx| {
31-
let (items, set_items) = use_state_classic(cx, || RowList::default());
32-
let (selection, set_selection) = use_state_classic(cx, || None as Option<usize>);
23+
let items = use_state(cx, || RowList::default());
3324

34-
let create_rendered_rows = move |from, num| move |_| set_items(create_row_list(from, num));
25+
let create_rendered_rows = move |from, num| move |_| items.set(create_row_list(from, num));
3526

3627
let append_1_000_rows =
37-
move |_| set_items(create_row_list(items.len(), 1000).union(items.clone()));
28+
move |_| items.set(create_row_list(items.len(), 1000).union((*items).clone()));
3829

3930
let update_every_10th_row = move |_| {
40-
let mut new_items = items.clone();
31+
let mut new_items = (*items).clone();
4132
let mut small_rng = SmallRng::from_entropy();
42-
new_items
43-
.iter_mut()
44-
.step_by(10)
45-
.for_each(|(_, val)| *val = create_new_row_label(&mut small_rng));
46-
set_items(new_items);
33+
new_items.iter_mut().step_by(10).for_each(|(_, val)| {
34+
*val = create_new_row_label(&mut String::with_capacity(30), &mut small_rng)
35+
});
36+
items.set(new_items);
4737
};
48-
let clear_rows = move |_| set_items(RowList::default());
38+
let clear_rows = move |_| items.set(RowList::default());
4939

5040
let swap_rows = move |_| {
5141
// this looks a bit ugly because we're using a hashmap instead of a vec
5242
if items.len() > 998 {
53-
let mut new_items = items.clone();
43+
let mut new_items = (*items).clone();
5444
let a = new_items.get(&0).unwrap().clone();
5545
*new_items.get_mut(&0).unwrap() = new_items.get(&998).unwrap().clone();
5646
*new_items.get_mut(&998).unwrap() = a;
57-
set_items(new_items);
47+
items.set(new_items);
5848
}
5949
};
6050

@@ -83,7 +73,7 @@ static App: FC<()> = |cx| {
8373
}
8474
}
8575
}
86-
table {
76+
table {
8777
tbody {
8878
{rows}
8979
}
@@ -93,23 +83,28 @@ static App: FC<()> = |cx| {
9383
})
9484
};
9585

86+
#[derive(Clone)]
87+
struct RowController {}
88+
9689
#[derive(Props)]
9790
struct ActionButtonProps<F: Fn(MouseEvent)> {
9891
name: &'static str,
9992
id: &'static str,
10093
action: F,
10194
}
102-
fn ActionButton<F: Fn(MouseEvent)>(cx: Context<ActionButtonProps<F>>) -> VNode {
95+
fn ActionButton<F>(cx: Context<ActionButtonProps<F>>) -> VNode
96+
where
97+
F: Fn(MouseEvent),
98+
{
10399
cx.render(rsx! {
104100
div { class: "col-sm-6 smallpad"
105-
button {class:"btn btn-primary btn-block", r#type: "button", id: "{cx.id}", onclick: {&cx.action},
101+
button { class:"btn btn-primary btn-block", r#type: "button", id: "{cx.id}", onclick: {&cx.action},
106102
"{cx.name}"
107103
}
108104
}
109105
})
110106
}
111107

112-
113108
#[derive(PartialEq, Props)]
114109
struct RowProps {
115110
row_id: usize,
@@ -132,22 +127,25 @@ fn Row<'a>(cx: Context<'a, RowProps>) -> VNode {
132127
})
133128
}
134129

135-
use fxhash::{FxBuildHasher, FxHasher32};
136130
use rand::prelude::*;
137-
fn create_new_row_label(rng: &mut SmallRng) -> Rc<str> {
138-
let mut label = String::new();
131+
fn create_new_row_label(label: &mut String, rng: &mut SmallRng) -> Rc<str> {
139132
label.push_str(ADJECTIVES.choose(rng).unwrap());
140133
label.push(' ');
141134
label.push_str(COLOURS.choose(rng).unwrap());
142135
label.push(' ');
143136
label.push_str(NOUNS.choose(rng).unwrap());
144-
Rc::from(label)
137+
Rc::from(label.as_ref())
145138
}
146139

147140
fn create_row_list(from: usize, num: usize) -> RowList {
148141
let mut small_rng = SmallRng::from_entropy();
142+
let mut buf = String::with_capacity(35);
149143
(from..num + from)
150-
.map(|f| (f, create_new_row_label(&mut small_rng)))
144+
.map(|f| {
145+
let o = (f, create_new_row_label(&mut buf, &mut small_rng));
146+
buf.clear();
147+
o
148+
})
151149
.collect::<RowList>()
152150
}
153151

examples/rsx_usage.rs

-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ static Example: FC<()> = |cx| {
100100
// Using an "ID" associated with your data is a good idea.
101101
data.into_iter().map(|(k, v)| rsx!(li { key: "{k}" "{v}" }))
102102
}}
103-
104103

105104
// Matching
106105
// Matching will throw a Rust error about "no two closures are the same type"
@@ -147,7 +146,6 @@ static Example: FC<()> = |cx| {
147146
}
148147
}
149148
}
150-
151149

152150
// Components
153151
// Can accept any paths

packages/core-macro/examples/fc.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
2-
31
fn main() {}

packages/core-macro/examples/rsxt.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
pub mod dioxus {
42
pub mod builder {
53
pub struct Builder;

0 commit comments

Comments
 (0)