It was 2015 when I first heard about webcomponents, custom elements and the mysterious shadow dom. Browser support was - well - let's call it exper...
For further actions, you may consider blocking this person and/or reporting abuse
What is the purpose of using a
<template>
in your example? You never clone it, you're just getting it'sinnerHTML
as a string. This makes it a very expensive string holder.You could simplify what you have to roughly this without the template:
But not that with both a
<slot>
and copying the text content, you'll be displaying the content twice. You're also reading the attribute in the constructor, but it may not be set there yet.Or maybe simplify it to:
comming back 2 years later
There is a bug in all replies code! There is no DOM available in the
constructor
when the Web Component is defined before being used in the DOMYes, you are absolutely right. As mentioned in several disclaimers throughout this post, this is not the structure you would go for. This example element is meant to introduce several concepts and by no means represents an actual custom element.
I carefully chose this setup to accommodate for progression throughout this tutorial and made some crude decisions to maintain overview yet somewhat of a separation.
As I am also concerned about potential readers imitating such a pattern: do you think I haven't mentioned used anti-patterns enough, or is your feedback only based on the actual code snippets?
What is the best framework to use with Web Components? Perhaps even something like SnowPack? Or perhaps, Webpack or Parcel.js?
Actually, I hope that HTML/CSS/JS will all die. Only backend compilation to WebAssembly remains.
But in reality, at least HTML will probably survive.
I started with Z80 assembly in 1979
If assembly languages were better we would never have had BASIC, Turbo-Pascal, Delphi, ActionScript, PHP, Go, Python, and name them all
The best Web Components learning track is to start with native.
Learn what food is, learn what paint is, learn what Web Components are
Frameworks and Libraries like Lit, are tools to help you produce faster, not better,
You can try hqjs.org server. It works with web components as well as with different frameworks and metalanguages as typescript and scss
Thanks. But I run these with neoan3 as this
Gives me the possibility to generate the skeleton of a new custom element via cli
Allows me to use server side variables with ease
Provides me with a unified system when developing API/backend
Serve/use without building process or development server
Edit: sorry. I now realize that your suggestion is targeted at somebody else.
It was, but in any case you have to have server to deliver your code. hqjs.org is the server that avoid bundling and ensure that you browser get as little code as possible to run your app. It might not suite if you want to serve your app let's say from github, but can do the trick in m any other cases.
Looks interesting. In the past, I used Stencil.js, though. Might be replaceable with hqjs, (with jsx-to-html converter, just to avoid long html strings).
aloud-comments.web.app/
HTML/CSS & JS will all survive for the time being. But yes, WebAssembly will make the same path I outlined here. Right now it's a little "clunky" to use, but that will change and will surely expand the web in a way never seen possible. What Google started with ChromeOS might progress into the next logical step: PCs will become simple "Internet terminals" and everything will be available through what we call a browser today.
As for the framework question: As mentioned, I like it simple and small. Since I personally work a lot backend, lit-html and axios is all I need to fulfill my needs.
Surprisingly enough, you were indeed right about Web Components being "easy". Thanks for the neat introduction! I'll definitely start on a toy project for experimentation.
Thank you! This is exactly what I intended for the reader to take away from it.