Convert use_eval to use send/recv system (#1080)

* progress: reworked

don't run this, it'll kill your web browser

* feat: use_eval but with comms

* revision: async recv & recv_sync

* revision: use_eval

* revision: standard eval interface

* revision: use serde_json::Value instead of JsValue

* revision: docs

* revision: error message

* create: desktop eval (wip)

* fix: desktop eval

* revision: wrap use_eval in Rc<RefCell<_>>

* fix: fmt, clippy

* fix: desktop tests

* revision: change to channel system

- fixes clippy errors
- fixes playwright tests

* fix: tests

* fix: eval example

* fix: fmt

* fix: tests, desktop stuff

* fix: tests

* feat: drop handler

* fix: tests

* fix: rustfmt

* revision: web promise/callback system

* fix: recv error

* revision: IntoFuture, functionation

* fix: ci

* revision: playwright web

* remove: unescessary code

* remove dioxus-html from public examples

* prototype-patch

* fix web eval

* fix: rustfmt

* fix: CI

* make use_eval more efficient

* implement eval for liveview as well

* fix playwright tests

* fix clippy

* more clippy fixes

* fix clippy

* fix stack overflow

* fix desktop mock

* fix clippy

---------

Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
This commit is contained in:
Miles MurgawandEvan Almloff authored and GitHub committed 2023-07-21 17:36:25 -05:00
1 parent b36a7a3993
commit 6210c6fefe
31 files changed
+1025 -410

No files matched your search

+16 -9
View File
@@ -1,13 +1,13 @@
// This test is used by playwright configured in the root of the repo
use dioxus::prelude::*;
use dioxus_web::use_eval;
fn app(cx: Scope) -> Element {
let mut num = use_state(cx, || 0);
let eval = use_eval(cx);
let eval_result = use_state(cx, String::new);
let eval_provider = dioxus_html::prelude::use_eval(cx);
cx.render(rsx! {
div {
"hello axum! {num}"
@@ -42,13 +42,20 @@ fn app(cx: Scope) -> Element {
button {
class: "eval-button",
onclick: move |_| {
// Set the window title
let result = eval(r#"window.document.title = 'Hello from Dioxus Eval!';
return "returned eval value";"#.to_string());
if let Ok(serde_json::Value::String(string)) = result.get() {
eval_result.set(string);
}
},
let eval = eval_provider(
r#"
window.document.title = 'Hello from Dioxus Eval!';
dioxus.send("returned eval value");
"#).unwrap();
let setter = eval_result.setter();
async move {
// Set the window title
let result = eval.recv().await;
if let Ok(serde_json::Value::String(string)) = result {
setter(string);
}
}},
"Eval"
}
div {