2 ms·
Every time I look at lit I get this unsettling feeling that it’s almost what I want but can’t be, because it loses the only thing I want in JSX. Lit fundamental
by eyelidlessness 6y ago
Every time I look at lit I get this unsettling feeling that it’s almost what I want but can’t be, because it loses the only thing I want in JSX. Lit fundamentally targets templates with HTML output. Which is great for what it is. But the thing JSX offers that nothing else does is:
- return values are a data structure, so they’re render-target/render-implementation agnostic
- it’s compile time only/effectively a macro, so the compiler can choose how to render subtrees
I love the “it’s actually part of the language not a build tool” part of lit, but it can’t satisfy those other goals without giving up its core selling points.
- spankalee 6y agolit-html also returns a data structure - strings and values. You can interpret the strings however you want. JSX actually doesn't return a data structure. It's syntax only and some transforms do things quite different from what React.createElement() does. And this is part of the problem with it and why it can't really be standardized - there's no semantics to standardize. lit-html as an render implementation does indeed target only the DOM, it's not trying to target non-web platforms.
- eyelidlessness 6y agoSorry, I misstated my point. JSX is itself a data structure, not interpolated strings and values. That makes it closer to hyperscript. But it doesn’t necessarily return anything or have a runtime value at all. The problems you cite are exactly what I meant to say are its strengths. Because it’s entirely undefined syntax that only corresponds to data, it can be used as a general purpose macro for anything from React.createElement to defining a web component to defining an output for a CLI to defining a test or an API endpoint or anything at all. It’s a general purpose DSL, and the fact that it looks like HTML/XML is just convenient for its most common usage.
- deleted 6y ago[deleted]
- spankalee 6y agoJSX really isn't a data structure, is just syntax. Sometimes it's compiled to statements, like with some idom transforms.
- eyelidlessness 6y agoJSX is an expression with structural semantics. It doesn’t have to be compiled to a data structure but at the AST level it definitely is, which is the whole point.