Skip to content

Conversation

mcmah309
Copy link
Contributor

@mcmah309 mcmah309 commented Jun 21, 2025

Adds a call_js! macro to simplifies calling a javascript function with arguments and returning a value.

e.g.

let value = call_js!("assets/example.js", greeting(from, to)).await.unwrap();

It also validates the js in assets/example.js is valid, the function e.g. greeting exists, is exported, and the number of arguments in the call are correct at compile time.

Edit:
Alternative syntax's to consider

let value = call_js!("assets/example.js"::greeting(from, to)).await.unwrap();
let value = call_js!(
    #[source("assets/example.js")]
    greeting(from, to)
).await.unwrap();

@mcmah309
Copy link
Contributor Author

mcmah309 commented Jun 21, 2025

I also thought of this, it might be might be nice to create compile time function(s). Since we are already doing introspection, we know the number of arguments needed and this is possible:

use_js!("assets/example.js"::greeting)
// or use_js!("assets/example.js::*")

fn main() {
    let value = greeting(from, to).await.unwrap();
}

mcmah309 added a commit to mcmah309/dioxus that referenced this pull request Jun 22, 2025
@mcmah309
Copy link
Contributor Author

mcmah309 commented Jun 22, 2025

I ended up working on the use_js! macro and created a PR for it in the dioxus repo DioxusLabs/dioxus#4309

If merged, this can then be closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant