Liquid syntax error: Unknown tag 'endraw'
For further actions, you may consider blocking this person and/or reporting abuse
Liquid syntax error: Unknown tag 'endraw'
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (4)
super()calls its parent classconstructorwhich a class does by default if there is noconstructordefined; so you can leave out those 3 lines.The
connectedCallbackruns on the opening tag; so its innerHTML is not defined yet.querySelectoron this lightDOM will returnundefinedvalues.Your code only works because it defines the component after DOM is created.
You want your components as self contained as possible; if you want users to include their own (inner)HTML; shadowDOM with
<slot>is the best approach.It is your own component; No one else (most likely) is going to append Eventlisteners inside your component; thus bloated
addEventListener()is not required.Refactored
<x-timers>can be:What do you mean by this? I think I may have misunderstood the lifecycle methods.
I went this approach to showcase different ways to author the component (creating elements with JavaScript and progressively enhancing with JavaScript). In this context there isn't too much benefit with the progressive enhancement approach, so your refactored version works great.
Good shout on the shadom DOM approach too. That's what I'm working on now for the follow up post.
Why do you think
addEventListeneris bloated? My understanding was that it's just a declarative alternative to overriding theonclickproperty. I couldn't find any documentation on this to suggest there might be a performance impact.connectedCallback
Update: see long read Dev.to post: Developers do not connect with the connectedCallback (yet)
Experience yourself; FOO is NOT logged to the console, BAR is logged
Because
connectedCallback()is executed on the OPENING tag (and when DOM nodes are moved around!)So for component1
this.innerHTMLis referencing DOM that does not exist/isn't parsed yet.Many developers, even libraries that make programming Web Components "easier", do
<script defer src="...">to force all their components to load like component 2They don't understand the behavior, thus use
defer. They probably use!importantas well when they do not understand CSS Specificity.LifeCycle Methods:
andyogo.github.io/custom-element-r...
Event listeners
addEventListenerdoesn't override/writeonclick. It is bloated because usingonclickis shorter.Use the ones that do the job for you: javascript.info/introduction-brows...
Thank you! I'll check it out