m("main", [
m("h1", {class: "title"}, "My first app"),
m("button", "A button"),
])
React does the same (after the JSX is compiled), and I'm not aware of any that don't use function calls, vs just plain object data: {
tag: "main",
children: [
{ tag: "h1", attributes: { class: "title" }, children: [ "My first app" ] },
{ tag: "button", children: [ "A button" ] }
]
}
Is it just for brevity, or is there some deeper reason I'm missing?
By using functions you can evaluate parts of the dom, which crucially means you can reevaluate parts of the dom.
Those functions also enable changing their output based on inputs, enabling data reactivity.
If you had to evaluate the whole tree each time, you’re doing a lot of unnecessary compute.