diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 43612bb120f..26280de26dd 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -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: @@ -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 diff --git a/docs/concepts/services/fetch.md b/docs/concepts/services/fetch.md index d2b1f00703f..3ad1136b18a 100644 --- a/docs/concepts/services/fetch.md +++ b/docs/concepts/services/fetch.md @@ -26,7 +26,7 @@ pub type Binary = Result, 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"); @@ -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"}))) @@ -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 { @@ -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) diff --git a/docs/more/debugging.md b/docs/more/debugging.md index 5a2709fb892..045be34e27d 100644 --- a/docs/more/debugging.md +++ b/docs/more/debugging.md @@ -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 diff --git a/examples/boids/Cargo.toml b/examples/boids/Cargo.toml index c1f4a759389..6c31c01c509 100644 --- a/examples/boids/Cargo.toml +++ b/examples/boids/Cargo.toml @@ -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" } diff --git a/examples/boids/README.md b/examples/boids/README.md index 992e274a631..08a54838e7f 100644 --- a/examples/boids/README.md +++ b/examples/boids/README.md @@ -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 diff --git a/examples/boids/src/settings.rs b/examples/boids/src/settings.rs index 5f216bc8e32..d62bb86fe33 100644 --- a/examples/boids/src/settings.rs +++ b/examples/boids/src/settings.rs @@ -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 { diff --git a/examples/boids/src/simulation.rs b/examples/boids/src/simulation.rs index d3c4c363659..9f87adf7564 100644 --- a/examples/boids/src/simulation.rs +++ b/examples/boids/src/simulation.rs @@ -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); diff --git a/examples/counter/Cargo.toml b/examples/counter/Cargo.toml index 5c81dbe928a..03f0c2f0f66 100644 --- a/examples/counter/Cargo.toml +++ b/examples/counter/Cargo.toml @@ -7,3 +7,4 @@ edition = "2018" [dependencies] js-sys = "0.3" yew = { path = "../../packages/yew" } +yew-services = { path = "../../packages/yew-services" } diff --git a/examples/counter/src/main.rs b/examples/counter/src/main.rs index 52c6aa7ea1b..85dcc33d5fc 100644 --- a/examples/counter/src/main.rs +++ b/examples/counter/src/main.rs @@ -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, diff --git a/examples/crm/Cargo.toml b/examples/crm/Cargo.toml index 8eb6dbc71bb..cabdd989741 100644 --- a/examples/crm/Cargo.toml +++ b/examples/crm/Cargo.toml @@ -8,3 +8,4 @@ edition = "2018" serde = "1" serde_derive = "1" yew = { path = "../../packages/yew" } +yew-services = { path = "../../packages/yew-services" } diff --git a/examples/crm/README.md b/examples/crm/README.md index b628490bee2..b669166447d 100644 --- a/examples/crm/README.md +++ b/examples/crm/README.md @@ -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 diff --git a/examples/crm/src/main.rs b/examples/crm/src/main.rs index 28dd90d29fa..db06f1544ce 100644 --- a/examples/crm/src/main.rs +++ b/examples/crm/src/main.rs @@ -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; diff --git a/examples/dashboard/Cargo.toml b/examples/dashboard/Cargo.toml index 3e826c659c7..d4448367ce3 100644 --- a/examples/dashboard/Cargo.toml +++ b/examples/dashboard/Cargo.toml @@ -9,3 +9,4 @@ anyhow = "1" serde = "1" serde_derive = "1" yew = { path = "../../packages/yew", features = ["toml"] } +yew-services = { path = "../../packages/yew-services" } diff --git a/examples/dashboard/src/main.rs b/examples/dashboard/src/main.rs index 6d70b021f11..dcb3381b8eb 100644 --- a/examples/dashboard/src/main.rs +++ b/examples/dashboard/src/main.rs @@ -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; @@ -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>>| { let (meta, Json(data)) = response.into_parts(); @@ -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>>| { let (meta, Toml(data)) = response.into_parts(); diff --git a/examples/file_upload/Cargo.toml b/examples/file_upload/Cargo.toml index a5e5f278e47..0d325aac693 100644 --- a/examples/file_upload/Cargo.toml +++ b/examples/file_upload/Cargo.toml @@ -7,3 +7,4 @@ edition = "2018" [dependencies] js-sys = "0.3" yew = { path = "../../packages/yew" } +yew-services = { path = "../../packages/yew-services" } diff --git a/examples/file_upload/src/main.rs b/examples/file_upload/src/main.rs index c71354e97ad..75fd757f68d 100644 --- a/examples/file_upload/src/main.rs +++ b/examples/file_upload/src/main.rs @@ -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; diff --git a/examples/futures/Cargo.toml b/examples/futures/Cargo.toml index 9e467cfb1ec..adb4fc72244 100644 --- a/examples/futures/Cargo.toml +++ b/examples/futures/Cargo.toml @@ -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" diff --git a/examples/game_of_life/Cargo.toml b/examples/game_of_life/Cargo.toml index b9eebeb5ed1..fbb05fa1041 100644 --- a/examples/game_of_life/Cargo.toml +++ b/examples/game_of_life/Cargo.toml @@ -14,3 +14,4 @@ log = "0.4" rand = "0.8" wasm-logger = "0.2" yew = { path = "../../packages/yew" } +yew-services = { path = "../../packages/yew-services" } diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index 1cfcbad68fc..9c0365f4c4f 100644 --- a/examples/game_of_life/src/main.rs +++ b/examples/game_of_life/src/main.rs @@ -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; diff --git a/examples/inner_html/Cargo.toml b/examples/inner_html/Cargo.toml index 9ac048fc35b..e9e01632200 100644 --- a/examples/inner_html/Cargo.toml +++ b/examples/inner_html/Cargo.toml @@ -6,6 +6,7 @@ edition = "2018" [dependencies] yew = { path = "../../packages/yew" } +yew-services = { path = "../../packages/yew-services" } [dependencies.web-sys] version = "0.3" diff --git a/examples/js_callback/Cargo.toml b/examples/js_callback/Cargo.toml index a9ae1691e52..895fda7a638 100644 --- a/examples/js_callback/Cargo.toml +++ b/examples/js_callback/Cargo.toml @@ -7,3 +7,4 @@ edition = "2018" [dependencies] wasm-bindgen = "0.2" yew = { path = "../../packages/yew" } +yew-services = { path = "../../packages/yew-services" } diff --git a/examples/keyed_list/Cargo.toml b/examples/keyed_list/Cargo.toml index 53a43780a1d..d4bd3563b3a 100644 --- a/examples/keyed_list/Cargo.toml +++ b/examples/keyed_list/Cargo.toml @@ -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" } diff --git a/examples/mount_point/Cargo.toml b/examples/mount_point/Cargo.toml index c979d920e86..1d2dda17c82 100644 --- a/examples/mount_point/Cargo.toml +++ b/examples/mount_point/Cargo.toml @@ -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" diff --git a/examples/multi_thread/Cargo.toml b/examples/multi_thread/Cargo.toml index aa3f3c81fae..d9c0fb0db99 100644 --- a/examples/multi_thread/Cargo.toml +++ b/examples/multi_thread/Cargo.toml @@ -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" } diff --git a/examples/multi_thread/src/context.rs b/examples/multi_thread/src/context.rs index a4b87c7483c..7e6471252aa 100644 --- a/examples/multi_thread/src/context.rs +++ b/examples/multi_thread/src/context.rs @@ -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 { diff --git a/examples/multi_thread/src/job.rs b/examples/multi_thread/src/job.rs index b3fbb159629..b41b799871a 100644 --- a/examples/multi_thread/src/job.rs +++ b/examples/multi_thread/src/job.rs @@ -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 { diff --git a/examples/multi_thread/src/native_worker.rs b/examples/multi_thread/src/native_worker.rs index bfd5f9d6019..3a9bd2a162f 100644 --- a/examples/multi_thread/src/native_worker.rs +++ b/examples/multi_thread/src/native_worker.rs @@ -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 { diff --git a/examples/nested_list/Cargo.toml b/examples/nested_list/Cargo.toml index 78cfaa02130..9a5200a3e9a 100644 --- a/examples/nested_list/Cargo.toml +++ b/examples/nested_list/Cargo.toml @@ -8,3 +8,4 @@ edition = "2018" log = "0.4" wasm-logger = "0.2" yew = { path = "../../packages/yew" } +yew-services = { path = "../../packages/yew-services" } diff --git a/examples/node_refs/Cargo.toml b/examples/node_refs/Cargo.toml index 58793ee95bf..4e3e1f5a223 100644 --- a/examples/node_refs/Cargo.toml +++ b/examples/node_refs/Cargo.toml @@ -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" } diff --git a/examples/router/Cargo.toml b/examples/router/Cargo.toml index 94de34b2df6..22bc6651d69 100644 --- a/examples/router/Cargo.toml +++ b/examples/router/Cargo.toml @@ -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" } diff --git a/examples/router/README.md b/examples/router/README.md index 83da7f5b590..5dc1db091c6 100644 --- a/examples/router/README.md +++ b/examples/router/README.md @@ -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/ diff --git a/examples/router/src/components/progress_delay.rs b/examples/router/src/components/progress_delay.rs index 4c3ce3b56e0..da6ca1bd19a 100644 --- a/examples/router/src/components/progress_delay.rs +++ b/examples/router/src/components/progress_delay.rs @@ -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; diff --git a/examples/store/Cargo.toml b/examples/store/Cargo.toml index 11bd23b57d0..190c02ee096 100644 --- a/examples/store/Cargo.toml +++ b/examples/store/Cargo.toml @@ -7,3 +7,4 @@ edition = "2018" [dependencies] yew = { path = "../../packages/yew" } yewtil = { path = "../../packages/yewtil" } +yew-services = { path = "../../packages/yew-services" } diff --git a/examples/store/src/main.rs b/examples/store/src/main.rs index a48da294a6e..7179879dc3d 100644 --- a/examples/store/src/main.rs +++ b/examples/store/src/main.rs @@ -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 { diff --git a/examples/timer/Cargo.toml b/examples/timer/Cargo.toml index 0fe42c865d7..38573ef4873 100644 --- a/examples/timer/Cargo.toml +++ b/examples/timer/Cargo.toml @@ -7,3 +7,4 @@ edition = "2018" [dependencies] yew = { path = "../../packages/yew" } js-sys = "0.3" +yew-services = { path = "../../packages/yew-services" } diff --git a/examples/timer/README.md b/examples/timer/README.md index f4d230ef97e..5eed9ca0cc4 100644 --- a/examples/timer/README.md +++ b/examples/timer/README.md @@ -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 diff --git a/examples/timer/src/main.rs b/examples/timer/src/main.rs index 87ff2e0107e..9da5867206d 100644 --- a/examples/timer/src/main.rs +++ b/examples/timer/src/main.rs @@ -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, diff --git a/examples/todomvc/Cargo.toml b/examples/todomvc/Cargo.toml index e7e43439a91..55b05fef65f 100644 --- a/examples/todomvc/Cargo.toml +++ b/examples/todomvc/Cargo.toml @@ -10,3 +10,4 @@ strum_macros = "0.20" serde = "1" serde_derive = "1" yew = { path = "../../packages/yew" } +yew-services = { path = "../../packages/yew-services" } diff --git a/examples/todomvc/README.md b/examples/todomvc/README.md index 9cc23beec75..fea25f68a5c 100644 --- a/examples/todomvc/README.md +++ b/examples/todomvc/README.md @@ -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/ diff --git a/examples/todomvc/src/main.rs b/examples/todomvc/src/main.rs index 718c3659991..ff5e4876b53 100644 --- a/examples/todomvc/src/main.rs +++ b/examples/todomvc/src/main.rs @@ -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; diff --git a/examples/two_apps/Cargo.toml b/examples/two_apps/Cargo.toml index 3107e574a36..81c4ee39c0b 100644 --- a/examples/two_apps/Cargo.toml +++ b/examples/two_apps/Cargo.toml @@ -6,3 +6,4 @@ edition = "2018" [dependencies] yew = { path = "../../packages/yew" } +yew-services = { path = "../../packages/yew-services" } diff --git a/examples/webgl/Cargo.toml b/examples/webgl/Cargo.toml index 2c0fad9de4f..7d9b9742ffa 100644 --- a/examples/webgl/Cargo.toml +++ b/examples/webgl/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" js-sys = "0.3" wasm-bindgen = "0.2" yew = { path = "../../packages/yew" } +yew-services = { path = "../../packages/yew-services" } [dependencies.web-sys] version = "0.3" diff --git a/examples/webgl/src/main.rs b/examples/webgl/src/main.rs index 2c30ef79274..aecb973d6cb 100644 --- a/examples/webgl/src/main.rs +++ b/examples/webgl/src/main.rs @@ -1,8 +1,8 @@ use wasm_bindgen::JsCast; use web_sys::{HtmlCanvasElement, WebGlRenderingContext as GL}; -use yew::services::render::RenderTask; -use yew::services::RenderService; use yew::{html, Component, ComponentLink, Html, NodeRef, ShouldRender}; +use yew_services::render::RenderTask; +use yew_services::RenderService; pub enum Msg { Render(f64), diff --git a/packages/yew-functional/Cargo.toml b/packages/yew-functional/Cargo.toml index 44266653442..ac1b8448a49 100644 --- a/packages/yew-functional/Cargo.toml +++ b/packages/yew-functional/Cargo.toml @@ -14,6 +14,7 @@ description = "A framework for making client-side single-page apps" wasm-bindgen-test = "0.3.9" web-sys = "0.3.36" yew = { path = "../yew" } +yew-services = { path = "../yew-services" } [dependencies] yew = { path = "../yew" } diff --git a/packages/yew-functional/tests/use_context.rs b/packages/yew-functional/tests/use_context.rs index 07e68dfc109..f4fbe39f1f7 100644 --- a/packages/yew-functional/tests/use_context.rs +++ b/packages/yew-functional/tests/use_context.rs @@ -26,7 +26,7 @@ fn use_context_scoping_works() { fn run(_props: &Self::TProps) -> Html { if use_context::().is_some() { - yew::services::ConsoleService::log(&format!( + yew_services::ConsoleService::log(&format!( "Context should be None here, but was {:?}!", use_context::().unwrap() )); diff --git a/packages/yew-router/Cargo.toml b/packages/yew-router/Cargo.toml index 90a4bf6eee1..c012c801977 100644 --- a/packages/yew-router/Cargo.toml +++ b/packages/yew-router/Cargo.toml @@ -31,7 +31,7 @@ web_sys = [ ] [dependencies] -yew = { version = "0.17.0", path = "../yew", features = ["services", "agent"], default-features= false, optional = true } +yew = { version = "0.17.0", path = "../yew", features = ["agent"], default-features= false, optional = true } yew-router-macro = { version = "0.14.0", path = "../yew-router-macro" } yew-router-route-parser = { version = "0.14.0", path = "../yew-router-route-parser" } diff --git a/packages/yew-services/Cargo.toml b/packages/yew-services/Cargo.toml new file mode 100644 index 00000000000..c5041740a04 --- /dev/null +++ b/packages/yew-services/Cargo.toml @@ -0,0 +1,70 @@ +[package] +name = "yew-services" +version = "0.1.0" +authors = ["Hamza "] +edition = "2018" + +[dependencies] + +anyhow = "1" +cfg-if = "1.0" +cfg-match = "0.2" +gloo = { version = "0.2.1", optional = true } +http = "0.2" +js-sys = { version = "0.3", optional = true } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +stdweb = { version = "0.4.20", optional = true } +thiserror = "1" +yew = { path = "../yew" } +wasm-bindgen = { version = "0.2.60" } +wasm-bindgen-futures = { version = "0.4", optional = true } + +[dependencies.web-sys] +version = "0.3" +optional = true +features = [ + "AbortController", + "AbortSignal", + "BinaryType", + "Blob", + "BlobPropertyBag", + "DedicatedWorkerGlobalScope", + "DomTokenList", + "Headers", + "ReferrerPolicy", + "Request", + "RequestCache", + "RequestCredentials", + "RequestInit", + "RequestMode", + "RequestRedirect", + "Response", + "Storage", + "Text", + "Url", + "WebSocket", + "Window", + "Worker", + "WorkerGlobalScope", + "WorkerOptions", +] + + +[dev-dependencies] +wasm-bindgen-test = "0.3.4" +base64 = "0.13.0" +ssri = "6.0.0" + +[features] +default = ["web_sys"] +web_sys = [ + "gloo", + "js-sys", + "web-sys", + "wasm-bindgen-futures" +] +std_web = ["stdweb"] +wasm_test = [] +httpbin_test = [] +echo_server_test = [] diff --git a/packages/yew-services/src/callback_test_util.rs b/packages/yew-services/src/callback_test_util.rs new file mode 100644 index 00000000000..6f9adcf2ceb --- /dev/null +++ b/packages/yew-services/src/callback_test_util.rs @@ -0,0 +1,147 @@ +#![cfg(test)] + +#[cfg(feature = "web_sys")] +pub use self::web_sys::*; + +#[cfg(feature = "std_web")] +pub use self::std_web::*; + +#[cfg(feature = "web_sys")] +mod web_sys { + use std::cell::RefCell; + use std::future::Future; + use std::pin::Pin; + use std::rc::Rc; + use std::task::{Context, Poll, Waker}; + use yew::callback::*; + + struct CallbackHandle { + waker: Option, + output: Option, + } + + impl Default for CallbackHandle { + fn default() -> Self { + CallbackHandle { + waker: None, + output: None, + } + } + } + + pub struct CallbackFuture(Rc>>); + + impl Clone for CallbackFuture { + fn clone(&self) -> Self { + Self(self.0.clone()) + } + } + + impl Default for CallbackFuture { + fn default() -> Self { + Self(Rc::default()) + } + } + + impl Into> for CallbackFuture { + fn into(self) -> Callback { + Callback::from(move |r| self.finish(r)) + } + } + + impl Future for CallbackFuture { + type Output = T; + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + if let Some(output) = self.ready() { + Poll::Ready(output) + } else { + let handle = &self.0; + handle.borrow_mut().waker = Some(cx.waker().clone()); + Poll::Pending + } + } + } + + impl CallbackFuture { + pub fn ready(&self) -> Option { + self.0.borrow_mut().output.take() + } + + fn finish(&self, output: T) { + self.0.borrow_mut().output = Some(output); + if let Some(waker) = self.0.borrow_mut().waker.take() { + waker.wake(); + } + } + } +} + +#[cfg(feature = "std_web")] +mod std_web { + use std::cell::RefCell; + use std::future::Future; + use std::pin::Pin; + use std::rc::Rc; + use std::task::{Context, Poll, Waker}; + use yew::callback::*; + + struct CallbackHandle { + waker: Option, + output: Option, + } + + impl Default for CallbackHandle { + fn default() -> Self { + CallbackHandle { + waker: None, + output: None, + } + } + } + + pub struct CallbackFuture(Rc>>); + + impl Clone for CallbackFuture { + fn clone(&self) -> Self { + Self(self.0.clone()) + } + } + + impl Default for CallbackFuture { + fn default() -> Self { + Self(Rc::default()) + } + } + + impl Into> for CallbackFuture { + fn into(self) -> Callback { + Callback::from(move |r| self.finish(r)) + } + } + + impl Future for CallbackFuture { + type Output = T; + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + if let Some(output) = self.ready() { + Poll::Ready(output) + } else { + let handle = &self.0; + handle.borrow_mut().waker = Some(cx.waker().clone()); + Poll::Pending + } + } + } + + impl CallbackFuture { + pub fn ready(&self) -> Option { + self.0.borrow_mut().output.take() + } + + fn finish(&self, output: T) { + self.0.borrow_mut().output = Some(output); + if let Some(waker) = self.0.borrow_mut().waker.take() { + waker.wake(); + } + } + } +} diff --git a/packages/yew/src/services/console.rs b/packages/yew-services/src/console.rs similarity index 100% rename from packages/yew/src/services/console.rs rename to packages/yew-services/src/console.rs diff --git a/packages/yew/src/services/dialog.rs b/packages/yew-services/src/dialog.rs similarity index 99% rename from packages/yew/src/services/dialog.rs rename to packages/yew-services/src/dialog.rs index 4c1b46918a5..a71fbddb229 100644 --- a/packages/yew/src/services/dialog.rs +++ b/packages/yew-services/src/dialog.rs @@ -12,7 +12,7 @@ cfg_if! { #[allow(unused_imports)] use stdweb::{_js_impl, js}; } else if #[cfg(feature = "web_sys")] { - use crate::utils; + use yew::utils; } } diff --git a/packages/yew/src/services/fetch.rs b/packages/yew-services/src/fetch.rs similarity index 98% rename from packages/yew/src/services/fetch.rs rename to packages/yew-services/src/fetch.rs index e2b635f8b5d..f42c8d16624 100644 --- a/packages/yew/src/services/fetch.rs +++ b/packages/yew-services/src/fetch.rs @@ -25,15 +25,16 @@ pub enum Referrer { #[cfg(all(feature = "wasm_test", feature = "httpbin_test"))] mod tests { use super::*; - use crate::callback::{test_util::CallbackFuture, Callback}; - use crate::format::{Json, Nothing}; - use crate::utils; + use crate::callback_test_util::CallbackFuture; #[cfg(feature = "web_sys")] use ::web_sys::ReferrerPolicy; use serde::Deserialize; use ssri::Integrity; use std::collections::HashMap; use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure}; + use yew::callback::Callback; + use yew::format::{Json, Nothing}; + use yew::utils; wasm_bindgen_test_configure!(run_in_browser); diff --git a/packages/yew/src/services/fetch/std_web.rs b/packages/yew-services/src/fetch/std_web.rs similarity index 97% rename from packages/yew/src/services/fetch/std_web.rs rename to packages/yew-services/src/fetch/std_web.rs index 9bfddc8e73f..6a4c6ae0d1a 100644 --- a/packages/yew/src/services/fetch/std_web.rs +++ b/packages/yew-services/src/fetch/std_web.rs @@ -1,9 +1,7 @@ //! `stdweb` implementation for the fetch service. use super::Referrer; -use crate::callback::Callback; -use crate::format::{Binary, Format, Text}; -use crate::services::Task; +use crate::Task; use serde::Serialize; use std::collections::HashMap; use std::fmt; @@ -15,6 +13,8 @@ use stdweb::{JsSerialize, Value}; #[allow(unused_imports)] use stdweb::{_js_impl, js}; use thiserror::Error; +use yew::callback::Callback; +use yew::format::{Binary, Format, Text}; #[doc(no_inline)] pub use http::{HeaderMap, Method, Request, Response, StatusCode, Uri}; @@ -169,7 +169,7 @@ impl FetchService { /// /// ``` ///# use yew::format::{Nothing, Json}; - ///# use yew::services::fetch::Request; + ///# use yew_services::fetch::Request; ///# use serde_json::json; /// let post_request = Request::post("https://my.api/v1/resource") /// .header("Content-Type", "application/json") @@ -186,8 +186,8 @@ impl FetchService { /// /// ``` ///# use yew::{Component, ComponentLink, Html}; - ///# use yew::services::FetchService; - ///# use yew::services::fetch::{Response, Request}; + ///# use yew_services::FetchService; + ///# use yew_services::fetch::{Response, Request}; ///# struct Comp; ///# impl Component for Comp { ///# type Message = Msg;type Properties = (); @@ -222,9 +222,9 @@ impl FetchService { /// /// ``` ///# use yew::format::{Json, Nothing, Format}; - ///# use yew::services::FetchService; + ///# use yew_services::FetchService; ///# use http::Request; - ///# use yew::services::fetch::Response; + ///# use yew_services::fetch::Response; ///# use yew::{Component, ComponentLink, Html}; ///# use serde_derive::Deserialize; ///# struct Comp; @@ -275,9 +275,9 @@ impl FetchService { /// Use it if you need to send cookies with a request: /// ``` ///# use yew::format::Nothing; - ///# use yew::services::fetch::{self, FetchOptions, Credentials}; + ///# use yew_services::fetch::{self, FetchOptions, Credentials}; ///# use yew::{Html, Component, ComponentLink}; - ///# use yew::services::FetchService; + ///# use yew_services::FetchService; ///# use http::Response; ///# struct Comp; ///# impl Component for Comp { diff --git a/packages/yew/src/services/fetch/web_sys.rs b/packages/yew-services/src/fetch/web_sys.rs similarity index 97% rename from packages/yew/src/services/fetch/web_sys.rs rename to packages/yew-services/src/fetch/web_sys.rs index 52ec4ef0a4a..1e56e3d5936 100644 --- a/packages/yew/src/services/fetch/web_sys.rs +++ b/packages/yew-services/src/fetch/web_sys.rs @@ -1,9 +1,7 @@ //! `web-sys` implementation for the fetch service. use super::Referrer; -use crate::callback::Callback; -use crate::format::{Binary, Format, Text}; -use crate::services::Task; +use crate::Task; use anyhow::{anyhow, Error}; use http::request::Parts; use js_sys::{Array, Promise, Uint8Array}; @@ -20,6 +18,8 @@ use web_sys::{ AbortController, Headers, ReferrerPolicy, Request as WebRequest, RequestInit, Response as WebResponse, }; +use yew::callback::Callback; +use yew::format::{Binary, Format, Text}; #[doc(no_inline)] pub use web_sys::{ @@ -171,7 +171,7 @@ impl FetchService { /// /// ``` ///# use yew::format::{Nothing, Json}; - ///# use yew::services::fetch::Request; + ///# use yew_services::fetch::Request; ///# use serde_json::json; /// let post_request = Request::post("https://my.api/v1/resource") /// .header("Content-Type", "application/json") @@ -188,8 +188,8 @@ impl FetchService { /// /// ``` ///# use yew::{Component, ComponentLink, Html}; - ///# use yew::services::FetchService; - ///# use yew::services::fetch::{Response, Request}; + ///# use yew_services::FetchService; + ///# use yew_services::fetch::{Response, Request}; ///# use anyhow::Error; ///# struct Comp; ///# impl Component for Comp { @@ -225,11 +225,11 @@ impl FetchService { /// /// ``` ///# use yew::format::{Json, Nothing, Format}; - ///# use yew::services::FetchService; + ///# use yew_services::FetchService; ///# use http::Request; - ///# use yew::services::fetch::Response; + ///# use yew_services::fetch::Response; ///# use yew::{Component, ComponentLink, Html}; - ///# use serde_derive::Deserialize; + ///# use serde::Deserialize; ///# use anyhow::Error; ///# struct Comp; ///# impl Component for Comp { @@ -279,9 +279,9 @@ impl FetchService { /// Use it if you need to send cookies with a request: /// ``` ///# use yew::format::Nothing; - ///# use yew::services::fetch::{self, FetchOptions, Credentials}; + ///# use yew_services::fetch::{self, FetchOptions, Credentials}; ///# use yew::{Html, Component, ComponentLink}; - ///# use yew::services::FetchService; + ///# use yew_services::FetchService; ///# use http::Response; ///# use anyhow::Error; ///# struct Comp; diff --git a/packages/yew/src/services/interval.rs b/packages/yew-services/src/interval.rs similarity index 98% rename from packages/yew/src/services/interval.rs rename to packages/yew-services/src/interval.rs index fb8b23aac73..17ae8c36512 100644 --- a/packages/yew/src/services/interval.rs +++ b/packages/yew-services/src/interval.rs @@ -2,12 +2,12 @@ //! periodic sending messages to a loop. use super::Task; -use crate::callback::Callback; use cfg_if::cfg_if; use cfg_match::cfg_match; use std::convert::TryInto; use std::fmt; use std::time::Duration; +use yew::callback::Callback; cfg_if! { if #[cfg(feature = "std_web")] { use stdweb::Value; diff --git a/packages/yew/src/services/keyboard.rs b/packages/yew-services/src/keyboard.rs similarity index 99% rename from packages/yew/src/services/keyboard.rs rename to packages/yew-services/src/keyboard.rs index 8cb52932b25..d76d9a6243d 100644 --- a/packages/yew/src/services/keyboard.rs +++ b/packages/yew-services/src/keyboard.rs @@ -1,9 +1,9 @@ //! Service to register key press event listeners on elements. -use crate::callback::Callback; use cfg_if::cfg_if; use cfg_match::cfg_match; use std::fmt; +use yew::callback::Callback; cfg_if! { if #[cfg(feature = "std_web")] { use stdweb::web::event::{ConcreteEvent, KeyDownEvent, KeyPressEvent, KeyUpEvent}; diff --git a/packages/yew/src/services/mod.rs b/packages/yew-services/src/lib.rs similarity index 96% rename from packages/yew/src/services/mod.rs rename to packages/yew-services/src/lib.rs index bcc5c95b401..41d64424093 100644 --- a/packages/yew/src/services/mod.rs +++ b/packages/yew-services/src/lib.rs @@ -3,6 +3,8 @@ //! It carries a similar role as subscriptions in Elm, but can be used directly //! from the `update` method. +#[cfg(test)] +pub(crate) mod callback_test_util; pub mod console; pub mod dialog; pub mod fetch; diff --git a/packages/yew/src/services/reader.rs b/packages/yew-services/src/reader.rs similarity index 98% rename from packages/yew/src/services/reader.rs rename to packages/yew-services/src/reader.rs index f9d86d40fd4..46de8bdb050 100644 --- a/packages/yew/src/services/reader.rs +++ b/packages/yew-services/src/reader.rs @@ -1,6 +1,6 @@ //! Service to load files using `FileReader`. -use crate::services::Task; +use crate::Task; use std::fmt; cfg_if::cfg_if! { if #[cfg(feature = "std_web")] { diff --git a/packages/yew/src/services/reader/std_web.rs b/packages/yew-services/src/reader/std_web.rs similarity index 98% rename from packages/yew/src/services/reader/std_web.rs rename to packages/yew-services/src/reader/std_web.rs index 238d9a4799b..968ccb7cc81 100644 --- a/packages/yew/src/services/reader/std_web.rs +++ b/packages/yew-services/src/reader/std_web.rs @@ -1,8 +1,7 @@ //! `stdweb` implementation for the reader service. use super::*; -use crate::callback::Callback; -use crate::services::Task; +use crate::Task; use std::cmp; use stdweb::unstable::{TryFrom, TryInto}; use stdweb::web::event::LoadEndEvent; @@ -11,6 +10,7 @@ pub use stdweb::web::{Blob, File, IBlob}; use stdweb::web::{FileReader, FileReaderReadyState, FileReaderResult, IEventTarget, TypedArray}; #[allow(unused_imports)] use stdweb::{_js_impl, js}; +use yew::callback::Callback; fn new_file_reader() -> Result { let file_reader = js! { diff --git a/packages/yew/src/services/reader/web_sys.rs b/packages/yew-services/src/reader/web_sys.rs similarity index 98% rename from packages/yew/src/services/reader/web_sys.rs rename to packages/yew-services/src/reader/web_sys.rs index bd26b83f321..6a74ae31547 100644 --- a/packages/yew/src/services/reader/web_sys.rs +++ b/packages/yew-services/src/reader/web_sys.rs @@ -1,8 +1,7 @@ //! `web-sys` implementation for the reader service. use super::*; -use crate::callback::Callback; -use crate::services::Task; +use crate::Task; #[doc(no_inline)] pub use ::web_sys::{Blob, File}; use ::web_sys::{Event, FileReader}; @@ -10,6 +9,7 @@ use anyhow::{anyhow, Result}; use gloo::events::EventListener; use js_sys::Uint8Array; use std::cmp; +use yew::callback::Callback; impl ReaderService { /// Reads all bytes from a file and returns them with a callback. diff --git a/packages/yew/src/services/render.rs b/packages/yew-services/src/render.rs similarity index 97% rename from packages/yew/src/services/render.rs rename to packages/yew-services/src/render.rs index 2c2dfd19362..1f47336ad4b 100644 --- a/packages/yew/src/services/render.rs +++ b/packages/yew-services/src/render.rs @@ -1,11 +1,11 @@ //! This module contains Yew's implementation of a service which can be used to //! request frame rendering -use crate::callback::Callback; -use crate::services::Task; +use crate::Task; use cfg_if::cfg_if; use cfg_match::cfg_match; use std::fmt; +use yew::callback::Callback; cfg_if! { if #[cfg(feature = "std_web")] { #[allow(unused_imports)] @@ -13,7 +13,7 @@ cfg_if! { use stdweb::unstable::TryInto; use stdweb::Value; } else if #[cfg(feature = "web_sys")] { - use crate::utils; + use yew::utils; use wasm_bindgen::closure::Closure; use wasm_bindgen::{JsCast, JsValue}; } diff --git a/packages/yew/src/services/resize.rs b/packages/yew-services/src/resize.rs similarity index 99% rename from packages/yew/src/services/resize.rs rename to packages/yew-services/src/resize.rs index 57b9f45cc78..0a80639bbfa 100644 --- a/packages/yew/src/services/resize.rs +++ b/packages/yew-services/src/resize.rs @@ -1,5 +1,5 @@ //! This module contains Yew's implementation of a service which listens for browser window resize events. -use crate::services::Task; +use crate::Task; use cfg_if::cfg_if; use cfg_match::cfg_match; use std::fmt; diff --git a/packages/yew/src/services/storage.rs b/packages/yew-services/src/storage.rs similarity index 98% rename from packages/yew/src/services/storage.rs rename to packages/yew-services/src/storage.rs index 14b527f342b..ef66431ebcf 100644 --- a/packages/yew/src/services/storage.rs +++ b/packages/yew-services/src/storage.rs @@ -1,11 +1,11 @@ //! This module contains Yew's implementation of a service to //! use local and session storage of a browser. -use crate::format::Text; use cfg_if::cfg_if; use cfg_match::cfg_match; use std::fmt; use thiserror::Error; +use yew::format::Text; cfg_if! { if #[cfg(feature = "std_web")] { #[allow(unused_imports)] @@ -13,7 +13,7 @@ cfg_if! { use stdweb::unstable::TryFrom; use stdweb::web::{Storage}; } else if #[cfg(feature = "web_sys")] { - use crate::utils; + use yew::utils; use web_sys::Storage; } } diff --git a/packages/yew/src/services/timeout.rs b/packages/yew-services/src/timeout.rs similarity index 98% rename from packages/yew/src/services/timeout.rs rename to packages/yew-services/src/timeout.rs index 6843e142fe7..27a5b1b4dcf 100644 --- a/packages/yew/src/services/timeout.rs +++ b/packages/yew-services/src/timeout.rs @@ -2,12 +2,12 @@ //! send messages when a timeout has elapsed. use super::Task; -use crate::callback::Callback; use cfg_if::cfg_if; use cfg_match::cfg_match; use std::convert::TryInto; use std::fmt; use std::time::Duration; +use yew::callback::Callback; cfg_if! { if #[cfg(feature = "std_web")] { use stdweb::Value; diff --git a/packages/yew/src/services/websocket.rs b/packages/yew-services/src/websocket.rs similarity index 98% rename from packages/yew/src/services/websocket.rs rename to packages/yew-services/src/websocket.rs index a5120121bd1..1df276915af 100644 --- a/packages/yew/src/services/websocket.rs +++ b/packages/yew-services/src/websocket.rs @@ -2,11 +2,11 @@ //! [`WebSocket` Protocol](https://tools.ietf.org/html/rfc6455). use super::Task; -use crate::callback::Callback; -use crate::format::{Binary, FormatError, Text}; use cfg_if::cfg_if; use cfg_match::cfg_match; use std::fmt; +use yew::callback::Callback; +use yew::format::{Binary, FormatError, Text}; cfg_if! { if #[cfg(feature = "std_web")] { use stdweb::traits::IMessageEvent; @@ -366,15 +366,16 @@ impl Drop for WebSocketTask { } #[cfg(test)] -#[cfg(all(feature = "wasm_test", feature = "echo_server_test"))] +#[cfg(feature = "wasm_test")] mod tests { use super::*; - use crate::callback::{test_util::CallbackFuture, Callback}; - use crate::format::{FormatError, Json}; - use crate::services::TimeoutService; + use crate::callback_test_util::CallbackFuture; + use crate::TimeoutService; use serde::{Deserialize, Serialize}; use std::time::Duration; use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure}; + use yew::callback::Callback; + use yew::format::{FormatError, Json}; wasm_bindgen_test_configure!(run_in_browser); diff --git a/packages/yew-stdweb/Cargo.toml b/packages/yew-stdweb/Cargo.toml index 61c259b972b..bac365d730d 100644 --- a/packages/yew-stdweb/Cargo.toml +++ b/packages/yew-stdweb/Cargo.toml @@ -64,13 +64,10 @@ rmp-serde = "0.14.0" bincode = "1" [features] -default = ["services", "agent", "std_web"] +default = ["agent", "std_web"] std_web = ["stdweb"] doc_test = [] wasm_test = [] -httpbin_test = [] -echo_server_test = [] -services = [] agent = ["bincode"] yaml = ["serde_yaml"] msgpack = ["rmp-serde"] diff --git a/packages/yew-stdweb/examples/counter/Cargo.toml b/packages/yew-stdweb/examples/counter/Cargo.toml index acd8d2399b0..a86e3e6f7cc 100644 --- a/packages/yew-stdweb/examples/counter/Cargo.toml +++ b/packages/yew-stdweb/examples/counter/Cargo.toml @@ -7,6 +7,7 @@ edition = "2018" [dependencies] stdweb = "0.4.20" yew = { path = "../..", package = "yew-stdweb" } +yew-services = { path = "../../../yew-services" } [target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dependencies] wasm-bindgen = "0.2.60" diff --git a/packages/yew-stdweb/examples/counter/src/lib.rs b/packages/yew-stdweb/examples/counter/src/lib.rs index 506fc0b959d..238cc556d29 100644 --- a/packages/yew-stdweb/examples/counter/src/lib.rs +++ b/packages/yew-stdweb/examples/counter/src/lib.rs @@ -1,8 +1,8 @@ #![recursion_limit = "256"] use stdweb::web::Date; -use yew::services::ConsoleService; use yew::{html, Component, ComponentLink, Html, ShouldRender}; +use yew_services::ConsoleService; pub struct Model { link: ComponentLink, diff --git a/packages/yew-stdweb/examples/todomvc/Cargo.toml b/packages/yew-stdweb/examples/todomvc/Cargo.toml index 7cf4ebe860c..41ad6798c27 100644 --- a/packages/yew-stdweb/examples/todomvc/Cargo.toml +++ b/packages/yew-stdweb/examples/todomvc/Cargo.toml @@ -10,6 +10,7 @@ strum_macros = "0.13" serde = "1" serde_derive = "1" yew = { path = "../..", package = "yew-stdweb" } +yew-services = { path = "../../../yew-services" } [target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dependencies] wasm-bindgen = "0.2.60" diff --git a/packages/yew-stdweb/examples/todomvc/src/lib.rs b/packages/yew-stdweb/examples/todomvc/src/lib.rs index 244ac547823..97eb4d4fb54 100644 --- a/packages/yew-stdweb/examples/todomvc/src/lib.rs +++ b/packages/yew-stdweb/examples/todomvc/src/lib.rs @@ -6,8 +6,8 @@ use strum::IntoEnumIterator; use strum_macros::{EnumIter, ToString}; use yew::events::IKeyboardEvent; use yew::format::Json; -use yew::services::storage::{Area, StorageService}; use yew::{html, Component, ComponentLink, Html, InputData, KeyPressEvent, ShouldRender}; +use yew_services::storage::{Area, StorageService}; const KEY: &str = "yew.todomvc.self"; diff --git a/packages/yew/Cargo.toml b/packages/yew/Cargo.toml index 1beadc54557..831214deb3e 100644 --- a/packages/yew/Cargo.toml +++ b/packages/yew/Cargo.toml @@ -122,7 +122,7 @@ rmp-serde = "0.15.0" bincode = "1" [features] -default = ["services", "agent", "web_sys"] +default = ["agent", "web_sys"] std_web = ["stdweb", "yew-macro/std_web"] web_sys = [ "console_error_panic_hook", @@ -134,10 +134,7 @@ web_sys = [ ] doc_test = [] wasm_test = [] -httpbin_test = [] -echo_server_test = [] wasm_bench = [] -services = [] agent = ["bincode"] yaml = ["serde_yaml"] msgpack = ["rmp-serde"] diff --git a/packages/yew/Makefile.toml b/packages/yew/Makefile.toml index b25678662a8..d67aa71e714 100644 --- a/packages/yew/Makefile.toml +++ b/packages/yew/Makefile.toml @@ -31,7 +31,7 @@ args = [ "test", "--doc", "--features", - "doc_test,wasm_test,yaml,msgpack,cbor,toml,std_web,agent,services", + "doc_test,wasm_test,yaml,msgpack,cbor,toml,std_web,agent", "--no-default-features", ] diff --git a/packages/yew/src/callback.rs b/packages/yew/src/callback.rs index 41f151710f7..75e306b2340 100644 --- a/packages/yew/src/callback.rs +++ b/packages/yew/src/callback.rs @@ -115,72 +115,3 @@ impl Callback { Callback::from(func) } } - -#[cfg(test)] -pub(crate) mod test_util { - use super::*; - use std::cell::RefCell; - use std::future::Future; - use std::pin::Pin; - use std::task::{Context, Poll, Waker}; - - struct CallbackHandle { - waker: Option, - output: Option, - } - - impl Default for CallbackHandle { - fn default() -> Self { - CallbackHandle { - waker: None, - output: None, - } - } - } - - pub(crate) struct CallbackFuture(Rc>>); - - impl Clone for CallbackFuture { - fn clone(&self) -> Self { - Self(self.0.clone()) - } - } - - impl Default for CallbackFuture { - fn default() -> Self { - Self(Rc::default()) - } - } - - impl Into> for CallbackFuture { - fn into(self) -> Callback { - Callback::from(move |r| self.finish(r)) - } - } - - impl Future for CallbackFuture { - type Output = T; - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - if let Some(output) = self.ready() { - Poll::Ready(output) - } else { - let handle = &self.0; - handle.borrow_mut().waker = Some(cx.waker().clone()); - Poll::Pending - } - } - } - - impl CallbackFuture { - pub fn ready(&self) -> Option { - self.0.borrow_mut().output.take() - } - - fn finish(&self, output: T) { - self.0.borrow_mut().output = Some(output); - if let Some(waker) = self.0.borrow_mut().waker.take() { - waker.wake(); - } - } - } -} diff --git a/packages/yew/src/lib.rs b/packages/yew/src/lib.rs index 1f618923dee..b09773e5418 100644 --- a/packages/yew/src/lib.rs +++ b/packages/yew/src/lib.rs @@ -290,8 +290,6 @@ pub mod virtual_dom; #[cfg(feature = "agent")] pub mod agent; -#[cfg(feature = "services")] -pub mod services; #[cfg(feature = "web_sys")] pub use web_sys;