mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 14:54:16 +00:00
fix: remove need for inline JS for queue_microtask
(#1129)
This commit is contained in:
parent
53e09279a2
commit
84e8922aa6
1 changed files with 8 additions and 10 deletions
|
@ -1,8 +1,4 @@
|
|||
// `queue_microtask` needs to be in its own module, which is the only thing
|
||||
// in this entire framework that requires "unsafe" code (because Rust seems to
|
||||
// that a `wasm_bindgen` imported function like this is unsafe)
|
||||
// this is stupid, and one day hopefully web_sys will add queue_microtask itself
|
||||
|
||||
#![forbid(unsafe_code)]
|
||||
use cfg_if::cfg_if;
|
||||
|
||||
cfg_if! {
|
||||
|
@ -14,11 +10,13 @@ cfg_if! {
|
|||
}
|
||||
|
||||
#[cfg(any(feature = "csr", feature = "hydrate"))]
|
||||
#[wasm_bindgen::prelude::wasm_bindgen(
|
||||
inline_js = "export function microtask(f) { queueMicrotask(f); }"
|
||||
)]
|
||||
extern "C" {
|
||||
fn microtask(task: wasm_bindgen::JsValue);
|
||||
fn microtask(task: wasm_bindgen::JsValue) {
|
||||
use js_sys::{Reflect, Function};
|
||||
use wasm_bindgen::prelude::*;
|
||||
let window = web_sys::window().expect("window not available");
|
||||
let queue_microtask = Reflect::get(&window, &JsValue::from_str("queueMicrotask")).expect("queueMicrotask not available");
|
||||
let queue_microtask = queue_microtask.unchecked_into::<Function>();
|
||||
let _ = queue_microtask.call0(&task);
|
||||
}
|
||||
} else {
|
||||
/// Exposes the [`queueMicrotask`](https://developer.mozilla.org/en-US/docs/Web/API/queueMicrotask) method
|
||||
|
|
Loading…
Reference in a new issue