codify "platform" into resolution logic, server-fn/fullstack overhaul (#4596)
overhaul dioxus fullstack using a new implementation of server_fn This PR is a complete rewrite of dioxus fullstack designed to improve compatibility with axum and to fix a number of compilation errors based on feature flag unification plumbing through macros.
This commit is contained in:
1 parent
8421c3aef0
commit
f2b1c6d97f
424 files changed
+17284
-6624
No files matched your search
@@ -0,0 +1,47 @@
|
||||
//! This example shows how to use the `eval` function to run JavaScript code in the webview.
|
||||
//!
|
||||
//! Eval will only work with renderers that support javascript - so currently only the web and desktop/mobile renderers
|
||||
//! that use a webview. Native renderers will throw "unsupported" errors when calling `eval`.
|
||||
|
||||
use async_std::task::sleep;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
dioxus::launch(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
// Create a future that will resolve once the javascript has been successfully executed.
|
||||
let future = use_resource(move || async move {
|
||||
// Wait a little bit just to give the appearance of a loading screen
|
||||
sleep(std::time::Duration::from_secs(1)).await;
|
||||
|
||||
// The `eval` is available in the prelude - and simply takes a block of JS.
|
||||
// Dioxus' eval is interesting since it allows sending messages to and from the JS code using the `await dioxus.recv()`
|
||||
// builtin function. This allows you to create a two-way communication channel between Rust and JS.
|
||||
let mut eval = document::eval(
|
||||
r#"
|
||||
dioxus.send("Hi from JS!");
|
||||
let msg = await dioxus.recv();
|
||||
console.log(msg);
|
||||
return "hi from JS!";
|
||||
"#,
|
||||
);
|
||||
|
||||
// Send a message to the JS code.
|
||||
eval.send("Hi from Rust!").unwrap();
|
||||
|
||||
// Our line on the JS side will log the message and then return "hello world".
|
||||
let res: String = eval.recv().await.unwrap();
|
||||
|
||||
// This will print "Hi from JS!" and "Hi from Rust!".
|
||||
println!("{:?}", eval.await);
|
||||
|
||||
res
|
||||
});
|
||||
|
||||
match future.value().as_ref() {
|
||||
Some(v) => rsx!( p { "{v}" } ),
|
||||
_ => rsx!( p { "waiting.." } ),
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user