Open ivnsch opened 3 years ago
I think youre looking for the Wasm-Bindgen Reference. Btw, I think your approach is problematic. Either you want to declare the JS-Function with a JS-Snippet/Inline-JS or you want to give a Callback to the Rust-Funktion.
There seems to be something problematic with wasm-bindgen (used with webpack?). See https://github.com/rustwasm/wasm-bindgen/issues/2375#issuecomment-736861169
I'm trying to adapt the tutorial to call user-defined JS (instead of
alert
) from Rust:index.js:
lib.rs:
wasm-pack build
runs fine. But running the web project (npm run start
) can't resolve the import anymore:It works before introducing the circular dependency.
It would be great if you could add an example of this to the tutorial (use case allowing of course). This flow (call Rust, which calls JS back) should be used frequently and it surprisingly hard to find examples. There's e.g. import_js in wasm-bindgen but there there's no direct call to Rust from JS.