1
0

eval.rs 871 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. use dioxus::prelude::*;
  2. fn main() {
  3. dioxus_desktop::launch(app);
  4. }
  5. fn app(cx: Scope) -> Element {
  6. let eval_provider = use_eval(cx);
  7. let future = use_future(cx, (), |_| {
  8. to_owned![eval_provider];
  9. async move {
  10. let eval = eval_provider(
  11. r#"
  12. dioxus.send("Hi from JS!");
  13. let msg = await dioxus.recv();
  14. console.log(msg);
  15. return "hello world";
  16. "#,
  17. )
  18. .unwrap();
  19. eval.send("Hi from Rust!".into()).unwrap();
  20. let res = eval.recv().await.unwrap();
  21. println!("{:?}", eval.await);
  22. res
  23. }
  24. });
  25. match future.value() {
  26. Some(v) => cx.render(rsx!(
  27. p { "{v}" }
  28. )),
  29. _ => cx.render(rsx!(
  30. p { "hello" }
  31. )),
  32. }
  33. }