I know webassembly (wasm) is still in its infancy but I'd like to know if and how could I use it to change the DOM (in the same way I'm using Javascript to change the DOM).
Here is the official page:
Wasm MVP
In order to manipulate the DOM you have to do this via the JavaScript host - your WebAssembly module has to send messages to JavaScript 'asking' it to manipulate the DOM on its behalf.
By itself, WebAssembly cannot currently directly access the DOM; it can only call JavaScript, passing in integer and floating point primitive data types. Thus, to access any Web API, WebAssembly needs to call out to JavaScript, which then makes the Web API call.
wat text format (a human-readable textual representation of WebAssembly) and in . wasm binary format (the raw bytecode, expressed below in hexadecimal), that is executed by a Web browser or run-time environment that supports WebAssembly.
“WebAssembly is a new type of code that can be run in modern web browsers — it is a low-level assembly-like language with a compact binary format that runs with near-native performance and provides languages such as C/C++, C# and Rust with a compilation target so that they can run on the web.
according to the docs, DOM access is not supported (as of November 2016) but is planned for the future.
Manipulating the DOM probably won't be supported, if things proceed according to the outline described on that page since references to the DOM are going to be opaque.
A Wasm module can import and call JavaScript functions. A program that wants to manipulate the DOM hence has to come with the right glue layer written in JavaScript. It is more or less the same model as for asm.js code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With