6 ms·
I mean who cares, really. 90% of developers will spend time building reusable components that will be used exactly once, and and some people will open source so
by weego 10y ago
I mean who cares, really. 90% of developers will spend time building reusable components that will be used exactly once, and and some people will open source some stuff that wedges in every suggestion and pull so it is 5 times the complexity any one person ever needs and then we will talk about the failed promise of web components.
- jakelazaroff 10y agoI don't think the thesis of the article is that it hinders reusability, though — it's that anything built on the DOM presents significant limitations compared to what we can do with JavaScript. The example of passing dynamic styles to a web component is a good one: since attributes have to be strings, you have to handle serialization somewhere rather than have it Just Work, like it does with most modern JavaScript frameworks.
- dmitriid 10y agoIt's also the main problem React faces when trying to incorporate/integrate with Web Components. React Components can be arbitrarily complex and accept arbitrarily complex properties. Web Components work ok as "leaf" nodes: then it's just a component with string props/attributes. The inverse is nigh impossible: Web Components can only deal with strings, so you would end up with yet another incompatible wrapper à la Polymer if you want to do anything remotely complex.
- Touche 10y agoWhen you say "Web Components", what is it that you are talking about? I assume you mean custom elements. Custom elements are DOM Nodes like any other. They are represented in JavaScript like any other object. Of course you can pass non-strings to DOM elements. Open your development console and type document.createElement('div').user = {name: 'Dmitri'}. Did you get an error?
- spankalee 10y ago> React Components can be arbitrarily complex and accept arbitrarily complex properties. Web Components can be arbitrarily complex and accept arbitrarily complex properties or children. Did you even try Web Components before spewing falsehoods?
- jakelazaroff 10y agoThe W3C editor's draft for custom elements clearly states that attributes are sequences of DOMString: https://w3c.github.io/webcomponents/spec/custom/#concept-custom-element-definition-observed-attributes https://w3c.github.io/webcomponents/spec/custom/#concept-cus...
- spankalee 10y agoSo? Properties are objects and children are nodes.
- dmitriid 10y agoSo, basically, "we push everything to JS and we have the curse of the empty body tag where everything is rendered with JS" turned into "we push everything to JS and we have the curse of the empty body tag where everything is rendered with JS ... but with WebComponents! So it's cool now!"
- sametmax 10y agoPrecisely the reason I missed angular when going to react and why I now love vue (which is kinda the best world of both): most of the time, you don't start with reusable components. You just hack on your template, and maybe, maybe, if your project grow, you start extracting common code into reusable widgets.
- danabramov 10y agoWhen I use React I do exactly the same, too. Templates are not that different from components in terms of code ortanization. Components don't have to be reusable at all—it's just nice that once you need them to, they are.
- sametmax 10y agoThis works only if you are a full js stack. Using any other language means you get 2 sets of templates.
- danabramov 10y agoNot sure what you mean. My point is that you can “keep everything in one component” in React exactly the same way you’d do it in Angular or Vue.
- sametmax 10y agoIf you use django/rails, suddenly you have django/rail template files and templates in your components.