Most active commenters
  • shortrounddev2(3)

←back to thread

304 points ulrischa | 16 comments | | HN request time: 1.29s | source | bottom
1. judah ◴[] No.44687229[source]
Looks like it's done using standards-based web components[0]. The page says these components don't require any existing JavaScript framework; because web component support is built-in to the browser.

Nice to see devs picking up web components.

[0]: https://developer.mozilla.org/en-US/docs/Web/API/Web_compone...

replies(4): >>44687259 #>>44687425 #>>44688701 #>>44690588 #
2. cchance ◴[] No.44687259[source]
This has been soooooooo long in the making, i remember playing with webcomponents for personal stuff years ago when i didn't care about compat. Good to see mainstream libraries finally picking it up
replies(1): >>44690386 #
3. shortrounddev2 ◴[] No.44687425[source]
We use web components at the hook for my company's advertising code but I've found them pretty thoroughly disappointing, personally. They make it simple to trigger code execution but their API isn't really that good
replies(1): >>44688410 #
4. spankalee ◴[] No.44688410[source]
The whole point is to make it simple to trigger code and to be interoperable. Then you write whatever code you want to implement the component.

Web components are not analogous to frameworks because frameworks tightly couple the component interface and lifecycle hooks with the component implementations. Those are properly decoupled in web components and you bring whatever rendering layer you prefer.

replies(1): >>44704283 #
5. hyperbolablabla ◴[] No.44688701[source]
I remember toying with Polymer circa 2014, for some reason the word "transclusion" jumps into my mind, I remember being excited about it at the time. I barely remember what it means today though.
replies(2): >>44689107 #>>44691149 #
6. julik ◴[] No.44689107[source]
I believe "transclusion" was the Angular 1.x vernacular for "slots", but don't quote me on that ;-)
7. oaxacaoaxaca ◴[] No.44690386[source]
https://webawesome.com is now in beta and I couldn't be happier.
8. reactordev ◴[] No.44690588[source]
12 years I’ve been saying this… 12, damn, years. React graduates look at me crazy. Angular devs say it’s not needed anyway. Svelte bros say get bent. I’m so happy that someone is paying attention.

You don’t need a shadow dom, you don’t need rerendering of everything when a simple value changes. You simply need web components and scoped js/ts with vite or whatever rollup you use.

replies(1): >>44692769 #
9. 8n4vidtmkvmk ◴[] No.44691149[source]
Polymer still haunts me to this day. It never made sense. It was literally designed to be deprecated. It's a big nasty polyfill for web components and it had/has a huge perf overhead. Not to mention it's ergonomics are just bad.
replies(1): >>44697379 #
10. JoeyJoJoJr ◴[] No.44692769[source]
Can you point to any example projects or a todo list app that shows how modern web component can be utilized.
replies(2): >>44693879 #>>44696067 #
11. bmare ◴[] No.44693879{3}[source]
Here's a great one: https://plainvanillaweb.com/pages/components.html
12. reactordev ◴[] No.44696067{3}[source]
Sure

    class App extends HTMLDivElement {}

    customElements.define(“main-app”, App)

    <body><main-app/></body>
    
This is the simplest web component.

More examples:

https://github.com/mdn/web-components-examples

13. owebmaster ◴[] No.44697379{3}[source]
and some of the bad design decisions propagated to the web components implementation and Lit framework.
14. shortrounddev2 ◴[] No.44704283{3}[source]
Yes but their choice to abandon constructors as a primary part of the lifecycle means that adding some kind of member field to the class will leave it inherently uninitialized in the `connectedCallback`. All fields basically have to be declared as `| undefined` if you're using typescript, which leads to reall ugly code:

    class MyComponent extends HTMLElement
    {
        private width: number | undefined; // must be | undefined or
                                           // you'll get a typescript error
        constructor()
        {
            // useless, unpredictable
        }

        connectedCallback()
        {
            this.initAttributes();
            // using this.width will still require an undefined check at some point
        }
   
        initAttributes()
        {
            this.width = Number(this.getAttribute('width'));
        }
    }
If you could reliably load attributes in the constructor instead of being forced to do everything in connectedCallback (or even better, load them automatically with decorators), it would make typescript implementations much cleaner. Just some way to validate attributes before connectedCallback, or work with typescript guarantees would make this much more attractive
replies(1): >>44709863 #
15. spankalee ◴[] No.44709863{4}[source]
The constructor is a part of the lifecycle, and always has been. It wasn't abandoned.

The lifecycle of custom elements reflects the behavior of the HTML parser and DOM APIs. Attributes aren't consistently available in the constructor because the HTML parser is streaming and may yield to the main thread at any time. So the element is constructed first, possibly before attributes are parsed. Attribute also aren't available because when element are constructed imperatively they will never have attributes at first, ie:

    // ctor is called, no attributes!
    const el = document.createElement('my-element'); 
    // now there will be an attribute:
    el.setAttribute('width');
You also shouldn't ever consider attributes to be fixed in a web component, since they may be added and removed at any time, and of course may never be set in the first place. You should implement attributeChangedCallback() and give your element defined behavior for any set of possible attributes.

Or you can use a helper library like Lit which does let you declare and consume your attributes via decorators.

replies(1): >>44710243 #
16. shortrounddev2 ◴[] No.44710243{5}[source]
I understand all these things, I think they are weaknesses. They make web components less generally useful, and really only useful for one thing. Constructors are only useful for dependency injection.