Skip to content

Commit 108f952

Browse files
feat: remove more references to stdweb
1 parent da7b29a commit 108f952

File tree

15 files changed

+45
-189
lines changed

15 files changed

+45
-189
lines changed

packages/yew/build.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1 @@
1-
use std::env;
2-
3-
pub fn main() {
4-
let using_web_sys = cfg!(feature = "web_sys");
5-
let using_std_web = cfg!(feature = "std_web");
6-
if using_web_sys && using_std_web {
7-
panic!("Yew does not allow the `web_sys` and `std_web` cargo features to be used simultaneously");
8-
} else if !using_web_sys && !using_std_web {
9-
panic!("Yew requires selecting either the `web_sys` or `std_web` cargo feature");
10-
}
11-
12-
let using_cargo_web = env::var("COMPILING_UNDER_CARGO_WEB").is_ok();
13-
if using_cargo_web && using_web_sys {
14-
panic!("cargo-web is not compatible with web-sys");
15-
}
16-
}
1+
pub fn main() {}

packages/yew/src/agent/worker/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,8 @@ enum FromWorker<T> {
6262
ProcessOutput(HandlerId, T),
6363
}
6464

65-
fn send_to_remote<AGN>(
66-
#[cfg(feature = "std_web")] worker: &Value,
67-
#[cfg(feature = "web_sys")] worker: &Worker,
68-
msg: ToWorker<AGN::Input>,
69-
) where
65+
fn send_to_remote<AGN>(worker: &Worker, msg: ToWorker<AGN::Input>)
66+
where
7067
AGN: Agent,
7168
<AGN as Agent>::Input: Serialize + for<'de> Deserialize<'de>,
7269
<AGN as Agent>::Output: Serialize + for<'de> Deserialize<'de>,

packages/yew/src/agent/worker/private.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,7 @@ use queue::Queue;
66
use std::fmt;
77
use std::marker::PhantomData;
88
use std::sync::atomic::{AtomicUsize, Ordering};
9-
cfg_if! {
10-
if #[cfg(feature = "std_web")] {
11-
use stdweb::Value;
12-
#[allow(unused_imports)]
13-
use stdweb::{_js_impl, js};
14-
} else if #[cfg(feature = "web_sys")] {
15-
use web_sys::{Worker};
16-
}
17-
}
9+
use web_sys::Worker;
1810

1911
thread_local! {
2012
static QUEUE: Queue<usize> = Queue::new();
@@ -40,9 +32,7 @@ where
4032
fn spawn_or_join(callback: Option<Callback<AGN::Output>>) -> Box<dyn Bridge<AGN>> {
4133
let id = PRIVATE_ID_COUNTER.fetch_add(1, Ordering::Relaxed);
4234
let callback = callback.expect("Callback required for Private agents");
43-
let handler = move |data: Vec<u8>,
44-
#[cfg(feature = "std_web")] worker: Value,
45-
#[cfg(feature = "web_sys")] worker: &Worker| {
35+
let handler = move |data: Vec<u8>, worker: &Worker| {
4636
let msg = FromWorker::<AGN::Output>::unpack(&data);
4737
match msg {
4838
FromWorker::WorkerLoaded => {
@@ -88,9 +78,6 @@ where
8878
<AGN as Agent>::Input: Serialize + for<'de> Deserialize<'de>,
8979
<AGN as Agent>::Output: Serialize + for<'de> Deserialize<'de>,
9080
{
91-
#[cfg(feature = "std_web")]
92-
worker: Value,
93-
#[cfg(feature = "web_sys")]
9481
worker: Worker,
9582
_agent: PhantomData<AGN>,
9683
id: usize,

packages/yew/src/agent/worker/public.rs

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::WorkerExt;
12
use super::*;
23
use crate::callback::Callback;
34
use crate::scheduler::Shared;
@@ -11,16 +12,7 @@ use std::cell::RefCell;
1112
use std::fmt;
1213
use std::marker::PhantomData;
1314
use std::rc::Rc;
14-
cfg_if! {
15-
if #[cfg(feature = "std_web")] {
16-
use stdweb::Value;
17-
#[allow(unused_imports)]
18-
use stdweb::{_js_impl, js};
19-
} else if #[cfg(feature = "web_sys")] {
20-
use super::WorkerExt;
21-
use web_sys::{Worker};
22-
}
23-
}
15+
use web_sys::Worker;
2416

2517
thread_local! {
2618
static REMOTE_AGENTS_POOL: RefCell<AnyMap> = RefCell::new(AnyMap::new());
@@ -51,9 +43,7 @@ where
5143
Rc::new(RefCell::new(Slab::new()));
5244
let handler = {
5345
let slab = slab.clone();
54-
move |data: Vec<u8>,
55-
#[cfg(feature = "std_web")] worker: Value,
56-
#[cfg(feature = "web_sys")] worker: &Worker| {
46+
move |data: Vec<u8>, worker: &Worker| {
5747
let msg = FromWorker::<AGN::Output>::unpack(&data);
5848
match msg {
5949
FromWorker::WorkerLoaded => {
@@ -108,9 +98,6 @@ where
10898
<AGN as Agent>::Input: Serialize + for<'de> Deserialize<'de>,
10999
<AGN as Agent>::Output: Serialize + for<'de> Deserialize<'de>,
110100
{
111-
#[cfg(feature = "std_web")]
112-
worker: Value,
113-
#[cfg(feature = "web_sys")]
114101
worker: Worker,
115102
id: HandlerId,
116103
_agent: PhantomData<AGN>,
@@ -259,9 +246,6 @@ where
259246
<AGN as Agent>::Input: Serialize + for<'de> Deserialize<'de>,
260247
<AGN as Agent>::Output: Serialize + for<'de> Deserialize<'de>,
261248
{
262-
#[cfg(feature = "std_web")]
263-
worker: Value,
264-
#[cfg(feature = "web_sys")]
265249
worker: Worker,
266250
slab: SharedOutputSlab<AGN>,
267251
}
@@ -272,11 +256,7 @@ where
272256
<AGN as Agent>::Input: Serialize + for<'de> Deserialize<'de>,
273257
<AGN as Agent>::Output: Serialize + for<'de> Deserialize<'de>,
274258
{
275-
pub fn new(
276-
#[cfg(feature = "std_web")] worker: Value,
277-
#[cfg(feature = "web_sys")] worker: Worker,
278-
slab: SharedOutputSlab<AGN>,
279-
) -> Self {
259+
pub fn new(worker: Worker, slab: SharedOutputSlab<AGN>) -> Self {
280260
RemoteAgent { worker, slab }
281261
}
282262

packages/yew/src/html/component/lifecycle.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@ use crate::scheduler::{scheduler, ComponentRunnableType, Runnable, Shared};
55
use crate::virtual_dom::{VDiff, VNode};
66
use crate::NodeRef;
77
use cfg_if::cfg_if;
8-
cfg_if! {
9-
if #[cfg(feature = "std_web")] {
10-
use stdweb::web::Element;
11-
} else if #[cfg(feature = "web_sys")] {
12-
use web_sys::Element;
13-
}
14-
}
8+
use web_sys::Element;
159

1610
pub(crate) struct ComponentState<COMP: Component> {
1711
parent: Element,

packages/yew/src/html/component/scope.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,12 @@ use crate::callback::Callback;
88
use crate::html::NodeRef;
99
use crate::scheduler::{scheduler, Shared};
1010
use crate::virtual_dom::VNode;
11-
use cfg_if::cfg_if;
1211
use std::any::{Any, TypeId};
1312
use std::cell::{Ref, RefCell};
1413
use std::fmt;
1514
use std::ops::Deref;
1615
use std::rc::Rc;
17-
cfg_if! {
18-
if #[cfg(feature = "std_web")] {
19-
use stdweb::web::Element;
20-
} else if #[cfg(feature = "web_sys")] {
21-
use web_sys::Element;
22-
}
23-
}
16+
use web_sys::Element;
2417

2518
/// Untyped scope used for accessing parent scope
2619
#[derive(Debug, Clone)]

packages/yew/src/html/listener/macros.rs

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,9 @@ macro_rules! impl_action {
1313
#[allow(unused_imports)]
1414
use crate::html::listener::*;
1515
use crate::virtual_dom::Listener;
16-
cfg_if! {
17-
if #[cfg(feature = "std_web")] {
18-
use stdweb::web::event::$type;
19-
use stdweb::web::{Element, IEventTarget};
20-
} else if #[cfg(feature = "web_sys")] {
21-
use gloo::events::{EventListener, EventListenerOptions};
22-
use wasm_bindgen::JsValue;
23-
use web_sys::{$type as WebSysType, Element, EventTarget};
24-
}
25-
}
16+
use gloo::events::{EventListener, EventListenerOptions};
17+
use wasm_bindgen::JsValue;
18+
use web_sys::{$type as WebSysType, Element, EventTarget};
2619

2720
/// A wrapper for a callback which attaches event listeners to elements.
2821
#[derive(Clone, Debug)]
@@ -49,25 +42,18 @@ macro_rules! impl_action {
4942
let this = element.clone();
5043
let callback = self.callback.clone();
5144
let listener = move |
52-
#[cfg(feature = "std_web")] event: $type,
53-
#[cfg(feature = "web_sys")] event: &web_sys::Event
45+
event: &web_sys::Event
5446
| {
55-
#[cfg(feature = "web_sys")]
5647
let event: WebSysType = JsValue::from(event).into();
5748
callback.emit($convert(&this, event));
5849
};
59-
cfg_match! {
60-
feature = "std_web" => EventListener(Some(element.add_event_listener(listener))),
61-
feature = "web_sys" => ({
62-
// We should only set passive event listeners for `touchstart` and `touchmove`.
63-
// See here: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Improving_scrolling_performance_with_passive_listeners
64-
if $name == "touchstart" || $name == "touchmove" {
65-
EventListener::new(&EventTarget::from(element.clone()), $name, listener)
66-
} else {
67-
let options = EventListenerOptions::enable_prevent_default();
68-
EventListener::new_with_options(&EventTarget::from(element.clone()), $name, options, listener)
69-
}
70-
}),
50+
// We should only set passive event listeners for `touchstart` and `touchmove`.
51+
// See here: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Improving_scrolling_performance_with_passive_listeners
52+
if $name == "touchstart" || $name == "touchmove" {
53+
EventListener::new(&EventTarget::from(element.clone()), $name, listener)
54+
} else {
55+
let options = EventListenerOptions::enable_prevent_default();
56+
EventListener::new_with_options(&EventTarget::from(element.clone()), $name, options, listener)
7157
}
7258
}
7359
}

packages/yew/src/html/mod.rs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,8 @@ use cfg_if::cfg_if;
1313
use cfg_match::cfg_match;
1414
use std::cell::RefCell;
1515
use std::rc::Rc;
16-
cfg_if! {
17-
if #[cfg(feature = "std_web")] {
18-
use stdweb::unstable::TryFrom;
19-
use stdweb::web::Node;
20-
} else if #[cfg(feature = "web_sys")] {
21-
use wasm_bindgen::JsValue;
22-
use web_sys::Node;
23-
}
24-
}
16+
use wasm_bindgen::JsValue;
17+
use web_sys::Node;
2518

2619
/// A type which expected as a result of `view` function implementation.
2720
pub type Html = VNode;
@@ -31,9 +24,6 @@ pub type Html = VNode;
3124
/// # Example
3225
/// Focus an `<input>` element on mount.
3326
/// ```
34-
/// #[cfg(feature = "std_web")]
35-
/// use stdweb::web::{html_element::InputElement, IHtmlElement};
36-
/// #[cfg(feature = "web_sys")]
3727
/// use web_sys::HtmlInputElement as InputElement;
3828
///# use yew::prelude::*;
3929
///
@@ -96,17 +86,9 @@ impl NodeRef {
9686
}
9787

9888
/// Try converting the node reference into another form
99-
pub fn cast<
100-
#[cfg(feature = "std_web")] INTO: TryFrom<Node>,
101-
#[cfg(feature = "web_sys")] INTO: AsRef<Node> + From<JsValue>,
102-
>(
103-
&self,
104-
) -> Option<INTO> {
89+
pub fn cast<INTO: AsRef<Node> + From<JsValue>>(&self) -> Option<INTO> {
10590
let node = self.get();
106-
cfg_match! {
107-
feature = "std_web" => node.and_then(|node| INTO::try_from(node).ok()),
108-
feature = "web_sys" => node.map(Into::into).map(INTO::from),
109-
}
91+
node.map(Into::into).map(INTO::from)
11092
}
11193

11294
/// Wrap an existing `Node` in a `NodeRef`

packages/yew/src/services/console.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,8 @@
22
33
use cfg_if::cfg_if;
44
use cfg_match::cfg_match;
5-
cfg_if! {
6-
if #[cfg(feature = "std_web")] {
7-
#[allow(unused_imports)]
8-
use stdweb::{_js_impl, js};
9-
} else if #[cfg(feature = "web_sys")] {
10-
use wasm_bindgen::JsValue;
11-
use web_sys::console;
12-
}
13-
}
5+
use wasm_bindgen::JsValue;
6+
use web_sys::console;
147

158
/// A service to use methods of a
169
/// [Console](https://developer.mozilla.org/en-US/docs/Web/API/Console).

packages/yew/src/services/dialog.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl DialogService {
2828
/// Prompts the user to input a message. In most browsers this will open an alert box with
2929
/// an input field where the user can input a message.
3030
#[cfg_attr(
31-
doc = "A default value can be supplied which will be returned if the user doesn't input anything.",
31+
doc = "A default value can be supplied which will be returned if the user doesn't input anything."
3232
)]
3333
///
3434
/// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Window/prompt)
@@ -43,7 +43,7 @@ impl DialogService {
4343
#[cfg_attr(
4444
doc = "This function will return `None` if the value of `default` is `None` and the user \
4545
cancels the operation. (normally a 'cancel' button will be displayed to the user, \
46-
clicking which cancels the operation).",
46+
clicking which cancels the operation)."
4747
)]
4848
pub fn prompt(message: &str, default: Option<&str>) -> Option<String> {
4949
if let Some(default) = default {

0 commit comments

Comments
 (0)