I should preface this with “not a javascript expert”.
const { parse } = wasm_bindgen // <-- This,
This imports this function from Rust:
#[wasm_bindgen]
pub fn parse() -> String {
that is, this wasm_bindgen exposes a list of functions, and I believe this is using object destructuring to create a function named parse that corresponds to the parse exposed by wasm_bindgen.
If you did it by hand, including the bindings, sure. But there’s not really a reason to; that’s why Wrangler exists
In my code, I just changed parse to the name of my function, and called it with the right arguments later on. It’s not a great idea to go back and forth and back and forth between JS and wasm anyway, so all the logic lives inside a single “main function” in the wasm.
Ahhh, ok. Thanks so much for the clarification! The CF Workers syntax is different from e.g. the MDN examples. And I think I had it stuck in my head that it was more similar to KV resources in that let ret = MYWASM.parse(...) was what I looking for. I’m guessing there’s a certain amount of presumed JS knowledge that I don’t have.
Yeah, the Workers project I started with, I got a lot of inconsistent results between “push X, download Y, why is X != Y?” So ended up throwing out all of the “spooky action at a distance” and just used a Makefile and a shell script [0]. From then on, I got consistent results, because make clean deleted the build/ directory where I concatenated the individual scripts. Therefore I knew exactly what was going into the deployed script. I controlled which JS fragments to include in which target scripts based on Linux kernel kconfig-style configuration and I prepend the non-git-tracked secrets so API keys and such are never in the source history. It’s been working beautifully, but no, it’s not wrangler. I realize I’m on my own in that respect, but I prefer the dependable simplicity.
Agreed for sure, I’m looking at adding a single function call to do some complex math and return the result. Only one call per request will be necessary, so I seem to be on the right track there. If CF’s V8 engine supports WASM’s SIMD accelerated instructions, I’m in a really good place.
[0] Yes, I freely admit that this is completely due to my lack of familiarity with JS :-))
Ha! That’s nice of you to assume the error was in the tool. . I’m fairly certain it was EBKAC [0]. I basically decided to skip the JS ecosystem learning curve. e.g. minification was preventing me from doing basic debugging (line numbers and variable names went away), and I didn’t know how to disable it back then. Also, didn’t know how to remove cached minified objects and some of my problems seems to originate around stale code remaining in the deployed script.
Honestly, the only bug I’ve consistently run into that I still think might be legit is the inconsistent state that seems to happen between using the CF Workers Web interface and then switching to uploading via wrangler/curl API. I’ve just completely given up on the web interface because it didn’t feel consistent to me . Once I did that, I always had the code I expected running actually deployed.
I just went to “Launch Editor” to provide a clear example of what I’m referring to, but it seems CF is already on it. It’s being deprecated in favor of a new interface. Which I’ve also not used because I don’t want my-worker._____.workers.dev domain. I really wish I could skip setting that up…
The last thing I need is another place for a deployed script to hide, “oh ■■■■, I accidentally uploaded the new version to the domain I never use!”