Skip to content

Commit

Permalink
Second attempt to remove wasm-bindgen-futures.
Browse files Browse the repository at this point in the history
  • Loading branch information
futursolo committed May 23, 2022
1 parent 268cf57 commit 92ebe1a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 5 additions & 1 deletion packages/yew/Cargo.toml
Expand Up @@ -32,7 +32,6 @@ html-escape = { version = "0.2.9", optional = true }
base64ct = { version = "1.5.0", features = ["std"], optional = true }
bincode = { version = "1.3.3", optional = true }
serde = { version = "1", features = ["derive"] }
wasm-bindgen-futures = "0.4"

[dependencies.web-sys]
version = "0.3"
Expand Down Expand Up @@ -68,6 +67,11 @@ features = [
"HtmlScriptElement",
]

[target.'cfg(target_arch = "wasm32")'.dependencies]
# we move it here so no promise-based spawn_local can present for
# non-wasm32 targets.
wasm-bindgen-futures = "0.4"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1.15.0", features = ["rt"], optional = true }

Expand Down
Expand Up @@ -3,19 +3,22 @@
use std::marker::PhantomData;
use std::rc::Rc;

use gloo_utils::window;
use js_sys::Uint8Array;
use serde::de::DeserializeOwned;
use serde::Serialize;
use wasm_bindgen::{JsCast, JsValue};
use wasm_bindgen_futures::JsFuture;
use wasm_bindgen::JsValue;

use super::PreparedStateBase;
use crate::functional::{use_state, Hook, HookContext};
use crate::io_coop::spawn_local;
use crate::suspense::{Suspension, SuspensionResult};

#[cfg(target_arch = "wasm32")]
async fn decode_base64(s: &str) -> Result<Vec<u8>, JsValue> {
use gloo_utils::window;
use js_sys::Uint8Array;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::JsFuture;

let fetch_promise = window().fetch_with_str(s);

let content_promise = JsFuture::from(fetch_promise)
Expand All @@ -31,6 +34,11 @@ async fn decode_base64(s: &str) -> Result<Vec<u8>, JsValue> {
Ok(content_array.to_vec())
}

#[cfg(not(target_arch = "wasm32"))]
async fn decode_base64(_s: &str) -> Result<Vec<u8>, JsValue> {
unreachable!("this function is not callable under non-wasm targets!");
}

#[doc(hidden)]
pub fn use_prepared_state<T, D>(deps: D) -> impl Hook<Output = SuspensionResult<Option<Rc<T>>>>
where
Expand Down

0 comments on commit 92ebe1a

Please sign in to comment.