Skip to content

Commit e42a4c0

Browse files
committed
Merge branch 'bump-leptos-0.5.0' of https://github.com/birkskyum/js-framework-benchmark into birkskyum-bump-leptos-0.5.0
2 parents c5d82f5 + ab85696 commit e42a4c0

File tree

10 files changed

+480
-193
lines changed

10 files changed

+480
-193
lines changed

frameworks/keyed/leptos/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ wasm-bindgen = { version = "0.2", features = ["enable-interning"] }
1212
console_error_panic_hook = "0.1"
1313
getrandom = { version = "0.2.7", features = ["js"] }
1414
rand = { version = "0.8.5", features = ["small_rng"] }
15-
leptos = { version = "0.4.4", features = ["csr", "nightly", "template_macro"] }
15+
leptos = { version = "0.5.0", features = ["csr", "nightly", "template_macro"] }
1616
web-sys = "0.3"
1717

1818
[profile.release]

frameworks/keyed/leptos/bundled-dist/js-framework-benchmark-leptos.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

frameworks/keyed/leptos/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
"description": "Benchmark for Leptos",
55
"license": "ISC",
66
"js-framework-benchmark": {
7-
"frameworkVersion": "0.4.1",
7+
"frameworkVersion": "0.5.0",
88
"frameworkHomeURL": "https://github.com/leptos-rs/leptos",
99
"issues": [
1010
1139
1111
]
1212
},
1313
"scripts": {
1414
"build-prod": "echo This is a no-op. && echo Due to heavy dependencies, the generated javascript is already provided. && echo If you really want to rebuild from source use: && echo npm run build-prod-force",
15-
"build-prod-quick": "rimraf bundled-dist && wasm-pack build --release --target web --no-typescript --out-name js-framework-benchmark-leptos --out-dir bundled-dist && cpr index.html bundled-dist/index.html && (cd bundled-dist && rimraf .gitignore README.md package.json)",
16-
"build-prod-force": "rustup target add wasm32-unknown-unknown && cargo install --force wasm-pack && rimraf bundled-dist && wasm-pack build --release --target web --no-typescript --out-name js-framework-benchmark-leptos --out-dir bundled-dist && cpr index.html bundled-dist/index.html && (cd bundled-dist && rimraf .gitignore README.md package.json)"
15+
"build-prod-quick": "rimraf bundled-dist && wasm-pack build --release --target web --no-typescript --out-name js-framework-benchmark-leptos --out-dir bundled-dist && cpr index.html bundled-dist/index.html && cd bundled-dist && esbuild --minify js-framework-benchmark-leptos.js > js-framework-benchmark-leptos.min.js && mv js-framework-benchmark-leptos.min.js js-framework-benchmark-leptos.js && rimraf .gitignore README.md package.json",
16+
"build-prod-force": "rustup target add wasm32-unknown-unknown && cargo install --force wasm-pack && rimraf bundled-dist && wasm-pack build --release --target web --no-typescript --out-name js-framework-benchmark-leptos --out-dir bundled-dist && cpr index.html bundled-dist/index.html && (cd bundled-dist && esbuild --minify js-framework-benchmark-leptos.js > js-framework-benchmark-leptos.min.js && mv js-framework-benchmark-leptos.min.js js-framework-benchmark-leptos.js && rimraf .gitignore README.md package.json)"
1717
},
1818
"repository": {
1919
"type": "git",

frameworks/keyed/leptos/src/lib.rs

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ static ADJECTIVES: &[&str] = &[
3333
];
3434

3535
static COLOURS: &[&str] = &[
36-
"red", "yellow", "blue", "green", "pink", "brown", "purple", "brown", "white", "black",
37-
"orange",
36+
"red", "yellow", "blue", "green", "pink", "brown", "purple", "brown",
37+
"white", "black", "orange",
3838
];
3939

4040
static NOUNS: &[&str] = &[
41-
"table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger",
42-
"pizza", "mouse", "keyboard",
41+
"table", "chair", "house", "bbq", "desk", "car", "pony", "cookie",
42+
"sandwich", "burger", "pizza", "mouse", "keyboard",
4343
];
4444

4545
#[derive(Copy, Debug, Clone, PartialEq, Eq, Hash)]
@@ -50,7 +50,7 @@ struct RowData {
5050

5151
static ID_COUNTER: AtomicUsize = AtomicUsize::new(1);
5252

53-
fn build_data(cx: Scope, count: usize) -> Vec<RowData> {
53+
fn build_data(count: usize) -> Vec<RowData> {
5454
let mut thread_rng = thread_rng();
5555

5656
let mut data = Vec::new();
@@ -70,10 +70,11 @@ fn build_data(cx: Scope, count: usize) -> Vec<RowData> {
7070

7171
data.push(RowData {
7272
id: ID_COUNTER.load(Ordering::Relaxed),
73-
label: create_signal(cx, label),
73+
label: create_signal(label),
7474
});
7575

76-
ID_COUNTER.store(ID_COUNTER.load(Ordering::Relaxed) + 1, Ordering::Relaxed);
76+
ID_COUNTER
77+
.store(ID_COUNTER.load(Ordering::Relaxed) + 1, Ordering::Relaxed);
7778
}
7879

7980
data
@@ -82,14 +83,13 @@ fn build_data(cx: Scope, count: usize) -> Vec<RowData> {
8283
/// Button component.
8384
#[component]
8485
fn Button(
85-
cx: Scope,
8686
/// ID for the button element
8787
id: &'static str,
8888
/// Text that should be included
8989
text: &'static str,
9090
) -> impl IntoView {
9191
view! {
92-
cx,
92+
9393
<div class="col-sm-6 smallpad">
9494
<button
9595
id=id
@@ -103,26 +103,26 @@ fn Button(
103103
}
104104

105105
#[component]
106-
fn App(cx: Scope) -> impl IntoView {
107-
let (data, set_data) = create_signal(cx, Vec::<RowData>::new());
108-
let (selected, set_selected) = create_signal(cx, None::<usize>);
106+
fn App() -> impl IntoView {
107+
let (data, set_data) = create_signal(Vec::<RowData>::new());
108+
let (selected, set_selected) = create_signal(None::<usize>);
109109

110110
let remove = move |id: usize| {
111111
set_data.update(move |data| data.retain(|row| row.id != id));
112112
};
113113

114114
let run = move |_| {
115-
set_data(build_data(cx, 1000));
115+
set_data(build_data(1000));
116116
set_selected(None);
117117
};
118118

119119
let run_lots = move |_| {
120-
set_data(build_data(cx, 10000));
120+
set_data(build_data(10000));
121121
set_selected(None);
122122
};
123123

124124
let add = move |_| {
125-
set_data.update(move |data| data.append(&mut build_data(cx, 1000)));
125+
set_data.update(move |data| data.append(&mut build_data(1000)));
126126
};
127127

128128
let update = move |_| {
@@ -146,17 +146,17 @@ fn App(cx: Scope) -> impl IntoView {
146146
});
147147
};
148148

149-
let is_selected = create_selector(cx, selected);
149+
let is_selected = create_selector(selected);
150150

151151
view! {
152-
cx,
152+
153153
<div class="container">
154154
<div class="jumbotron">
155155
<div class="row">
156156
<div class="col-md-6"><h1>"Leptos"</h1></div>
157157
<div class="col-md-6">
158158
<div class="row">
159-
<Button id="run" text="Create 1,000 rows" on:click=run/>
159+
<Button id="run" text="Create 1,000 rows" on:click=run />
160160
<Button id="runlots" text="Create 10,000 rows" on:click=run_lots />
161161
<Button id="add" text="Append 1,000 rows" on:click=add />
162162
<Button id="update" text="Update every 10th row" on:click=update />
@@ -171,16 +171,19 @@ fn App(cx: Scope) -> impl IntoView {
171171
<For
172172
each={data}
173173
key={|row| row.id}
174-
view=move |cx, row: RowData| {
174+
children=move |row: RowData| {
175175
let row_id = row.id;
176176
let (label, _) = row.label;
177-
let is_selected = is_selected.clone();
178-
on_cleanup(cx, move || {
179-
label.dispose();
177+
on_cleanup({
178+
let is_selected = is_selected.clone();
179+
move || {
180+
label.dispose();
181+
is_selected.remove(&Some(row_id));
182+
}
180183
});
184+
let is_selected = is_selected.clone();
181185
template! {
182-
cx,
183-
<tr class:danger={move || is_selected(Some(row_id))}>
186+
<tr class:danger={move || is_selected.selected(Some(row_id))}>
184187
<td class="col-md-1">{row_id.to_string()}</td>
185188
<td class="col-md-4"><a on:click=move |_| set_selected(Some(row_id))>{move || label.get()}</a></td>
186189
<td class="col-md-1"><a on:click=move |_| remove(row_id)><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td>
@@ -201,5 +204,5 @@ pub fn start() {
201204
console_error_panic_hook::set_once();
202205

203206
let root = document().query_selector("#main").unwrap().unwrap();
204-
mount_to(root.unchecked_into(), |cx| view! { cx, <App/> });
207+
mount_to(root.unchecked_into(), || view! { <App/> });
205208
}

0 commit comments

Comments
 (0)