-
Notifications
You must be signed in to change notification settings - Fork 387
Description
I read Justin's recent blog post about a DOM templating API, and I wanted to chime in on the discussion because I've been researching this topic quietly on my own for several years now.
While the DOMParts solution solves the problem but only when HTML is the thing being templated, I've built a document system called agAST which solves the problem for any and every possible language that you could want to template. You get a solution to the problem that works for HTML, JS, CSS, JSON, XML, GraphQL, JSX, Python, Java... you get the idea, it works for anything.
Here is what this looks like for JS:
let js = buildTag(jsParser);
let tree = js`fire('event', js.Expression`true`)`;
// We can always print the textual tree as if this was just a text interpolation
printSource(tree) === `fire('event', true)` // true
// We can also support random named reads (and writes) in logn time
printSource(tree.get(['statements', 0, 'expression', 'callee'])) === `fire` // trueThis works because tree is (a thin OO Proxy facade around) an immutable collections of plain JS objects and arrays -- structured more or less as a marriage of a syntax tree and a btree. Also because of the jsParser, which needs to be a special kind of parser that is aware of the possibility of embedding holes (gaps in the input) so that it works with buildTag.
Is this interesting to the web components team? If an API like this was in common use across the ecosystem, would it have any impact on what an optimal DOM-parts design would look like?