The UI is here https://loda-lang.org/edit/?oeis=2487
It can run from commandline for mining.
Implementation https://github.com/loda-lang/loda-rust
WASM is to offload computationally expensive workloads that JS is not so good for (perhaps some sort of computer vision, for example). It passes the result back to JS to update the DOM.
And yet you have articles like OP, where someone finds WASM useful for form validation which is clearly not in the "offload computationally expensive workloads" category and would profit from a direct integration.
Everywhere the author used `unwrap` is a place where I would expect the program to crash if the operation fails, so I'm not sure what they imagine "proper error handling" in this case would look like. Take this snippet for example:
let doc = window().unwrap().document().unwrap();
let form = doc
.get_element_by_id("login")
.unwrap()
.dyn_into::<HtmlFormElement>()
.unwrap();
In javascript that looks like this: // or you could write nothing. `login` is already a global variable
let form = document.getElementById('login');
At a glance, the web-sys docs don't say, but I assume the error
conditions that would trigger those `unwrap`s are:- The `window` global is missing or the code is running outside of the browser
- The `document` global is missing
- The page has no form element with an id of "login"
I don't see a reasonable thing to do in those cases except crash.
A more general point: I find WebAssembly works best when:
- Interfacing with the DOM and web APIs is still mostly done in javascript
- The wasm binary has a narrow interface consisting of a handful of functions with careful calling conventions
- The wasm binary avoids dependencies on either third-party packages or the standard library (e.g. rust's "no_std")
- The compiled code generously uses mutable "global" variables (note: local to the wasm module instance)
The rust + wasm-bindgen + web-sys strategy feels like the exact opposite of this, which doesn't strike me as very useful unless you just want to avoid writing javascript entirely.
reactordev•7mo ago
WASM should be left to things like IPC/Canvas/WebGPU stuff, not things easily done with document.querySelector
No offense, but this is using a bomb to kill a fly.
I know it says this is just a demo but people will find this and do this thinking it’s normal.
milliams•7mo ago
remram•7mo ago
littlestymaar•7mo ago
porridgeraisin•7mo ago
https://html.spec.whatwg.org/#email-state-(type=email)
But it is true that you can implement it with a FSM(which is what firefox does). Webkit uses a regex as well I think.drowsspa•7mo ago
littlestymaar•7mo ago
zoechi•7mo ago
remram•7mo ago
What kind of validation are you going to do without a regular expression?
littlestymaar•7mo ago
Actual form validation… I can't even think of a single kind of form validation where a regex would help…
01HNNWZ0MV43FF•7mo ago
Not great, not terrible.
qoez•7mo ago
graypegg•7mo ago
Of course there's always the argument that you'd add more javascript to "framework-ize" this a bit more, but the rust code is just targeting the DOM with IDs, so I don't think it's fair to compare it to any "framework-y" solution.
madduci•7mo ago
timeon•7mo ago
jpdenford•7mo ago
> I’m using form validation as a placeholder. It shows all the crucial aspects to use WASM instead of JS, like wiring up DOM events to Rust functions, and then reacting to those events.
_mlbt•7mo ago
https://developer.mozilla.org/en-US/docs/Learn_web_developme...