AFASSoftware / maquette

Pure and simple virtual DOM library

Home Page:https://maquettejs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make the h function more strict

johan-gorter opened this issue · comments

To boost performance, we want to make the h function more strict. The children in the h function in maquette do not have to be inside an array, but may appear as additional arguments. We did this to to make JSX possible and to be able to create text nodes easier. The downside to this approach is the TypeScript compile errors are harder to understand and there is a performance penalty. In maquette 3, we propose to only allow childnodes as an array again.
If you still want to use JSX, you can use this extra babel plugin

This is one of our ideas for maquette 3

this would be quite frustrating for a standard typescript user who uses the inbuilt TSX transformer and likely not have babel in their toolchain.

I am not aware of the Typescript TSX compiler being able to produce hyperscript that maquette(2) can read. Do you have a working setup of this?

in what way? with jsxFactory set to h in tsconfig you get:

function render() {
    return h("span", null,
        h("div", { foo: "bar", onclick: hello }, "Hello"),
        h("span", null, "World")
    );
}

from:

function render() {
	return (
		<span>
			<div foo="bar" onclick={ hello }>Hello</div>
			<span>World</span>
		</span>
	)
}

Ok, I was not aware that jsxFactory could produce working code, but I see now that Typescript even uses h as an example.

This leaves us with two possibilities, either obandoning making the h function more strict, or providing a strict h function and a nonstrict jsx function (name pending).

I think I first want to know how big of a performance improvement a stricter h function would be, before making this decision.