make the closure dyn

This commit is contained in:
Ilya Maximov committed 2022-03-21 21:57:29 +01:00
1 parent c194fa8372
commit 6e8fdc1e4d
2 files changed
+11 -9

No files matched your search

+3 -3
View File
@@ -200,8 +200,8 @@ pub(super) fn handler(
} }
/// Get a closure that executes any JavaScript in the WebView context. /// Get a closure that executes any JavaScript in the WebView context.
pub fn use_eval<S: std::string::ToString>(cx: &ScopeState) -> impl Fn(S) + '_ { pub fn use_eval<S: std::string::ToString>(cx: &ScopeState) -> &dyn Fn(S) {
let desktop = use_window(&cx); let desktop = use_window(&cx).clone();
move |script| desktop.eval(script) cx.use_hook(|_| move |script| desktop.eval(script))
} }
+8 -6
View File
@@ -15,10 +15,12 @@ use dioxus_core::*;
/// ///
/// The closure will panic if the provided script is not valid JavaScript code /// The closure will panic if the provided script is not valid JavaScript code
/// or if it returns an uncaught error. /// or if it returns an uncaught error.
pub fn use_eval<S: std::string::ToString>(_cx: &ScopeState) -> impl Fn(S) { pub fn use_eval<S: std::string::ToString>(cx: &ScopeState) -> &dyn Fn(S) {
|script| { cx.use_hook(|_| {
js_sys::Function::new_no_args(&script.to_string()) |script: S| {
.call0(&wasm_bindgen::JsValue::NULL) js_sys::Function::new_no_args(&script.to_string())
.expect("failed to eval script"); .call0(&wasm_bindgen::JsValue::NULL)
} .expect("failed to eval script");
}
})
} }