This is the Virtual DOM of AppRun ported to WebAssembly using Rust.
To use this template, you need the Rust tool chain, and wasm-pack installed first.
In JavaScript/TypeScript
let mod;
import('../pkg').then(m => mod = m).catch(e => console.log(e));
const vdom = [...];
mod.render(document.getElementById('p'), vdom);
The virtual DOM is an array that contains number, string, object, html element, svg element, and virtual node.
The virtual node is an object that has three properties: tag, props and children.
[
'hi',
100,
{ a: 100 }
document.createElement('h1'),
{
tag: 'div',
props: { id: '1' },
children: [{
tag: 'button',
props: { onclick: () => { }}
}]
},
])
The render function renders the virtual DOM to an element or document.body.
In Rust
#[wasm_bindgen]
pub fn render(element: &Element, vdom: Vec<JsValue>, is_svg: &JsValue) {
......
}
Have fun!