Skip to content

Commit 2412a68

Browse files
ranilemc1098
and
mc1098
authored
Refactor and cleanup codebase (yewstack#1842)
* remove yew-dsl * remove yew-components * remove yew-services * remove yew::format * fix CI * move yew::agent to yew-agent crate * move yew-functional to yew plus a couple of misc fixes * move futures and neqassign out of yewtil * move yewtil::store to yew_agent, remove yewtil * formatting * fix tests * update docs * use `rustwasm` gloo repo instead of mine * add docs * use rustwasm/gloo repo * remove unused file * fix Makefile.toml * Fix issues after rebase * Apply suggestions from code review (part 1) Co-authored-by: mc1098 <m.cripps1@uni.brighton.ac.uk> * Apply suggestions from code review (part 2) * move `#[function_component(_)]` tests missed those before * Apply suggestions from code review Co-authored-by: mc1098 <m.cripps1@uni.brighton.ac.uk> Co-authored-by: mc1098 <m.cripps1@uni.brighton.ac.uk>
1 parent 91ab14b commit 2412a68

File tree

208 files changed

+551
-7912
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

208 files changed

+551
-7912
lines changed

.github/workflows/pull-request.yml

+1-30
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ jobs:
4141
command: clippy
4242
args: --all-targets -- -D warnings
4343

44-
- name: Run clippy - yew with all features
45-
if: always()
46-
run: |
47-
cd packages/yew
48-
cargo clippy --all-targets --features "cbor msgpack toml yaml" -- -D warnings
49-
5044
check_examples:
5145
name: Check Examples
5246
runs-on: ubuntu-latest
@@ -110,20 +104,11 @@ jobs:
110104
- name: Run doctest - yew with features
111105
run: |
112106
cd packages/yew
113-
cargo test --doc --features "doc_test wasm_test yaml msgpack cbor toml"
107+
cargo test --doc --features "doc_test wasm_test"
114108
115109
integration_tests:
116110
name: Integration Tests on ${{ matrix.toolchain }}
117111
runs-on: ubuntu-latest
118-
services:
119-
httpbin:
120-
image: kennethreitz/httpbin@sha256:599fe5e5073102dbb0ee3dbb65f049dab44fa9fc251f6835c9990f8fb196a72b
121-
ports:
122-
- 8080:80
123-
echo_server:
124-
image: jmalloc/echo-server@sha256:c461e7e54d947a8777413aaf9c624b4ad1f1bac5d8272475da859ae82c1abd7d
125-
ports:
126-
- 8081:8080
127112

128113
strategy:
129114
matrix:
@@ -163,20 +148,6 @@ jobs:
163148
cd packages/yew-router
164149
wasm-pack test --chrome --firefox --headless
165150
166-
- name: Run tests - yew-functional
167-
run: |
168-
cd packages/yew-functional
169-
wasm-pack test --chrome --firefox --headless
170-
171-
- name: Run tests - yew-services
172-
env:
173-
HTTPBIN_URL: "http://localhost:8080"
174-
ECHO_SERVER_URL: "ws://localhost:8081"
175-
run: |
176-
cd packages/yew-services
177-
wasm-pack test --chrome --firefox --headless -- --features "wasm_test httpbin_test echo_server_test"
178-
179-
180151
unit_tests:
181152
name: Unit Tests on ${{ matrix.toolchain }}
182153
runs-on: ubuntu-latest

Cargo.toml

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,18 @@
11
[workspace]
22
members = [
33
"packages/yew",
4-
"packages/yew-components",
54
"packages/yew-macro",
6-
"packages/yew-services",
75
"packages/yew-validation",
6+
"packages/yew-agent",
87

98
# Router
109
"packages/yew-router",
1110
"packages/yew-router-macro",
1211

13-
# Function components
14-
"packages/yew-functional",
15-
"packages/yew-functional-macro",
16-
17-
# Utilities
18-
"packages/yewtil",
19-
"packages/yewtil-macro",
20-
21-
# dsl
22-
"packages/yew-dsl",
23-
2412
# Examples
2513
"examples/boids",
2614
"examples/counter",
2715
"examples/crm",
28-
"examples/dashboard",
2916
"examples/dyn_create_destroy_apps",
3017
"examples/file_upload",
3118
"examples/futures",

examples/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ As an example, check out the TodoMVC example here: <https://examples.yew.rs/todo
3131
| [boids](boids) | Yew port of [Boids](https://en.wikipedia.org/wiki/Boids) |
3232
| [counter](counter) | Simple counter which can be incremented and decremented |
3333
| [crm](crm) | Shallow customer relationship management tool |
34-
| [dashboard](dashboard) | Uses the `fetch` and `websocket` services to load external data |
3534
| [dyn_create_destroy_apps](dyn_create_destroy_apps) | Uses the function `start_app_in_element` and the `AppHandle` struct to dynamically create and delete Yew apps |
36-
| [file_upload](file_upload) | Uses the `reader` service to read the content of user uploaded files |
35+
| [file_upload](file_upload) | Uses the `gloo::file` to read the content of user uploaded files |
3736
| [futures](futures) | Demonstrates how you can use futures and async code with Yew. Features a Markdown renderer. |
3837
| [game_of_life](game_of_life) | Implementation of [Conway's Game of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) |
3938
| [inner_html](inner_html) | Embeds an external document as raw HTML by manually managing the element |

examples/boids/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ getrandom = { version = "0.2", features = ["js"] }
1212
rand = "0.8"
1313
serde = { version = "1.0", features = ["derive"] }
1414
yew = { path = "../../packages/yew" }
15-
yew-services = { path = "../../packages/yew-services" }
15+
gloo = { git = "https://github.com/rustwasm/gloo/" }

examples/boids/README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,15 @@ trunk serve --release
1717

1818
## Concepts
1919

20-
The example uses [`IntervalService`] to drive the game loop.
20+
The example uses [`gloo::timers`](https://gloo-rs.web.app/docs/timer) implementation of `setInterval` to drive the Yew game loop.
2121

2222
## Improvements
2323

2424
- Add the possibility to switch the behaviour from flocking to scattering by inverting the cohesion rule so that boids avoid each other.
2525
This should also invert the color adaption to restore some variety.
26-
- Add keyboard shortcuts (using the `KeyboardService`) for the actions.
26+
- Add keyboard shortcuts for the actions.
2727
- Make it possible to hide the settings panel entirely
2828
- Bigger boids should accelerate slower than smaller ones
2929
- Share settings by encoding them into the URL
3030
- Resize the boids when "Spacing" is changed.
3131
The setting should then also be renamed to something like "Size".
32-
33-
[`intervalservice`]: https://docs.rs/yew-services/latest/yew_services/struct.IntervalService.html

examples/boids/src/settings.rs

+4-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1+
use gloo::storage::{LocalStorage, Storage};
12
use serde::{Deserialize, Serialize};
2-
use yew::format::Json;
3-
use yew_services::storage::{Area, StorageService};
43

54
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
65
pub struct Settings {
@@ -31,27 +30,15 @@ impl Settings {
3130
const KEY: &'static str = "yew.boids.settings";
3231

3332
pub fn load() -> Self {
34-
StorageService::new(Area::Local)
35-
.ok()
36-
.and_then(|storage| {
37-
storage
38-
.restore::<Json<anyhow::Result<Settings>>>(Self::KEY)
39-
.0
40-
.ok()
41-
})
42-
.unwrap_or_default()
33+
LocalStorage::get(Self::KEY).unwrap_or_default()
4334
}
4435

4536
pub fn remove() {
46-
if let Ok(mut storage) = StorageService::new(Area::Local) {
47-
storage.remove(Self::KEY);
48-
}
37+
LocalStorage::delete(Self::KEY);
4938
}
5039

5140
pub fn store(&self) {
52-
if let Ok(mut storage) = StorageService::new(Area::Local) {
53-
storage.store(Self::KEY, Json(self))
54-
}
41+
let _ = LocalStorage::set(Self::KEY, self);
5542
}
5643
}
5744
impl Default for Settings {

examples/boids/src/simulation.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use crate::boid::Boid;
22
use crate::math::Vector2D;
33
use crate::settings::Settings;
4-
use std::time::Duration;
4+
use gloo::timers::callback::Interval;
55
use yew::{html, Component, ComponentLink, Html, Properties, ShouldRender};
6-
use yew_services::interval::{IntervalService, IntervalTask};
76

87
pub const SIZE: Vector2D = Vector2D::new(1600.0, 1000.0);
98

@@ -26,7 +25,7 @@ pub struct Simulation {
2625
props: Props,
2726
link: ComponentLink<Self>,
2827
boids: Vec<Boid>,
29-
interval_task: IntervalTask,
28+
interval: Interval,
3029
}
3130
impl Component for Simulation {
3231
type Message = Msg;
@@ -38,16 +37,18 @@ impl Component for Simulation {
3837
.map(|_| Boid::new_random(settings))
3938
.collect();
4039

41-
let interval_task = IntervalService::spawn(
42-
Duration::from_millis(settings.tick_interval_ms),
43-
link.callback(|_| Msg::Tick),
44-
);
40+
let interval = {
41+
let link = link.clone();
42+
Interval::new(settings.tick_interval_ms as u32, move || {
43+
link.send_message(Msg::Tick)
44+
})
45+
};
4546

4647
Self {
4748
props,
4849
link,
4950
boids,
50-
interval_task,
51+
interval,
5152
}
5253
}
5354

@@ -86,10 +87,12 @@ impl Component for Simulation {
8687
if settings.tick_interval_ms != self.props.settings.tick_interval_ms {
8788
// as soon as the previous task is dropped it is cancelled.
8889
// We don't need to worry about manually stopping it.
89-
self.interval_task = IntervalService::spawn(
90-
Duration::from_millis(settings.tick_interval_ms),
91-
self.link.callback(|_| Msg::Tick),
92-
);
90+
self.interval = {
91+
let link = self.link.clone();
92+
Interval::new(settings.tick_interval_ms as u32, move || {
93+
link.send_message(Msg::Tick)
94+
})
95+
}
9396
}
9497

9598
self.props = props;

examples/counter/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ license = "MIT OR Apache-2.0"
88
[dependencies]
99
js-sys = "0.3"
1010
yew = { path = "../../packages/yew" }
11-
yew-services = { path = "../../packages/yew-services" }
11+
weblog = "0.3"
12+
wasm-bindgen = "0.2"

examples/counter/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use js_sys::Date;
2+
use weblog::console_log;
23
use yew::{html, Component, ComponentLink, Html, ShouldRender};
3-
use yew_services::ConsoleService;
44

55
// Define the possible messages which can be sent to the component
66
pub enum Msg {
@@ -25,12 +25,12 @@ impl Component for Model {
2525
match msg {
2626
Msg::Increment => {
2727
self.value += 1;
28-
ConsoleService::log("plus one"); // Will output a string to the browser console
28+
console_log!("plus one"); // Will output a string to the browser console
2929
true // Return true to cause the displayed change to update
3030
}
3131
Msg::Decrement => {
3232
self.value -= 1;
33-
ConsoleService::log("minus one");
33+
console_log!("minus one");
3434
true
3535
}
3636
}

examples/crm/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ license = "MIT OR Apache-2.0"
99
serde = "1"
1010
serde_derive = "1"
1111
yew = { path = "../../packages/yew" }
12-
yew-services = { path = "../../packages/yew-services" }
12+
gloo = { git = "https://github.com/rustwasm/gloo/" }
13+

examples/crm/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ For a much more sophisticated approach check out [`yew-router`](https://yew.rs/c
1414
One major flaw with the implementation used by this example is that the scenes aren't tied to the URL.
1515
Reloading the page always brings the user back to the initial scene.
1616

17-
The example also uses the [`StorageService`](https://docs.rs/yew-services/latest/yew_services/struct.StorageService.html)
17+
The example also uses the [`gloo::storage`](https://gloo-rs.web.app/docs/storage)
1818
to persist the clients across sessions.
1919

2020
## Improvements

examples/crm/src/main.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use add_client::AddClientForm;
2+
use gloo::storage::{LocalStorage, Storage};
23
use serde::{Deserialize, Serialize};
3-
use yew::format::Json;
44
use yew::{html, Component, ComponentLink, Html, ShouldRender};
5-
use yew_services::storage::Area;
6-
use yew_services::{DialogService, StorageService};
75

86
mod add_client;
97

@@ -46,7 +44,6 @@ pub enum Msg {
4644

4745
pub struct Model {
4846
link: ComponentLink<Self>,
49-
storage: StorageService,
5047
clients: Vec<Client>,
5148
scene: Scene,
5249
}
@@ -56,12 +53,9 @@ impl Component for Model {
5653
type Properties = ();
5754

5855
fn create(_props: Self::Properties, link: ComponentLink<Self>) -> Self {
59-
let storage = StorageService::new(Area::Local).expect("storage was disabled by the user");
60-
let Json(clients) = storage.restore(KEY);
61-
let clients = clients.ok().unwrap_or_else(Vec::new);
56+
let clients = LocalStorage::get(KEY).unwrap_or_else(|_| Vec::new());
6257
Self {
6358
link,
64-
storage,
6559
clients,
6660
scene: Scene::ClientsList,
6761
}
@@ -75,14 +69,14 @@ impl Component for Model {
7569
}
7670
Msg::AddClient(client) => {
7771
self.clients.push(client);
78-
self.storage.store(KEY, Json(&self.clients));
72+
LocalStorage::set(KEY, &self.clients).expect("failed to set");
7973
// we only need to re-render if we're currently displaying the clients
8074
matches!(self.scene, Scene::ClientsList)
8175
}
8276
Msg::ClearClients => {
83-
if DialogService::confirm("Do you really want to clear the data?") {
77+
if gloo::dialogs::confirm("Do you really want to clear the data?") {
8478
self.clients.clear();
85-
self.storage.remove(KEY);
79+
LocalStorage::delete(KEY);
8680
true
8781
} else {
8882
false

examples/dashboard/Cargo.toml

-13
This file was deleted.

examples/dashboard/README.md

-31
This file was deleted.

examples/dashboard/index.html

-12
This file was deleted.

examples/dashboard/server/Cargo.toml

-11
This file was deleted.

0 commit comments

Comments
 (0)