-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simple counter application with functional components (#2603)
* simple counter application with functional components * clean up some comments * use the word 'function' instead of 'functional' Co-authored-by: Muhammad Hamza <muhammadhamza1311@gmail.com> * add the counter functional example package to workspace root cargo toml * add data-trunk link tag in index html * include counter functional into the examples readme file Co-authored-by: Muhammad Hamza <muhammadhamza1311@gmail.com>
- Loading branch information
Showing
6 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "counter_functional" | ||
version = "0.1.0" | ||
authors = ["Zahash <zahash.z@gmail.com>"] | ||
edition = "2021" | ||
license = "MIT OR Apache-2.0" | ||
|
||
[dependencies] | ||
yew = { path = "../../packages/yew", features = ["csr"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Counter Example | ||
|
||
A simple example of a counter which can be increased or decreased with the press of a button implemented using function components | ||
|
||
## Running | ||
|
||
Run a debug version of this application: | ||
|
||
```bash | ||
trunk serve | ||
``` | ||
|
||
Run a release version of this application: | ||
|
||
```bash | ||
trunk serve --release | ||
``` | ||
|
||
## Concepts | ||
|
||
Demonstrates the use of function components. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>Counter Function Yew</title> | ||
<link data-trunk rel="rust" /> | ||
</head> | ||
<body></body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use yew::prelude::*; | ||
|
||
#[function_component(App)] | ||
fn app() -> Html { | ||
let state = use_state(|| 0); | ||
|
||
let incr_counter = { | ||
let state = state.clone(); | ||
Callback::from(move |_| state.set(*state + 1)) | ||
}; | ||
|
||
let decr_counter = { | ||
let state = state.clone(); | ||
Callback::from(move |_| state.set(*state - 1)) | ||
}; | ||
|
||
html!( | ||
<> | ||
<p> {"current count: "} {*state} </p> | ||
<button onclick={incr_counter}> {"+"} </button> | ||
<button onclick={decr_counter}> {"-"} </button> | ||
</> | ||
) | ||
} | ||
|
||
fn main() { | ||
yew::Renderer::<App>::new().render(); | ||
} |
7377156
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yew master branch benchmarks (Lower is better)
yew-struct-keyed 01_run1k
225.8875
156.064
1.45
yew-struct-keyed 02_replace1k
224.433
188.7795
1.19
yew-struct-keyed 03_update10th1k_x16
358.3595
315.98850000000004
1.13
yew-struct-keyed 04_select1k
72.30799999999999
52.0095
1.39
yew-struct-keyed 05_swap1k
99.957
75.5505
1.32
yew-struct-keyed 06_remove-one-1k
32.537
25.5745
1.27
yew-struct-keyed 07_create10k
3262.2275
2801.632
1.16
yew-struct-keyed 08_create1k-after1k_x2
457.603
386.4065
1.18
yew-struct-keyed 09_clear1k_x8
194.5915
166.05599999999998
1.17
yew-struct-keyed 21_ready-memory
1.457233428955078
1.457233428955078
1
yew-struct-keyed 22_run-memory
1.6921844482421875
1.6921310424804688
1.00
yew-struct-keyed 23_update5-memory
1.6954841613769531
1.6968612670898438
1.00
yew-struct-keyed 24_run5-memory
1.944538116455078
1.9441375732421875
1.00
yew-struct-keyed 25_run-clear-memory
1.3269538879394531
1.3270988464355469
1.00
yew-struct-keyed 31_startup-ci
1741.4520000000002
1730.7399999999998
1.01
yew-struct-keyed 32_startup-bt
42.236
28.756
1.47
yew-struct-keyed 33_startup-mainthreadcost
314.76400000000007
237.664
1.32
yew-struct-keyed 34_startup-totalbytes
328.744140625
328.744140625
1
This comment was automatically generated by workflow using github-action-benchmark.