3 ms·
I quite like this approach but I wish the web component spec had been better to begin with, I shouldn't have to "feed in" the internal divs to the web component
by sirwhinesalot 3y ago
I quite like this approach but I wish the web component spec had been better to begin with, I shouldn't have to "feed in" the internal divs to the web component (which wrecks encapsulation), HTML templates should be possible to name and instantiate from within HTML, allowing for proper encapsulation, while having the javascript be entirely optional and allow for progressive enhancement.
I ramble about this on my blog if anyone cares: https://btmc.substack.com/p/making-sense-of-web-components https://btmc.substack.com/p/making-sense-of-web-components
I've wanted to make a simple compiler (I'm talking a single python script level of complexity here) which takes a set of .html files with named templates inside (HTML+CSS+JS sane web components), encapsulates the CSS and the JS, then goes through the various actual .html page files and replaces each instance of the template <my-component></my-component> with a "HTML Web Component" as described in Jim Nielsen's article.
Alas, I lack the time, feel free to steal my idea.
- jadbox 3y agoFwiw I love this idea for a simple js-free component compiler/bundler.
- pphysch 3y agoDjango has something similar, on top of its template support https://docs.djangoproject.com/en/4.2/topics/forms/media/ https://docs.djangoproject.com/en/4.2/topics/forms/media/
- seabass-labrax 3y agoWhat you describe is provided by XSL and XHTML! These are both standard web technologies, albeit not particularly popular ones. This is how you define a template: <xsl:template match="put the xpath query for your components name here"> Anything inside that template will be expanded when you use your component's name in your XHTML file, either by the web browser or (more practically in an HTML5 world) by a server-side XSL processor. It's pretty fun :)
- deleted 3y ago[deleted]
- sirwhinesalot 3y agoYou still need to deal with style and script encapsulation, but it's a start :)
- uallo 3y agoDo you mean like Declarative Shadom Dom? https://github.com/whatwg/html/pull/5465 https://github.com/whatwg/html/pull/5465
- sirwhinesalot 3y agoNope, awful standard on top of an already awful standard.