Live data from Hacker News

The time is right for a DOM templating API

justinfagnani.com

101–110 of 256 posts

Re: The time is right for a DOM templating API

#101
I don't quite understand. The DOM is/needs a functional API. Why bolt another DSL on top?

Now you have to find a way for javascript to interact with your template language.

While functions are sufficient. That doesn't look like orthogonal language design.

Re: The time is right for a DOM templating API

#102
post #98
post #83

Earlier quoted context omitted.

Doesn't querySelector(All) provide this?

Not entirely. There's a reason people do Array.from(querySelectorAll) to do more than just `forEach`

So you are saying that Array.from(querySelectorAll) gets you there? What are you missing then?

Genuinely asking, I have no clue what's being alluded to without being clearly mentioned in this thread.

Re: The time is right for a DOM templating API

#103
post #17

The web really needs native templating, reactivity, and data binding. I can't even begin to imagine how much CPU and bandwidth is wasted with billions of users downloading, parsing, and executing something like React.

React isn’t templating though.

[dead]

Re: The time is right for a DOM templating API

#104
post #31

What we need is not templating. What we need is a native implementation of a virtual dom. More specifically, a native implementation of the "patch" function: patch(target_dom_node, virtual_dom) Where `virtual_dom` is just a plain-data description of the DOM. Most of the "slowness" of the DOM come from its requirement to be a 90's era Java style object hierarchy. Don't call it "templating". Just call it "virtual dom".…

Other than quibbling over the word "template", how does that differ from what TFA is describing?

The linked proposal has many "features" that would be "needed" if you frame the problem in terms of a "template api", centered around "binding" variables, and what not.

https://github.com/WICG/webcomponents/issues/1069

My proposal only adds one native function with nothing else: no new data types, no new apis.

Re: The time is right for a DOM templating API

#105
post #34

Hard not to laugh out loud at "We know what good syntax for templating looks like." We don't. Not even close. Because I'd hazard a good template is almost certainly more of a visual thing than it is a symbolic one. Is why dreamweaver and such was so successful back in the day. And why so many designers learn with tools like photoshop. Also hard not to feel like this is reaching hard to try and recreate xslt. :( It is…

> Hard not to laugh out loud at "We know what good syntax for templating looks like." We don't. Not even close. Because I'd hazard a good template is almost certainly more of a visual thing than it is a symbolic one.

How do you come to this conclusion? It seems to me that what you mean is a general gripe with HTML+CSS, not with how it's generated.

And why do you bring up absolute positioning?

I hear this take on HN again and again and sure, absolute positioning has its place, and is needed for many things.

But when it's used for page/app layout, most of the time I came across this it was an absolute nightmare, falling apart at the slightest content (even text!) or screen size changes.

Even print newspaper layout can't work like this, because typography is involved, although it's probably a lot closer to what I imagine you are describing.

Maybe I'm misunderstanding you.

But when I was doing more CSS-intensive work (I still do a fair bit), developing something on a basis when someone created a layout based on absolute positioning that looked like it was "almost ready", it was a terrible time sink to try to fix it and recreating it using flex, flow et al for layout (I'm not that fond of grid outside of some scenarios, and at the time I didn't use it due to browser support) was always faster because the problems with absolute positioning as the main layout tool were basically unfixable.

Maybe there are techniques using calc() and viewport units where it makes sense, but absolute positioning is not suitable for any layout outside of completely static content and viewport dimensions, in my experience.

Re: The time is right for a DOM templating API

#106
post #34

Hard not to laugh out loud at "We know what good syntax for templating looks like." We don't. Not even close. Because I'd hazard a good template is almost certainly more of a visual thing than it is a symbolic one. Is why dreamweaver and such was so successful back in the day. And why so many designers learn with tools like photoshop. Also hard not to feel like this is reaching hard to try and recreate xslt. :( It is…

> People will go through obscene lengths to recreate what judicious use of absolute positioning can achieve fairly well

the web has the requirement that the 'document' look good no matter what device size/dimension, orientation, and/or capability.

In regular apps (say, a windows app), you don't have this requirement. In mobile apps, there's a standardized set of sizes. Only on web do we have both!

Re: The time is right for a DOM templating API

#107
post #104

Earlier quoted context omitted.

Other than quibbling over the word "template", how does that differ from what TFA is describing?

The linked proposal has many "features" that would be "needed" if you frame the problem in terms of a "template api", centered around "binding" variables, and what not. https://github.com/WICG/webcomponents/issues/1069 My proposal only adds one native function with nothing else: no new data types, no new apis.

Doesn't your proposal implicitly introduce the concept of a virtual DOM, which the browser does not have?

You'd need to spec out what that looks like. It adds one new API from the users perspective but much more from the browsers perspective.

Additionally the next generation of Frameworks do not use virtual DOM. Solid and svelte do not. Vue is moving away from it. Signals are directionally where they're all heading.

Re: The time is right for a DOM templating API

#108
I disagree on the general principle of adding APIs -- the platform suffers not from lack of APIs, when you really think about it, but from "another API to rule them all". It's frankly a similar fallacy that struck Microsoft where they were for a long time stuck having to support every API their seniors and interns ever invented -- none of which seem to be sufficient, apparently.

The solution to the "bro, just one more API, please" is to design a _transparent_ platform that is well able to "delegate" programming of new features (e.g. one implementing your favourite templating API) to third-parties in a manner that maintains their "first class citizen" status. WebAssembly was a move in that direction because it's a generic platform that in part supercedes and otherwise supplants the mess that JavaScript has to manage bridging the originally "kiddie script" application software domain, with the native functionality the browser may be encapsulating (also for performance).

Case in point: FFMpeg may be compiled to a WebAssembly module, which gives you arbitrary video/audio encoding/decoding -- pending correct design of bit-blitting so the decoded output can be efficiently transferred to the screen/speakers (which, for much of the reasons I am trying to outline, _is_ the bottleneck of the entire solution).

We need more of the same kind of thinking. Stop begging Web browser vendors / w3C / WHATWG for more features that are just lipstick on a pig -- sit down, think about what kind of feature(s) would allow the Web platform to finally escape the death spiral it's been in since its inception -- albeit one with a large enough radius it's meant to never actually resemble a spiral.

I don't know if I am making myself clear here, but in much simpler terms: why should there be another piece of code that caters to "most" (because you happen to be a FP/React zealot, for better or for worse) when these people can ostensibly write such templating system themselves, publish it on e.g. NPM and/or pull it and use it from there?

Re: The time is right for a DOM templating API

#109
This is exactly the kind of high-level feature we need to stop putting standardisation efforts towards, and focus instead on low-level features that provide value for high-level user land abstractions.

There is no value this provides over making a tagged template function and exposing it as a library. If that library is stable with ubiquitous adoption for 5-10 years then maybe there's something to talk about.

Re: The time is right for a DOM templating API

#110

Earlier quoted context omitted.

> The react model - where you just update the global state and re-render everything - is slower but easier on the brain. The signals model is faster, but so much effort. there are multiple frameworks now that do fine-grained diffing without relying on signals, proxies, or any other reactive primitives. they basically have the top-down react model but much faster and without the weird concepts like hooks and manual/wa…

Just want to add that even though ivi is using tagged templates, I am strongly against using tagged templates to describe UIs as a Web Standard. One of the most useful features that could make a lot of incremental computation problems easier is "value types"[1], but unfortunately it seems that isn't going to happen anytime soon. The biggest constraint when developing an efficient UI framework with good DX is JavaScri…

> The biggest constraint when developing an efficient UI framework with good DX is JavaScript.

for perf, s/JavaScript/DOM, i think.

good DX comes from ecosystem and amount of time invested in making good tooling. JSX would be a non-starter without IDEs helping autocomplete, linting/format, syntax coloring, and webpack/babel to do the compilation.

tagged templates could reach at least the same level of DX as JSX if the community invested the resources to make that better. i'm not saying it's the right solution for a standard, but it would be way better than jsx, since tagged templates are already a standard.

Post reply on HN