News for hackers. Stuff that matters.
Re:The Firefox UI Is Now Built with Web Components by ng12 on Wednesday November 20, 2019 @02:31PM (#21587528)
Because the API is really ugly. I can't see them ever taking off except maybe as an implementation of another library with a cleaner API.
Re:The Firefox UI Is Now Built with Web Components by ergo14 on Wednesday November 20, 2019 @02:49PM (#21587719)
You are correct, they are pretty low level. You want something like lit-element or stencil (or vue, svelte... etc) on top of them for a pleasant experience.
Re:The Firefox UI Is Now Built with Web Components by interlocutor on Wednesday November 20, 2019 @05:36PM (#21589373)
What are you talking about? There is hardly any API. https://developer.mozilla.org/en-US/docs/Web/Web_Components/... It is extremely simple.
Re:The Firefox UI Is Now Built with Web Components by Crinus on Thursday November 21, 2019 @06:14AM (#21593060)
First time reading this.

On one hand it looks neat. This is something i expected browsers to be able to do since i noticed that Mozilla (pre-Firefox) implemented <blink> (or <marquee>?) in JavaScript.

On the other hand it looks like it'll become much harder for JavaScript-less environments to extract data from web-pages as now an article on a news site could be something like <news-article id="23848923"> and the JavaScript side will do the rest.

But being able to do something like <my-fancy-button caption="Go To Google" target="http://google.com/"> that in the background creates all the canvases and such needed will be neat.

Re:The Firefox UI Is Now Built with Web Components by Asooka on Thursday November 21, 2019 @12:34PM (#21596805)
>On the other hand it looks like it'll become much harder for JavaScript-less environments to extract data from web-pages as now an article on a news site could be something like <news-article id="23848923"> and the JavaScript side will do the rest.

This is already the case on a lot of sites, just not standardized. With the standard you could sandbox the javascript or maybe implement specific parsing for the most common web components.

Re:The Firefox UI Is Now Built with Web Components by madmulita on Thursday November 21, 2019 @06:37AM (#21593157)
Oh, wait for webassembly, that's gonna be fun.
Re:The Firefox UI Is Now Built with Web Components by jlengrand on Wednesday November 20, 2019 @05:14PM (#21589160)
Which is exactly the point :). So good news!
Re:The Firefox UI Is Now Built with Web Components by cmpolis on Wednesday November 20, 2019 @02:43PM (#21587655)
This is one of the goals of Polymer- a cleaner API/abstraction layer on top of web components, right?
Re:The Firefox UI Is Now Built with Web Components by floatboth on Wednesday November 20, 2019 @02:48PM (#21587708)
Well, forget about "Polymer the library", it served us well but it's very legacy at this point. The successor is https://lit-element.polymer-project.org and it's awesome.
Re:The Firefox UI Is Now Built with Web Components by interlocutor on Wednesday November 20, 2019 @05:38PM (#21589385)
Why on earth do you need something that heavy? How about this 200-line lib instead: https://github.com/wisercoder/uibuilder It lets you TSX format (same to React) to implement as well as to use web components.
Re:The Firefox UI Is Now Built with Web Components by spankalee on Wednesday November 20, 2019 @05:50PM (#21589500)
> Unlike React.js UIBuilder does not do incremental screen updates

LitElement + lit-html give you very efficient updates, and don't require non-standard JS like JSX.

Re:The Firefox UI Is Now Built with Web Components by interlocutor on Wednesday November 20, 2019 @06:52PM (#21589943)
lit-html is no more of a standard than JSX. In fact JSX is better because tools like VSCode is able to validate both HTML and embedded JavaScript.
Re:The Firefox UI Is Now Built with Web Components by spankalee on Wednesday November 20, 2019 @07:35PM (#21590249)
Huh? lit-html uses standard JavaScript. That's it. JSX is a non-standard extension. So yes it is more standard than a non-standard, and lit-html runs directly in browsers without any transpilation while JSX very much doesn't.

VS Code is as able to analyze lit-html templates as well as JSX via the lit-plugin extensions. It gives you type-checking, code completion, hover-over docs, and linting.

Re:The Firefox UI Is Now Built with Web Components by interlocutor on Wednesday November 20, 2019 @08:40PM (#21590665)
lit-html needs a 1600 line library where as UIBuilder is a 200-line library: https://github.com/wisercoder/uibuilder/blob/master/UIBuilde...

Yes, JSX needs transpilation but that happens at compile-time. Which is better, pre-processing at compile-time, or "transpilation" (i.e., string processing) at run-time?

Re:The Firefox UI Is Now Built with Web Components by spankalee on Wednesday November 20, 2019 @10:05PM (#21591092)
UIBuilder doesn't do incremental updates at all. You might as well use innerHTML and template literals. That's a 0-line library :)
Re:The Firefox UI Is Now Built with Web Components by interlocutor on Wednesday November 20, 2019 @11:45PM (#21591534)
Updates offered by lit-html appear to be very limited. If you change value of expressions it updates the DOM. What about larger changes, such as list items changing? What about child elements being replaced with new ones?
Re:The Firefox UI Is Now Built with Web Components by spankalee on Thursday November 21, 2019 @02:16AM (#21592056)
It handles all of that.
Re:The Firefox UI Is Now Built with Web Components by interlocutor on Thursday November 21, 2019 @09:55AM (#21594603)
That does not appear to be correct.

https://github.com/Polymer/lit-html/wiki/How-it-Works#4-upda...

Excerpt:

update() simply iterates through each part and value (the parts array and values array are always the same length) and calls part.setvalue(v) for each part.

https://lit-html.polymer-project.org/guide

Excerpt:

Behind the scenes lit-html creates HTML <template> elements from your JavaScript templates and processes them so that it knows exactly where to insert and update the values from expressions.

This is very limited. You need to manually update DOM unless your updates are simple changes in values of expressions.

Re:The Firefox UI Is Now Built with Web Components by spankalee on Thursday November 21, 2019 @11:33AM (#21595911)
It is very correct: lit-html is amongst the fastest template systems in use right now. This is shown in every benchmark I've seen or made for it.

lit-html updates only the parts of DOM that are dynamic and change. It handles nested templates as values, only updating the whole nested template if the template itself changes, otherwise recursing and only updating that template's values if needed. Repeated DOM is handled either by simply updating state for each item in sequence (non-keyed), or by using the repeat() directive which will move DOM (keyed).

You absolutely don't need to manually update DOM. The whole point is to describe your DOM structure as a function of data, and to be to describe all the conditional / repeated parts in the template expression itself.

Re:The Firefox UI Is Now Built with Web Components by petilon on Wednesday November 20, 2019 @09:59PM (#21591066)
OK, so plugins can enhance code editing. But what about compile-time checks? With TSX, if you have a mis-matched tag the TypeScript compiler will give you an error.
Re:The Firefox UI Is Now Built with Web Components by spankalee on Wednesday November 20, 2019 @10:04PM (#21591087)
Same with lit-html and the TypeScript compiler plugin.
Re:The Firefox UI Is Now Built with Web Components by petilon on Wednesday November 20, 2019 @10:57PM (#21591321)
All I am able to find is this "intellisense" (i.e. editing time) plug-in: https://github.com/microsoft/typescript-lit-html-plugin

Where is the plug-in that does compile-time checks of HTML tags and attributes?

Re:The Firefox UI Is Now Built with Web Components by spankalee on Wednesday November 20, 2019 @11:31PM (#21591474)
Re:The Firefox UI Is Now Built with Web Components by nothis on Wednesday November 20, 2019 @02:52PM (#21587755)
So we finally got a goddamn proper standard and we're already cheering for the next API to throw in front of it to make it "cleaner"?
Re:The Firefox UI Is Now Built with Web Components by floatboth on Wednesday November 20, 2019 @02:58PM (#21587828)
Actually, no. There's no need or possibility to make it "cleaner", but there's always the direction of making it more "high level". These are very different things.

If you look at https://lit-element.polymer-project.org — it's just a base class that integrates declarative DOM templates.

The platform APIs are not opinionated about templating, they just provide proper mechanisms for declaring elements and having isolated DOM subtrees. It makes sense to leave templating to libraries, because… well, good luck on getting even just two people to agree about how templating should be done :)