Hacker News new | past | comments | ask | show | jobs | submit login

Browsers do have built-in support for web components. You can extend HTMLElement in every current major browser.



This is in fact the first example in the article.


And such extension is a major PITA to do. The API is atrocious, like most of the DOM API is.


How is it atrocious exactly?

I mean it’s decidedly not React to be clear, but I’m not sure what makes it atrocious


It's overly verbose and error prone. Try adding an observable attribute. Then add another one. Then do something simple like change the name of the first one.

And that's just two attributes.


The Web Component APIs don't aim to be easy to use by application developers. That is simply not a goal of the spec. They're low level APIs which expose behavour and hooks on which libraries and frameworks can be built. As an application developer you are supposed to use those friendly libraries.


Aaand that's the problem with the API. The question was, how is API atrocious. Once an answer is received, it's immediately diverted to "the API is not for devs, you have to use libraries".

This doesn't make the API any less atrocious. And it would be nice if the platform didn't rely on libraries to make it usable.


Sure, from a dev perspective the API may be bad. But I'm saying that that isn't the right perspective to use when judging it.

"Nice" APIs or higher level APIs are desirable of course, but they tend to be much bigger in size and scope, much more opinionated and brittle than a smaller low level API. A portable API which browser makers can accurately implement and support for the long term, is a smarter goal even if it does expect devs to build a "nice" layer on top of it first.


In case of WebComponents it could have a small sane layer on top that wouldn't be too large. See WebComponents vs Polymer: [1]

As it stands now, it's nigh unusable by developers. Almost no frameworks even use it as their foundation. And those that do compile to them go out of their way to never ever use it anywhere except in base classes, maybe: [2]

As a result, today, 9 years (!!!) after they were first proposed, the very person who proposed them relegates them to "webcomponents will be used incidentally not totally" [3]

[1] https://twitter.com/dmitriid/status/865518972380237825?s=20

[2] Stencil compilation: https://twitter.com/dmitriid/status/1283445578853158917

[3] https://twitter.com/slightlylate/status/1283053719563563008


What's your suggestion for a better API?

You can't just say "React" though, you have to show how it actually integrates with the DOM that we have. "Throw away the DOM we have" isn't a realistic option either.


React integrates with the DOM we have. How dow you suppose it works?

How is React different from any of the libs and frameworks you are supposed to use for WebComponents? [1]

As for the API. How about a declarative API lime the one Polymer uses? [2]

[1] https://twitter.com/dmitriid/status/987771666846699520?s=20

[2] https://twitter.com/dmitriid/status/865518972380237825?s=20




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: