I noticed that
undefined, but if it returned
this, then it would be possible to write stuff like this:
document.createElement( 'div' ).append(
which is somewhat “declarative”. Does any native API exist like that? It would also be easy to map
JSX to that.
I know we can create these APIs ourselves. Just wondering about native options.
Updated the title, because obviously HTML is a declarative API. I meant to ask about declarative
Does any native API exist like that?
nope, but people have been talking about that:
document.createElement could accept the arguments to
append directly (as array).
Because it seems like string-parsing overhead at runtime. Or not?
Just look at the original post -^
It’s much more costly than the equivalent HTML.
Also, instantiating this in one go is more efficient.
And Template Literals can easily be pre-compiled and re-used.
(Any one of the various symbols could have changed)
June 23, 2018, 3:55am
Apple proposed extending the
<template> element to handle interpolation, which might be similar enough to what you’re looking for?
w3c/webcomponents: HTML Template Instantiation
@Androbin @Tigt Interesting replies, thanks!
I checked out
Surplus recently, it looks really nice too: converts JSX to in-place updates, similar to hyperHTML or lit-html approaches, but faster without DOM diffing.
August 8, 2018, 12:41am
This might be close to what you are looking for:
Inspired by kotlin-like layout parameters.
Lit-html also comes to mind, with string literals.
I’ve been using
Solid.js lately, and made lume/element on top of it. But I should try to stay on topic.
Seems that if
this (or even the child like
appendChild), it would be more useful. I wonder what was the reasoning that led to returning
@Androbin I was curious, so I made a benchmark to compare a HTML string parsing against a monkey-patched
append() that returns
It turns out the HTML parsing is 34.5% slower on my machine, for this particular example.