Hacker News new | ask | show | jobs
by tpm 338 days ago
With access to DOM it could run with no (or just very little) js, no ts-to-js transpiler, no web-framework-of-the-month wobbly frontends perpetually reinventing the wheel. One could use a sane language for the frontend. That would be quite the revolution.
2 comments

You can just interpolate bits of Javascript inside C++ to access the DOM, like so:

  #include <emscripten.h>

  void sayHello()
  {
    EM_ASM(
      let foo = document.getElementById('foo')
      foo.innerHTML = 'hello';
    );
  }
See https://emscripten.org/docs/porting/connecting_cpp_and_javas...
You already can do that. You need a tiny shim and you can forget it's JS and use all WASM.
Can you point me to a howto/tutorial?
This is wasm-dom for Rust: https://crates.io/crates/wasm-dom There's also web-sys. Those are Rust centric, I'm sure there are others, but basically you only need the whim once, and then you write in your language of choice and compile to WASM, you never have to think about JS. Although... I may question the purist attitude. But you can do it.

Think of it like HTMX, the way people say it "avoids working with JS" (HTMX itself is written in JS). Same principle.