Skip to content

Commit

Permalink
Move yew/services to yew-services crate (#1693)
Browse files Browse the repository at this point in the history
* move yew/services to yew-services crate

* fix stdweb examples

* remove services feature usage from workflow

* attempt at making CI pass

* remove unused feature

* add feature i missed during merge

* okay, it should compile now

* apply review

* fix yew-stdweb & aplease fmt

* misc fixes

Co-authored-by: Justin Starry <justin.starry@icloud.com>
  • Loading branch information
ranile and jstarry authored Jan 23, 2021
1 parent e5eda4e commit ab76a44
Show file tree
Hide file tree
Showing 73 changed files with 345 additions and 180 deletions.
21 changes: 12 additions & 9 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ jobs:
# To fix this we just run them on yew but with yew-stdweb's default features enabled.
cd packages/yew
cargo test --doc \
--no-default-features --features "services agent std_web" \
--no-default-features --features "agent std_web" \
--features "doc_test wasm_test yaml msgpack cbor toml"
integration_tests:
Expand Down Expand Up @@ -171,27 +171,30 @@ jobs:
cargo-${{ runner.os }}-
- name: Run tests - yew
env:
HTTPBIN_URL: "http://localhost:8080"
ECHO_SERVER_URL: "ws://localhost:8081"
run: |
cd packages/yew
wasm-pack test --chrome --firefox --headless -- --features "wasm_test httpbin_test echo_server_test"
wasm-pack test --chrome --firefox --headless -- --features "wasm_test"
- name: Run tests - yew-stdweb
if: matrix.toolchain != 'stable'
env:
HTTPBIN_URL: "http://localhost:8080"
ECHO_SERVER_URL: "ws://localhost:8081"
run: |
cd packages/yew-stdweb
wasm-pack test --chrome --firefox --headless -- --features "wasm_test httpbin_test echo_server_test"
wasm-pack test --chrome --firefox --headless -- --features "wasm_test"
- name: Run tests - yew-functional
run: |
cd packages/yew-functional
wasm-pack test --chrome --firefox --headless
- name: Run tests - yew-services
env:
HTTPBIN_URL: "http://localhost:8080"
ECHO_SERVER_URL: "ws://localhost:8081"
run: |
cd packages/yew-services
wasm-pack test --chrome --firefox --headless -- --features "wasm_test httpbin_test echo_server_test"
unit_tests:
name: Unit Tests on ${{ matrix.toolchain }}
runs-on: ubuntu-latest
Expand Down
13 changes: 5 additions & 8 deletions docs/concepts/services/fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub type Binary = Result<Vec<u8>, Error>;
Here is what a typical GET request will look like:
```rust
use yew::format::Nothing;
use yew::services::fetch::Request;
use yew_services::fetch::Request;
let get_request = Request::get("https://example.com/api/v1/get/something")
.body(Nothing)
.expect("Could not build that request");
Expand All @@ -36,7 +36,7 @@ Here is what a typical POST request will look like:
```rust
use serde_json::json;
use yew::format::Json;
use yew::services::fetch::Request;
use yew_services::fetch::Request;
let post_request = Request::post("https://example.com/api/v1/post/something")
.header("Content-Type", "application/json")
.body(Json(&json!({"key": "value"})))
Expand Down Expand Up @@ -94,11 +94,8 @@ An illustrated example of how to fetch data from an API giving information about
// requires the serde and anyhow crates

use serde::Deserialize;
use yew::{
format::{Json, Nothing},
prelude::*,
services::fetch::{FetchService, FetchTask, Request, Response},
};
use yew::{format::{Json, Nothing}, prelude::*};
use yew_services::fetch::{FetchService, FetchTask, Request, Response};

#[derive(Deserialize, Debug, Clone)]
pub struct ISSPosition {
Expand Down Expand Up @@ -241,7 +238,7 @@ The Rust Wasm Book also contains [useful debugging tips](https://rustwasm.github
for Wasm applications.

## Further reading
* [The API documentation](https://docs.rs/yew/0.14.3/yew/services/fetch/index.html)
* [The API documentation](https://docs.rs/yew-services/latest/yew_services/fetch/index.html)
* The [dashboard](https://github.com/yewstack/yew/tree/master/examples/dashboard) and
[npm_and_rest](https://github.com/yewstack/yew/tree/master/examples/web_sys/npm_and_rest) examples.
* [The Rust Wasm Book on debugging Wasm applications](https://rustwasm.github.io/book/reference/debugging.html)
5 changes: 2 additions & 3 deletions docs/more/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ fn main() {
log::info!("Update: {:?}", msg);
```

### [`ConsoleService`](https://docs.rs/yew/latest/yew/services/console/struct.ConsoleService.html)
### [`ConsoleService`](https://docs.rs/yew-services/latest/yew_services/struct.ConsoleService.html)

This service is included within Yew and is available when the "services" feature is enabled
(the "services" feature is enabled by default):
This service is included within the [`yew-services`](https://crates.io/crates/yew-services) crate:

```rust
// usage
Expand Down
1 change: 1 addition & 0 deletions examples/boids/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ getrandom = { version = "0.2", features = ["js"] }
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
yew = { path = "../../packages/yew" }
yew-services = { path = "../../packages/yew-services" }
2 changes: 1 addition & 1 deletion examples/boids/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ The example uses [`IntervalService`] to drive the game loop.
- Resize the boids when "Spacing" is changed.
The setting should then also be renamed to something like "Size".

[`intervalservice`]: https://docs.rs/yew/latest/yew/services/struct.IntervalService.html
[`intervalservice`]: https://docs.rs/yew-services/latest/yew_services/struct.IntervalService.html
2 changes: 1 addition & 1 deletion examples/boids/src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use yew::format::Json;
use yew::services::storage::{Area, StorageService};
use yew_services::storage::{Area, StorageService};

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct Settings {
Expand Down
2 changes: 1 addition & 1 deletion examples/boids/src/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::boid::Boid;
use crate::math::Vector2D;
use crate::settings::Settings;
use std::time::Duration;
use yew::services::interval::{IntervalService, IntervalTask};
use yew::{html, Component, ComponentLink, Html, Properties, ShouldRender};
use yew_services::interval::{IntervalService, IntervalTask};

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

Expand Down
1 change: 1 addition & 0 deletions examples/counter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ edition = "2018"
[dependencies]
js-sys = "0.3"
yew = { path = "../../packages/yew" }
yew-services = { path = "../../packages/yew-services" }
2 changes: 1 addition & 1 deletion examples/counter/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use js_sys::Date;
use yew::services::ConsoleService;
use yew::{html, Component, ComponentLink, Html, ShouldRender};
use yew_services::ConsoleService;

pub enum Msg {
Increment,
Expand Down
1 change: 1 addition & 0 deletions examples/crm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ edition = "2018"
serde = "1"
serde_derive = "1"
yew = { path = "../../packages/yew" }
yew-services = { path = "../../packages/yew-services" }
2 changes: 1 addition & 1 deletion examples/crm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ For a much more sophisticated approach check out [`yew-router`](https://yew.rs/d
One major flaw with the implementation used by this example is that the scenes aren't tied to the URL.
Reloading the page always brings the user back to the initial scene.

The example also uses the [`StorageService`](https://docs.rs/yew/latest/yew/services/struct.StorageService.html)
The example also uses the [`StorageService`](https://docs.rs/yew-services/latest/yew_services/struct.StorageService.html)
to persist the clients across sessions.

## Improvements
Expand Down
4 changes: 2 additions & 2 deletions examples/crm/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use add_client::AddClientForm;
use serde::{Deserialize, Serialize};
use yew::format::Json;
use yew::services::storage::Area;
use yew::services::{DialogService, StorageService};
use yew::{html, Component, ComponentLink, Html, ShouldRender};
use yew_services::storage::Area;
use yew_services::{DialogService, StorageService};

mod add_client;

Expand Down
1 change: 1 addition & 0 deletions examples/dashboard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ anyhow = "1"
serde = "1"
serde_derive = "1"
yew = { path = "../../packages/yew", features = ["toml"] }
yew-services = { path = "../../packages/yew-services" }
8 changes: 4 additions & 4 deletions examples/dashboard/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use anyhow::Error;
use serde_derive::{Deserialize, Serialize};
use yew::format::{Json, Nothing, Toml};
use yew::services::fetch::{FetchService, FetchTask, Request, Response};
use yew::services::websocket::{WebSocketService, WebSocketStatus, WebSocketTask};
use yew::{html, Component, ComponentLink, Html, ShouldRender};
use yew_services::fetch::{FetchService, FetchTask, Request, Response};
use yew_services::websocket::{WebSocketService, WebSocketStatus, WebSocketTask};

type AsBinary = bool;

Expand Down Expand Up @@ -72,7 +72,7 @@ impl Model {
}
}

fn fetch_json(&mut self, binary: AsBinary) -> yew::services::fetch::FetchTask {
fn fetch_json(&mut self, binary: AsBinary) -> yew_services::fetch::FetchTask {
let callback = self.link.batch_callback(
move |response: Response<Json<Result<DataFromFile, Error>>>| {
let (meta, Json(data)) = response.into_parts();
Expand All @@ -92,7 +92,7 @@ impl Model {
}
}

pub fn fetch_toml(&mut self, binary: AsBinary) -> yew::services::fetch::FetchTask {
pub fn fetch_toml(&mut self, binary: AsBinary) -> yew_services::fetch::FetchTask {
let callback = self.link.batch_callback(
move |response: Response<Toml<Result<DataFromFile, Error>>>| {
let (meta, Toml(data)) = response.into_parts();
Expand Down
1 change: 1 addition & 0 deletions examples/file_upload/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ edition = "2018"
[dependencies]
js-sys = "0.3"
yew = { path = "../../packages/yew" }
yew-services = { path = "../../packages/yew-services" }
2 changes: 1 addition & 1 deletion examples/file_upload/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use yew::services::reader::{File, FileChunk, FileData, ReaderService, ReaderTask};
use yew::{html, ChangeData, Component, ComponentLink, Html, ShouldRender};
use yew_services::reader::{File, FileChunk, FileData, ReaderService, ReaderTask};

type Chunks = bool;

Expand Down
1 change: 1 addition & 0 deletions examples/futures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
yew = { path = "../../packages/yew" }
yewtil = { path = "../../packages/yewtil", features = ["future"] }
yew-services = { path = "../../packages/yew-services" }

[dependencies.web-sys]
version = "0.3"
Expand Down
1 change: 1 addition & 0 deletions examples/game_of_life/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ log = "0.4"
rand = "0.8"
wasm-logger = "0.2"
yew = { path = "../../packages/yew" }
yew-services = { path = "../../packages/yew-services" }
2 changes: 1 addition & 1 deletion examples/game_of_life/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use cell::Cellule;
use rand::Rng;
use std::time::Duration;
use yew::services::interval::{IntervalService, IntervalTask};
use yew::{classes, html, Component, ComponentLink, Html, ShouldRender};
use yew_services::interval::{IntervalService, IntervalTask};

mod cell;

Expand Down
1 change: 1 addition & 0 deletions examples/inner_html/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2018"

[dependencies]
yew = { path = "../../packages/yew" }
yew-services = { path = "../../packages/yew-services" }

[dependencies.web-sys]
version = "0.3"
Expand Down
1 change: 1 addition & 0 deletions examples/js_callback/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ edition = "2018"
[dependencies]
wasm-bindgen = "0.2"
yew = { path = "../../packages/yew" }
yew-services = { path = "../../packages/yew-services" }
1 change: 1 addition & 0 deletions examples/keyed_list/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ rand = "0.8"
wasm-logger = "0.2"
yew = { path = "../../packages/yew" }
yewtil = { path = "../../packages/yewtil" }
yew-services = { path = "../../packages/yew-services" }
1 change: 1 addition & 0 deletions examples/mount_point/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2018"
[dependencies]
wasm-bindgen = "0.2"
yew = { path = "../../packages/yew" }
yew-services = { path = "../../packages/yew-services" }

[dependencies.web-sys]
version = "0.3"
Expand Down
1 change: 1 addition & 0 deletions examples/multi_thread/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ log = "0.4"
serde = { version = "1.0", features = ["derive"] }
wasm-logger = "0.2"
yew = { path = "../../packages/yew" }
yew-services = { path = "../../packages/yew-services" }
2 changes: 1 addition & 1 deletion examples/multi_thread/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
use std::time::Duration;
use yew::services::interval::{IntervalService, IntervalTask};
use yew::worker::{Agent, AgentLink, Context, HandlerId};
use yew_services::interval::{IntervalService, IntervalTask};

#[derive(Serialize, Deserialize, Debug)]
pub enum Request {
Expand Down
2 changes: 1 addition & 1 deletion examples/multi_thread/src/job.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
use std::time::Duration;
use yew::services::interval::{IntervalService, IntervalTask};
use yew::worker::{Agent, AgentLink, HandlerId, Job};
use yew_services::interval::{IntervalService, IntervalTask};

#[derive(Serialize, Deserialize, Debug)]
pub enum Request {
Expand Down
2 changes: 1 addition & 1 deletion examples/multi_thread/src/native_worker.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
use std::time::Duration;
use yew::services::interval::{IntervalService, IntervalTask};
use yew::worker::{Agent, AgentLink, HandlerId, Public};
use yew_services::interval::{IntervalService, IntervalTask};

#[derive(Serialize, Deserialize, Debug)]
pub enum Request {
Expand Down
1 change: 1 addition & 0 deletions examples/nested_list/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ edition = "2018"
log = "0.4"
wasm-logger = "0.2"
yew = { path = "../../packages/yew" }
yew-services = { path = "../../packages/yew-services" }
1 change: 1 addition & 0 deletions examples/node_refs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ edition = "2018"
[dependencies]
yew = { path = "../../packages/yew" }
web-sys = { version = "0.3", features = ["HtmlElement", "HtmlInputElement", "Node"] }
yew-services = { path = "../../packages/yew-services" }
1 change: 1 addition & 0 deletions examples/router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ wasm-logger = "0.2"
yew = { path = "../../packages/yew" }
yew-router = { path = "../../packages/yew-router" }
yewtil = { path = "../../packages/yewtil" }
yew-services = { path = "../../packages/yew-services" }
2 changes: 1 addition & 1 deletion examples/router/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ Take a look at [`PublicUrlSwitch`](src/switch.rs) for the implementation.
- Home (`/`) should include links to the post list and the author introduction
- Detect sub-path from `--public-url` value passed to Trunk. See: thedodd/trunk#51

[`intervalservice`]: https://docs.rs/yew/latest/yew/services/struct.IntervalService.html
[`intervalservice`]: https://docs.rs/yew-services/latest/yew_services/struct.IntervalService.html
[`yew-router`]: https://docs.rs/yew-router/latest/yew_router/
6 changes: 2 additions & 4 deletions examples/router/src/components/progress_delay.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use instant::Instant;
use std::time::Duration;
use yew::{
prelude::*,
services::interval::{IntervalService, IntervalTask},
};
use yew::prelude::*;
use yew_services::interval::{IntervalService, IntervalTask};
use yewtil::NeqAssign;

const RESOLUTION: u64 = 500;
Expand Down
1 change: 1 addition & 0 deletions examples/store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ edition = "2018"
[dependencies]
yew = { path = "../../packages/yew" }
yewtil = { path = "../../packages/yewtil" }
yew-services = { path = "../../packages/yew-services" }
3 changes: 2 additions & 1 deletion examples/store/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ mod text_input;
use agents::posts::{PostId, PostStore, Request};
use post::Post;
use text_input::TextInput;
use yew::{prelude::*, services::ConsoleService};
use yew::prelude::*;
use yew_services::ConsoleService;
use yewtil::store::{Bridgeable, ReadOnly, StoreWrapper};

pub enum Msg {
Expand Down
1 change: 1 addition & 0 deletions examples/timer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ edition = "2018"
[dependencies]
yew = { path = "../../packages/yew" }
js-sys = "0.3"
yew-services = { path = "../../packages/yew-services" }
6 changes: 3 additions & 3 deletions examples/timer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ but also makes use of some more advanced [`ConsoleService`] features.

- Apply the concept to something more fun than just a dry technical demonstration

[`timeoutservice`]: https://docs.rs/yew/latest/yew/services/struct.TimeoutService.html
[`intervalservice`]: https://docs.rs/yew/latest/yew/services/struct.IntervalService.html
[`consoleservice`]: https://docs.rs/yew/latest/yew/services/struct.ConsoleService.html
[`timeoutservice`]: https://docs.rs/yew-services/latest/yew_services/struct.TimeoutService.html
[`intervalservice`]: https://docs.rs/yew-services/latest/yew_services/struct.IntervalService.html
[`consoleservice`]: https://docs.rs/yew-services/latest/yew_services/struct.ConsoleService.html
4 changes: 2 additions & 2 deletions examples/timer/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::time::Duration;
use yew::services::interval::{IntervalService, IntervalTask};
use yew::services::{ConsoleService, Task, TimeoutService};
use yew::{html, Callback, Component, ComponentLink, Html, ShouldRender};
use yew_services::interval::{IntervalService, IntervalTask};
use yew_services::{ConsoleService, Task, TimeoutService};

pub enum Msg {
StartTimeout,
Expand Down
1 change: 1 addition & 0 deletions examples/todomvc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ strum_macros = "0.20"
serde = "1"
serde_derive = "1"
yew = { path = "../../packages/yew" }
yew-services = { path = "../../packages/yew-services" }
2 changes: 1 addition & 1 deletion examples/todomvc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ including: all entries, entered text and chosen filter.
- Use `yew-router` for the hash based routing
- Clean up the code

[`storageservice`]: https://docs.rs/yew/latest/yew/services/struct.StorageService.html
[`storageservice`]: https://docs.rs/yew-services/latest/yew_services/struct.StorageService.html
[`refs`]: https://yew.rs/docs/en/concepts/components/refs/
2 changes: 1 addition & 1 deletion examples/todomvc/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use state::{Entry, Filter, State};
use strum::IntoEnumIterator;
use yew::format::Json;
use yew::services::storage::{Area, StorageService};
use yew::web_sys::HtmlInputElement as InputElement;
use yew::{classes, html, Component, ComponentLink, Html, InputData, NodeRef, ShouldRender};
use yew::{events::KeyboardEvent, Classes};
use yew_services::storage::{Area, StorageService};

mod state;

Expand Down
Loading

0 comments on commit ab76a44

Please sign in to comment.