From 402715fc1027b9a000184316bce0c4d8935be43f Mon Sep 17 00:00:00 2001 From: daxpedda Date: Fri, 27 Dec 2019 11:24:00 +0100 Subject: [PATCH 1/8] Moved patches from different PRs. --- Cargo.toml | 35 +++++++++++++++++++++++++++++++++-- build.rs | 6 ++++++ src/app.rs | 35 +++++++++++++++++++++++++++++------ src/components/select.rs | 6 +++++- src/lib.rs | 6 ++++++ 5 files changed, 79 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 848d18a24c8..cf0cc74435f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ bincode = { version = "~1.2.1", optional = true } failure = "0.1" http = "0.2" indexmap = "1.0.2" +js-sys = { version = "0.3.33", optional = true } log = "0.4" proc-macro-hack = "0.5" proc-macro-nested = "0.1" @@ -33,10 +34,39 @@ serde_cbor = { version = "0.10.2", optional = true } serde_json = "1.0" serde_yaml = { version = "0.8.3", optional = true } slab = "0.4" -stdweb = "0.4.20" +stdweb = { version = "0.4.20", optional = true } toml = { version = "0.5", optional = true } yew-macro = { version = "0.10.1", path = "crates/macro" } +[dependencies.web-sys] +version = "0.3.33" +optional = true +features = [ + "DedicatedWorkerGlobalScope", + "Document", + "DomTokenList", + "DragEvent", + "Element", + "Event", + "EventTarget", + "FileList", + "FocusEvent", + "HtmlInputElement", + "HtmlSelectElement", + "HtmlTextAreaElement", + "KeyboardEvent", + "MessageEvent", + "MouseEvent", + "Node", + "PointerEvent", + "Text", + "TouchEvent", + "UiEvent", + "WheelEvent", + "Window", + "Worker", +] + [target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dependencies] wasm-bindgen = "0.2.56" wasm-bindgen-futures = "0.4.4" @@ -53,7 +83,8 @@ trybuild = "1.0" rustversion = "1.0" [features] -default = ["services", "agent"] +default = ["services", "agent", "stdweb"] +web_sys = ["web-sys", "js-sys"] doc_test = [] web_test = [] wasm_test = [] diff --git a/build.rs b/build.rs index a0445febb0e..093d3fa5244 100644 --- a/build.rs +++ b/build.rs @@ -1,6 +1,12 @@ use std::env; pub fn main() { + if cfg!(all(feature = "web_sys", feature = "stdweb")) { + panic!("don't use `web_sys` and `stdweb` simultaneously") + } else if cfg!(not(any(feature = "web_sys", feature = "stdweb"))) { + panic!("please select either `web_sys` or `stdweb`") + } + let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default(); let cargo_web = env::var("COMPILING_UNDER_CARGO_WEB").unwrap_or_default(); if target_arch == "wasm32" && cargo_web != "1" { diff --git a/src/app.rs b/src/app.rs index 3e6a9c2835e..0e6a254ce3a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -2,7 +2,10 @@ //! a component in an isolated scope. use crate::html::{Component, NodeRef, Scope}; +#[cfg(feature = "stdweb")] use stdweb::web::{document, Element, INode, IParentNode}; +#[cfg(feature = "web_sys")] +use web_sys::Element; /// An application instance. #[derive(Debug)] @@ -42,8 +45,13 @@ where /// Alias to `mount("body", ...)`. pub fn mount_to_body(self) -> Scope { + #[cfg(feature = "stdweb")] + let document = document(); + #[cfg(feature = "web_sys")] + let document = web_sys::window().unwrap().document().unwrap(); + // Bootstrap the component for `Window` environment only (not for `Worker`) - let element = document() + let element = document .query_selector("body") .expect("can't get body node for rendering") .expect("can't unwrap body node"); @@ -55,11 +63,16 @@ where /// need to manipulate the body element. For example, adding/removing app-wide /// CSS classes of the body element. pub fn mount_as_body(self) -> Scope { - let html_element = document() + #[cfg(feature = "stdweb")] + let document = document(); + #[cfg(feature = "web_sys")] + let document = web_sys::window().unwrap().document().unwrap(); + + let html_element = document .query_selector("html") .expect("can't get html node for rendering") .expect("can't unwrap html node"); - let body_element = document() + let body_element = document .query_selector("body") .expect("can't get body node for rendering") .expect("can't unwrap body node"); @@ -97,8 +110,13 @@ where /// Alias to `mount_with_props("body", ...)`. pub fn mount_to_body_with_props(self, props: COMP::Properties) -> Scope { + #[cfg(feature = "stdweb")] + let document = document(); + #[cfg(feature = "web_sys")] + let document = web_sys::window().unwrap().document().unwrap(); + // Bootstrap the component for `Window` environment only (not for `Worker`) - let element = document() + let element = document .query_selector("body") .expect("can't get body node for rendering") .expect("can't unwrap body node"); @@ -110,11 +128,16 @@ where /// when you need to manipulate the body element. For example, adding/removing app-wide /// CSS classes of the body element. pub fn mount_as_body_with_props(self, props: COMP::Properties) -> Scope { - let html_element = document() + #[cfg(feature = "stdweb")] + let document = document(); + #[cfg(feature = "web_sys")] + let document = web_sys::window().unwrap().document().unwrap(); + + let html_element = document .query_selector("html") .expect("can't get html node for rendering") .expect("can't unwrap html node"); - let body_element = document() + let body_element = document .query_selector("body") .expect("can't get body node for rendering") .expect("can't unwrap body node"); diff --git a/src/components/select.rs b/src/components/select.rs index a28f5d61892..d4a3a87178d 100644 --- a/src/components/select.rs +++ b/src/components/select.rs @@ -121,7 +121,11 @@ where fn onchange(&self) -> Callback { self.link.callback(|event| match event { ChangeData::Select(elem) => { - let value = elem.selected_index().map(|x| x as usize); + let value = elem.selected_index(); + #[cfg(feature = "stdweb")] + let value = value.map(|x| x as usize); + #[cfg(feature = "web_sys")] + let value = Some(value as usize); Msg::Selected(value) } _ => { diff --git a/src/lib.rs b/src/lib.rs index bc74e9b5b51..e20d0e68f47 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -96,6 +96,7 @@ pub mod services; pub mod events { pub use crate::html::{ChangeData, InputData}; + #[cfg(feature = "stdweb")] pub use stdweb::web::event::{ BlurEvent, ClickEvent, ContextMenuEvent, DoubleClickEvent, DragDropEvent, DragEndEvent, DragEnterEvent, DragEvent, DragExitEvent, DragLeaveEvent, DragOverEvent, DragStartEvent, @@ -106,6 +107,11 @@ pub mod events { PointerLeaveEvent, PointerMoveEvent, PointerOutEvent, PointerOverEvent, PointerUpEvent, ScrollEvent, SubmitEvent, TouchCancel, TouchEnd, TouchEnter, TouchMove, TouchStart, }; + #[cfg(feature = "web_sys")] + pub use web_sys::{ + DragEvent, Event, FocusEvent, KeyboardEvent, MouseEvent, PointerEvent, TouchEvent, UiEvent, + WheelEvent, + }; } /// Initializes yew framework. It should be called first. From f76d5f73579a719ce6a1ef55e2959c14f91122a0 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Fri, 27 Dec 2019 11:31:26 +0100 Subject: [PATCH 2/8] Add bits & pieces and some services. --- Cargo.toml | 2 ++ src/lib.rs | 2 ++ src/utils.rs | 27 ++++++++++++++++++++++++--- tests/vtag_test.rs | 15 +++++++++++++-- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cf0cc74435f..7d11785814d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,6 +42,7 @@ yew-macro = { version = "0.10.1", path = "crates/macro" } version = "0.3.33" optional = true features = [ + "console", "DedicatedWorkerGlobalScope", "Document", "DomTokenList", @@ -55,6 +56,7 @@ features = [ "HtmlSelectElement", "HtmlTextAreaElement", "KeyboardEvent", + "Location", "MessageEvent", "MouseEvent", "Node", diff --git a/src/lib.rs b/src/lib.rs index e20d0e68f47..584d88917d6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -116,11 +116,13 @@ pub mod events { /// Initializes yew framework. It should be called first. pub fn initialize() { + #[cfg(feature = "stdweb")] stdweb::initialize(); } /// Starts event loop. pub fn run_loop() { + #[cfg(feature = "stdweb")] stdweb::event_loop(); } diff --git a/src/utils.rs b/src/utils.rs index c56d43227ba..14c2f195050 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,12 +1,33 @@ //! This module contains useful utils to get information about the current document. -use failure::{err_msg, Error}; +use failure::err_msg; +#[allow(unused_imports)] +use failure::Error; +#[cfg(feature = "stdweb")] use stdweb::web::document; /// Returns `host` for the current document. Useful to connect to a server that server the app. pub fn host() -> Result { - document() + #[cfg(feature = "stdweb")] + { + document() + .location() + .ok_or_else(|| err_msg("can't get location")) + .and_then(|l| l.host().map_err(Error::from)) + } + #[cfg(feature = "web_sys")] + web_sys::window() + .unwrap() + .document() + .unwrap() .location() .ok_or_else(|| err_msg("can't get location")) - .and_then(|l| l.host().map_err(Error::from)) + .and_then(|l| { + l.host().map_err(|e| { + err_msg( + e.as_string() + .unwrap_or_else(|| String::from("error not recoverable")), + ) + }) + }) } diff --git a/tests/vtag_test.rs b/tests/vtag_test.rs index 94c6b687cb2..6af412d352c 100644 --- a/tests/vtag_test.rs +++ b/tests/vtag_test.rs @@ -1,4 +1,5 @@ #![recursion_limit = "128"] +#[cfg(feature = "stdweb")] use stdweb::web::{document, IElement}; #[cfg(feature = "wasm_test")] use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure}; @@ -270,8 +271,18 @@ fn assert_namespace(vtag: &VTag, namespace: &'static str) { #[test] fn supports_svg() { - let div_el = document().create_element("div").unwrap(); - let svg_el = document().create_element_ns(SVG_NAMESPACE, "svg").unwrap(); + #[cfg(feature = "stdweb")] + let document = document(); + #[cfg(feature = "web_sys")] + let document = web_sys::window().unwrap().document().unwrap(); + + let div_el = document.create_element("div").unwrap(); + #[cfg(feature = "stdweb")] + let svg_el = document.create_element_ns(SVG_NAMESPACE, "svg").unwrap(); + #[cfg(feature = "web_sys")] + let svg_el = document + .create_element_ns(Some(SVG_NAMESPACE), "svg") + .unwrap(); let mut g_node = html! { }; let path_node = html! { }; From 2cc1b6472f80cee6d4f71b0308402c9faab4f0e4 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Tue, 31 Dec 2019 15:40:07 +0100 Subject: [PATCH 3/8] Rename `stdweb` feature to `std_web`. --- .cargo/config | 2 +- Cargo.toml | 28 ++++++++++++++++++++++++---- build.rs | 4 ++-- src/app.rs | 10 +++++----- src/components/select.rs | 2 +- src/lib.rs | 6 +++--- src/utils.rs | 4 ++-- 7 files changed, 38 insertions(+), 18 deletions(-) diff --git a/.cargo/config b/.cargo/config index 83d4da00351..dfc21a02f68 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,7 +1,7 @@ [target.'cfg(not(not(feature = "doc_test")))'] target = 'wasm32-unknown-unknown' -[target.'cfg(all(target_arch = "wasm32", not(cargo_web)))'] +[target.'cfg(target_arch = "wasm32")'] runner = 'wasm-bindgen-test-runner' [alias] diff --git a/Cargo.toml b/Cargo.toml index 7d11785814d..dd582ac65c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ travis-ci = { repository = "yewstack/yew" } anymap = "0.12" bincode = { version = "~1.2.1", optional = true } failure = "0.1" +gloo = { version = "0.2", optional = true } http = "0.2" indexmap = "1.0.2" js-sys = { version = "0.3.33", optional = true } @@ -42,6 +43,10 @@ yew-macro = { version = "0.10.1", path = "crates/macro" } version = "0.3.33" optional = true features = [ + "AbortController", + "AbortSignal", + "BinaryType", + "Blob", "console", "DedicatedWorkerGlobalScope", "Document", @@ -50,8 +55,11 @@ features = [ "Element", "Event", "EventTarget", + "File", "FileList", + "FileReader", "FocusEvent", + "Headers", "HtmlInputElement", "HtmlSelectElement", "HtmlTextAreaElement", @@ -60,20 +68,31 @@ features = [ "MessageEvent", "MouseEvent", "Node", + "ObserverCallback", "PointerEvent", + "ReferrerPolicy", + "Request", + "RequestCache", + "RequestCredentials", + "RequestInit", + "RequestMode", + "RequestRedirect", + "Response", + "Storage", "Text", "TouchEvent", "UiEvent", + "WebSocket", "WheelEvent", "Window", "Worker", ] -[target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dependencies] +[target.'cfg(all(target_arch = "wasm32", not(target_os="wasi")))'.dependencies] wasm-bindgen = "0.2.56" wasm-bindgen-futures = "0.4.4" -[target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dev-dependencies] +[target.'cfg(all(target_arch = "wasm32", not(target_os="wasi")))'.dev-dependencies] wasm-bindgen-test = "0.3.4" [target.'cfg(target_os = "emscripten")'.dependencies] @@ -85,8 +104,9 @@ trybuild = "1.0" rustversion = "1.0" [features] -default = ["services", "agent", "stdweb"] -web_sys = ["web-sys", "js-sys"] +default = ["services", "agent"] +std_web = ["stdweb"] +web_sys = ["gloo", "js-sys", "web-sys"] doc_test = [] web_test = [] wasm_test = [] diff --git a/build.rs b/build.rs index 093d3fa5244..a3c2c5b7b74 100644 --- a/build.rs +++ b/build.rs @@ -1,9 +1,9 @@ use std::env; pub fn main() { - if cfg!(all(feature = "web_sys", feature = "stdweb")) { + if cfg!(all(feature = "web_sys", feature = "std_web")) { panic!("don't use `web_sys` and `stdweb` simultaneously") - } else if cfg!(not(any(feature = "web_sys", feature = "stdweb"))) { + } else if cfg!(not(any(feature = "web_sys", feature = "std_web"))) { panic!("please select either `web_sys` or `stdweb`") } diff --git a/src/app.rs b/src/app.rs index 0e6a254ce3a..295ae11b0ef 100644 --- a/src/app.rs +++ b/src/app.rs @@ -2,7 +2,7 @@ //! a component in an isolated scope. use crate::html::{Component, NodeRef, Scope}; -#[cfg(feature = "stdweb")] +#[cfg(feature = "std_web")] use stdweb::web::{document, Element, INode, IParentNode}; #[cfg(feature = "web_sys")] use web_sys::Element; @@ -45,7 +45,7 @@ where /// Alias to `mount("body", ...)`. pub fn mount_to_body(self) -> Scope { - #[cfg(feature = "stdweb")] + #[cfg(feature = "std_web")] let document = document(); #[cfg(feature = "web_sys")] let document = web_sys::window().unwrap().document().unwrap(); @@ -63,7 +63,7 @@ where /// need to manipulate the body element. For example, adding/removing app-wide /// CSS classes of the body element. pub fn mount_as_body(self) -> Scope { - #[cfg(feature = "stdweb")] + #[cfg(feature = "std_web")] let document = document(); #[cfg(feature = "web_sys")] let document = web_sys::window().unwrap().document().unwrap(); @@ -110,7 +110,7 @@ where /// Alias to `mount_with_props("body", ...)`. pub fn mount_to_body_with_props(self, props: COMP::Properties) -> Scope { - #[cfg(feature = "stdweb")] + #[cfg(feature = "std_web")] let document = document(); #[cfg(feature = "web_sys")] let document = web_sys::window().unwrap().document().unwrap(); @@ -128,7 +128,7 @@ where /// when you need to manipulate the body element. For example, adding/removing app-wide /// CSS classes of the body element. pub fn mount_as_body_with_props(self, props: COMP::Properties) -> Scope { - #[cfg(feature = "stdweb")] + #[cfg(feature = "std_web")] let document = document(); #[cfg(feature = "web_sys")] let document = web_sys::window().unwrap().document().unwrap(); diff --git a/src/components/select.rs b/src/components/select.rs index d4a3a87178d..cb919f2782c 100644 --- a/src/components/select.rs +++ b/src/components/select.rs @@ -122,7 +122,7 @@ where self.link.callback(|event| match event { ChangeData::Select(elem) => { let value = elem.selected_index(); - #[cfg(feature = "stdweb")] + #[cfg(feature = "std_web")] let value = value.map(|x| x as usize); #[cfg(feature = "web_sys")] let value = Some(value as usize); diff --git a/src/lib.rs b/src/lib.rs index 584d88917d6..9c1b6a8bec1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -96,7 +96,7 @@ pub mod services; pub mod events { pub use crate::html::{ChangeData, InputData}; - #[cfg(feature = "stdweb")] + #[cfg(feature = "std_web")] pub use stdweb::web::event::{ BlurEvent, ClickEvent, ContextMenuEvent, DoubleClickEvent, DragDropEvent, DragEndEvent, DragEnterEvent, DragEvent, DragExitEvent, DragLeaveEvent, DragOverEvent, DragStartEvent, @@ -116,13 +116,13 @@ pub mod events { /// Initializes yew framework. It should be called first. pub fn initialize() { - #[cfg(feature = "stdweb")] + #[cfg(feature = "std_web")] stdweb::initialize(); } /// Starts event loop. pub fn run_loop() { - #[cfg(feature = "stdweb")] + #[cfg(feature = "std_web")] stdweb::event_loop(); } diff --git a/src/utils.rs b/src/utils.rs index 14c2f195050..ed4c36d7681 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -3,12 +3,12 @@ use failure::err_msg; #[allow(unused_imports)] use failure::Error; -#[cfg(feature = "stdweb")] +#[cfg(feature = "std_web")] use stdweb::web::document; /// Returns `host` for the current document. Useful to connect to a server that server the app. pub fn host() -> Result { - #[cfg(feature = "stdweb")] + #[cfg(feature = "std_web")] { document() .location() From e56648d1673ba90a36736e0cd23f00eee290c12c Mon Sep 17 00:00:00 2001 From: daxpedda Date: Tue, 31 Dec 2019 15:45:33 +0100 Subject: [PATCH 4/8] Move tests and examples to different PR. --- Cargo.toml | 4 ++-- src/utils.rs | 4 +--- tests/vtag_test.rs | 15 ++------------- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dd582ac65c8..364f56b84ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ failure = "0.1" gloo = { version = "0.2", optional = true } http = "0.2" indexmap = "1.0.2" -js-sys = { version = "0.3.33", optional = true } +js-sys = { version = "0.3", optional = true } log = "0.4" proc-macro-hack = "0.5" proc-macro-nested = "0.1" @@ -40,7 +40,7 @@ toml = { version = "0.5", optional = true } yew-macro = { version = "0.10.1", path = "crates/macro" } [dependencies.web-sys] -version = "0.3.33" +version = "0.3" optional = true features = [ "AbortController", diff --git a/src/utils.rs b/src/utils.rs index ed4c36d7681..62f24e15bf1 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,8 +1,6 @@ //! This module contains useful utils to get information about the current document. -use failure::err_msg; -#[allow(unused_imports)] -use failure::Error; +use failure::{err_msg, Error}; #[cfg(feature = "std_web")] use stdweb::web::document; diff --git a/tests/vtag_test.rs b/tests/vtag_test.rs index 6af412d352c..94c6b687cb2 100644 --- a/tests/vtag_test.rs +++ b/tests/vtag_test.rs @@ -1,5 +1,4 @@ #![recursion_limit = "128"] -#[cfg(feature = "stdweb")] use stdweb::web::{document, IElement}; #[cfg(feature = "wasm_test")] use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure}; @@ -271,18 +270,8 @@ fn assert_namespace(vtag: &VTag, namespace: &'static str) { #[test] fn supports_svg() { - #[cfg(feature = "stdweb")] - let document = document(); - #[cfg(feature = "web_sys")] - let document = web_sys::window().unwrap().document().unwrap(); - - let div_el = document.create_element("div").unwrap(); - #[cfg(feature = "stdweb")] - let svg_el = document.create_element_ns(SVG_NAMESPACE, "svg").unwrap(); - #[cfg(feature = "web_sys")] - let svg_el = document - .create_element_ns(Some(SVG_NAMESPACE), "svg") - .unwrap(); + let div_el = document().create_element("div").unwrap(); + let svg_el = document().create_element_ns(SVG_NAMESPACE, "svg").unwrap(); let mut g_node = html! { }; let path_node = html! { }; From 6ab65cd9143a980c9570b8dbab4775f103ebcadc Mon Sep 17 00:00:00 2001 From: daxpedda Date: Wed, 1 Jan 2020 23:28:15 +0100 Subject: [PATCH 5/8] Revert some `cargo_web` handling removal. --- .cargo/config | 2 +- Cargo.toml | 2 +- build.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.cargo/config b/.cargo/config index dfc21a02f68..83d4da00351 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,7 +1,7 @@ [target.'cfg(not(not(feature = "doc_test")))'] target = 'wasm32-unknown-unknown' -[target.'cfg(target_arch = "wasm32")'] +[target.'cfg(all(target_arch = "wasm32", not(cargo_web)))'] runner = 'wasm-bindgen-test-runner' [alias] diff --git a/Cargo.toml b/Cargo.toml index 364f56b84ea..999cf40ddf3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -88,7 +88,7 @@ features = [ "Worker", ] -[target.'cfg(all(target_arch = "wasm32", not(target_os="wasi")))'.dependencies] +[target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dependencies] wasm-bindgen = "0.2.56" wasm-bindgen-futures = "0.4.4" diff --git a/build.rs b/build.rs index a3c2c5b7b74..437ea43a5d1 100644 --- a/build.rs +++ b/build.rs @@ -2,9 +2,9 @@ use std::env; pub fn main() { if cfg!(all(feature = "web_sys", feature = "std_web")) { - panic!("don't use `web_sys` and `stdweb` simultaneously") + panic!("don't use `web_sys` and `std_web` simultaneously") } else if cfg!(not(any(feature = "web_sys", feature = "std_web"))) { - panic!("please select either `web_sys` or `stdweb`") + panic!("please select either `web_sys` or `std_web`") } let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default(); From f5b266f00c1f9b141d61e2150ce01889edfcc5b7 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Wed, 1 Jan 2020 23:34:37 +0100 Subject: [PATCH 6/8] Missed something. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 999cf40ddf3..977cf9ea969 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -92,7 +92,7 @@ features = [ wasm-bindgen = "0.2.56" wasm-bindgen-futures = "0.4.4" -[target.'cfg(all(target_arch = "wasm32", not(target_os="wasi")))'.dev-dependencies] +[target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dev-dependencies] wasm-bindgen-test = "0.3.4" [target.'cfg(target_os = "emscripten")'.dependencies] From 4660a712c4436e742b32622a58dbbc2c6923dc32 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Sat, 4 Jan 2020 01:02:55 +0100 Subject: [PATCH 7/8] Implement `console_error_panic_hook`. --- Cargo.toml | 7 +++++-- src/lib.rs | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 977cf9ea969..e348b3b9e5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ travis-ci = { repository = "yewstack/yew" } [dependencies] anymap = "0.12" bincode = { version = "~1.2.1", optional = true } +console_error_panic_hook = { version = "0.1", optional = true } failure = "0.1" gloo = { version = "0.2", optional = true } http = "0.2" @@ -60,6 +61,7 @@ features = [ "FileReader", "FocusEvent", "Headers", + "HtmlElement", "HtmlInputElement", "HtmlSelectElement", "HtmlTextAreaElement", @@ -86,9 +88,10 @@ features = [ "WheelEvent", "Window", "Worker", + "WorkerOptions", ] -[target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dependencies] +[target.'cfg(all(not(target_os="wasi"), not(cargo_web)))'.dependencies] wasm-bindgen = "0.2.56" wasm-bindgen-futures = "0.4.4" @@ -106,7 +109,7 @@ rustversion = "1.0" [features] default = ["services", "agent"] std_web = ["stdweb"] -web_sys = ["gloo", "js-sys", "web-sys"] +web_sys = ["console_error_panic_hook", "gloo", "js-sys", "web-sys"] doc_test = [] web_test = [] wasm_test = [] diff --git a/src/lib.rs b/src/lib.rs index 9c1b6a8bec1..08e247834f8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -118,6 +118,8 @@ pub mod events { pub fn initialize() { #[cfg(feature = "std_web")] stdweb::initialize(); + #[cfg(feature = "web_sys")] + std::panic::set_hook(Box::new(console_error_panic_hook::hook)); } /// Starts event loop. From e4a53ee7e77e1f3e1962edd98549acff82372f22 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Wed, 8 Jan 2020 14:37:49 +0800 Subject: [PATCH 8/8] Update Cargo.toml --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index e348b3b9e5a..d56df56bce1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -91,7 +91,7 @@ features = [ "WorkerOptions", ] -[target.'cfg(all(not(target_os="wasi"), not(cargo_web)))'.dependencies] +[target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dependencies] wasm-bindgen = "0.2.56" wasm-bindgen-futures = "0.4.4"