Go Make Things
Go Make Things
  • 231
  • 83 160
Can I convert a React app into a vanilla Web Component!?!
Source code: gist.github.com/cferdinandi/aaa0ccf87ea2acd56472244a37622673
Work on fun projects like this at the Lean Web Club. Sign up for free at leanwebclub.com.
Hate the complexity of modern front‑end web development? I teach people a simpler, faster way to build for the web. Get free Daily Developer Tips at gomakethings.com.
⏳ Timestamps
00:00 - Intro
00:45 - Lean Web Club
02:00 - Rendering the Initial UI
09:27 - Build Game Play
23:15 - Track Game History
57:55 - Conclusion
zhlédnutí: 829

Video

Episode 146 - It lets me write less JS!
zhlédnutí 175Před 14 dny
In today’s episode, I talk about why writing less JS might be a bad goal (what!?!).In today’s episode, I talk about why writing less JS might be a bad goal (what!?!). Show Notes & Transcript → (gomakethings.com/podcast/it-lets-me-write-less-js/) 🎉 Preorder Getting Sh!t Done (adhdftw.com/getting-shit-done/) today and get 40% off! Be more productive, get more done, and feel more in-control of you...
Can you customize Web Components without a framework!?
zhlédnutí 1,1KPřed 21 dnem
Source code: gist.github.com/cferdinandi/9429aadec4790f6e85e11e83dacc31d0 Work on fun projects like this at the Lean Web Club. Sign up for free at leanwebclub.com. Hate the complexity of modern front‑end web development? I teach people a simpler, faster way to build for the web. Get free Daily Developer Tips at gomakethings.com. ⏳ Timestamps 00:00 - Intro 01:30 - Lean Web Club 02:05 - Customizi...
Episode 145 - The Shadow DOM is an anti-pattern
zhlédnutí 168Před 21 dnem
In today’s episode, I talk about why I think the Shadow DOM is a solution in search of a problem.In today’s episode, I talk about why I think the Shadow DOM is a solution in search of a problem. Show Notes & Transcript → (gomakethings.com/podcast/the-shadow-dom-is-an-anti-pattern/) 🎉 Preorder Getting Sh!t Done (adhdftw.com/getting-shit-done/) today and get 40% off! Be more productive, get more ...
Can you build a web app with vanilla Web Components in 2024 - PART 2!
zhlédnutí 1,1KPřed měsícem
Source code: gist.github.com/cferdinandi/308b4721cf8a8d762098e09398498866 Part 1: czcams.com/video/2S4-42vjZwY/video.html Work on fun projects like this at the Lean Web Club. Sign up for free at !leanwebclub.com. Hate the complexity of modern front‑end web development? I teach people a simpler, faster way to build for the web. Get free Daily Developer Tips at gomakethings.com. ⏳ Timestamps 00:0...
Can you build a web app with vanilla Web Components in 2024?!?
zhlédnutí 4,9KPřed měsícem
Source code: gist.github.com/cferdinandi/088d7f4ca088f7becd911e3e60efeec1 Work on fun projects like this at the Lean Web Club. Sign up for free at leanwebclub.com. Hate the complexity of modern front‑end web development? I teach people a simpler, faster way to build for the web. Get free Daily Developer Tips at gomakethings.com. ⏳ Timestamps 00:00 - Intro 01:04 - Lean Web Club 02:18 - Building ...
How to build a show-hide component with JavaScript
zhlédnutí 646Před měsícem
Source code: gist.github.com/cferdinandi/813b8d599c98e68a4dd4616f9cc545ed W3C ARIA Authoring Guidelines: www.w3.org/WAI/ARIA/apg/patterns/disclosure/ Get coaching, courses, and coding resources at leanwebclub.com. Hate the complexity of modern front‑end web development? I teach people a simpler, faster way to build for the web. Get free Daily Developer Tips at gomakethings.com.
How to build your first Web Component
zhlédnutí 2,1KPřed měsícem
Source code: gist.github.com/cferdinandi/5af9447941b64c1b58897ada14bf42aa Hate the complexity of modern front‑end web development? I teach people a simpler, faster way to build for the web. Get free Daily Developer Tips at gomakethings.com.
HTML Web Components
zhlédnutí 984Před 2 měsíci
While Web Components have been around for years, they're seeing a bit of a renaissance thanks to an emerging approach for authoring them: ditch the shadow DOM and progressively enhance existing HTML. In this talk, we'll look at what Web Components, how the "HTML Web Component" approach works, why it's awesome, and some tips, tricks, and gotchas when working with them. Hate the complexity of mod...
Episode 144 - Front end devs do not understand web accessibility
zhlédnutí 231Před 4 měsíci
In today’s episode, I talk about some awful comments on Hacker News, and why they're wrong.In today’s episode, I talk about some awful comments on Hacker News, and why they’re wrong. Show Notes & Transcript → (gomakethings.com/podcast/front-end-devs-do-not-understand-web-accessibility/) 🎉 Preorder Getting Sh!t Done (adhdftw.com/getting-shit-done/) today and get 40% off! Be more productive, get ...
Episode 143 - Vanilla JS doesn't scale
zhlédnutí 189Před 5 měsíci
In today’s episode, I talk about some nonsense developer sometimes spout about vanilla JavaScript.In today’s episode, I talk about some nonsense developer sometimes spout about vanilla JavaScript. Show Notes & Transcript → (gomakethings.com/podcast/vanilla-js-doesnt-scale/) 🎉 Preorder Getting Sh!t Done (adhdftw.com/getting-shit-done/) today and get 40% off! Be more productive, get more done, an...
Episode 142 - PHP Islands Architecture
zhlédnutí 104Před 5 měsíci
In today’s episode, I talk about using PHP with a static site generator to build fast, resilient websites with dynamic content.In today’s episode, I talk about using PHP with a static site generator to build fast, resilient websites with dynamic content. Show Notes & Transcript → (gomakethings.com/podcast/php-islands-architecture/) 🎉 Preorder Getting Sh!t Done (adhdftw.com/getting-shit-done/) t...
Episode 141 - My obsidian setup
zhlédnutí 189Před 5 měsíci
In today’s episode, I talk about my setup in Obsidian.In today’s episode, I talk about my setup in Obsidian. Show Notes & Transcript → (gomakethings.com/podcast/my-obsidian-setup/) 🎉 Preorder Getting Sh!t Done (adhdftw.com/getting-shit-done/) today and get 40% off! Be more productive, get more done, and feel more in-control of your work and life. Click here to learn more. (adhdftw.com/getting-s...
Episode 140 - Getting stuff done as a developer with ADHD
zhlédnutí 401Před 5 měsíci
In today’s episode, I talk about how to get stuff done as a developer with ADHD.In today’s episode, I talk about how to get stuff done as a developer with ADHD. Show Notes & Transcript → (gomakethings.com/podcast/getting-stuff-done-as-a-developer-with-adhd/) 🎉 Preorder Getting Sh!t Done (adhdftw.com/getting-shit-done/) today and get 40% off! Be more productive, get more done, and feel more in-c...
Episode 139 - Detecting when a Web Component is loaded with CSS
zhlédnutí 89Před 5 měsíci
In today’s episode, I talk about to detect when a Web Component is loaded using just CSS.In today’s episode, I talk about to detect when a Web Component is loaded using just CSS. Show Notes & Transcript → (gomakethings.com/podcast/detecting-when-a-web-component-is-loaded-with-css/) 🎉 Preorder Getting Sh!t Done (adhdftw.com/getting-shit-done/) today and get 40% off! Be more productive, get more ...
15 super rad web developer tricks (few people know this!)
zhlédnutí 430Před 9 měsíci
15 super rad web developer tricks (few people know this!)
Two-way data-binding and reactivity with 15 lines of JS
zhlédnutí 844Před 10 měsíci
Two-way data-binding and reactivity with 15 lines of JS
Episode 134: The craft of the web
zhlédnutí 321Před 10 měsíci
Episode 134: The craft of the web
How to build your first Web Component in less than 5 minutes
zhlédnutí 331Před 10 měsíci
How to build your first Web Component in less than 5 minutes
Episode 133: Learning JavaScript
zhlédnutí 237Před 10 měsíci
Episode 133: Learning JavaScript
How to choose between let and const in JavaScript (just use let!)
zhlédnutí 138Před 10 měsíci
How to choose between let and const in JavaScript (just use let!)
Arrow functions vs. traditional functions in JavaScript
zhlédnutí 221Před 10 měsíci
Arrow functions vs. traditional functions in JavaScript
The early return pattern in JavaScript
zhlédnutí 269Před 10 měsíci
The early return pattern in JavaScript
The problem with SPAs (they suck!)
zhlédnutí 555Před 10 měsíci
The problem with SPAs (they suck!)
Episode 132: Dave Letorey on the State of the Browser Conference
zhlédnutí 168Před 10 měsíci
Episode 132: Dave Letorey on the State of the Browser Conference
Episode 131: Using the platform when its not evenly distributed
zhlédnutí 73Před 11 měsíci
Episode 131: Using the platform when its not evenly distributed
Episode 130: The fear of keeping up
zhlédnutí 97Před 11 měsíci
Episode 130: The fear of keeping up
Calling serverless function APIs with vanilla JavaScript
zhlédnutí 185Před 11 měsíci
Calling serverless function APIs with vanilla JavaScript
Deploying serverless functions with Cloudflare Workers
zhlédnutí 433Před 11 měsíci
Deploying serverless functions with Cloudflare Workers
Creating serverless functions with Cloudflare Workers (for free!)
zhlédnutí 289Před 11 měsíci
Creating serverless functions with Cloudflare Workers (for free!)

Komentáře

  • @frumbert
    @frumbert Před 22 hodinami

    You could build a tic tac toe using html, no javascript. Lots of files though, one for each state the board could be in. Clicking a cell links to the hpertext file representing the new state. Inherent history/undo as well. That way it could even work on the Lynx browser.

  • @terryweb
    @terryweb Před dnem

    Amazing tricks, except #13... 😀

  • @IainSimmons
    @IainSimmons Před 2 dny

    Great video! I'd love to see more of these types of videos, comparing JS framework code to regular light DOM HTML web components! One thing about your app logic... Can you not just use the fact that the next move alternates between X and O and whether the index of the history is odd or even to determine what it should be? And can you just remove the list items and history with an index higher than the clicked one, in handleJumpTo?

  • @kanaillaurent526
    @kanaillaurent526 Před 2 dny

    Thank you I like that. This is how I work too with webcomponents: TDD on the browser when the webcomponent is not very complicated. Also I used to store the state in the DOM too but I've changed my method because I've founded that it's more complicated in a complex application. Now i store the state of the whole application in a centralized object (a little bit like redux does). Unfortunately I don't have the observation (subscribe and dispatch) mecanism yet in place but I'm working on it.

  • @svivian
    @svivian Před 3 dny

    “I like to use const for everything” *immediately changes const to let* 😆

    • @chritical_ep
      @chritical_ep Před 19 hodinami

      He might have misspoke, I remember in one newsletter he said he used let for everything, so he might have got them switched up

  • @dovh49
    @dovh49 Před 3 dny

    Van JS is a good alternative too. I was thinking for the history creating a square custom element and then storing all that information in there and then looping through the custom elements to update any history. Like `square.removeHistory(3)` Where 3 would be the history index. And when adding a value you can do `square.setValue('X', historyIndex)`. Something like that. Then you have a different class handling a lot of the things.

  • @terrencemoore8739
    @terrencemoore8739 Před 4 dny

    Amazing video idea. I always wondered how different making custom web components are to react implementations

    • @terrencemoore8739
      @terrencemoore8739 Před 3 dny

      Just tried making a web component without using the shadow dom, it worked great!

  • @SuicideDog
    @SuicideDog Před 4 dny

    im starting out in development. done a 2 year course on front-end where a lot of focus was on react. i feel like there are a lot of basic javascript knowledge that has flown over my head by transitioning over to react too quickly. I really like this type of content. because by comparing and practicing vanilla. It at least feels like i get a deeper understanding on how the language work, and how different programming logic and approaches can be applied. so super thankful:)

  • @cloudpuncher4615
    @cloudpuncher4615 Před 4 dny

    How did you write the Custom Element innerHTML in the constructor? I get an error unless I attachShadow and write the shadowRoot innerHTML....

    • @dovh49
      @dovh49 Před 3 dny

      The source code is in the description. Maybe you're doing something that is a little off?

  • @davidluhr
    @davidluhr Před 4 dny

    This is a great demonstration of the value of writing vanilla JavaScript: When you write framework code, you improve your skills in the framework. When you write vanilla JavaScript, you improve your skills in JavaScript as a whole. Sure, you use some vanilla JavaScript in React, but it's a narrower slice. Even if you create solutions that can React solve in its own way, your solution is tailored to your specific needs and context, and you gain more transferable knowledge along the way.

  • @k16e
    @k16e Před 4 dny

    JavaScript owes you, mentor. Then so does the community. Thanks for keeping me in check.

  • @bourge
    @bourge Před 8 dny

    I ran into problems when i tried to use a vanilla WC in a Next.js. Turns out SSR apps are not to friendly to WCs. Are there any thing we can do to solve this?

    • @gomakethings
      @gomakethings Před 5 dny

      I'd need more specifics about the errors you're seeing to answer that.

    • @bourge
      @bourge Před 5 dny

      @@gomakethings There are flash effects on every page loads. This is only for Nextjs apparently due to the way it handles hydration of the DOM.

  • @Alex-BSD
    @Alex-BSD Před 9 dny

    The CV says "senior" but the code has "document.getElementById"

  • @FlorianSchommertz
    @FlorianSchommertz Před 9 dny

    Am I correct that not using shadow DOM forces you to run the script after the DOM has loaded?

    • @gomakethings
      @gomakethings Před 5 dny

      No, that's just how DOM manipulation works in general. It's not specific to the shadow DOM (or lack thereof). If you target elements that don't exist yet, you'll get errors.

  • @tubeta028
    @tubeta028 Před 10 dny

    I like this, good video thanks

  • @YoungLink51423
    @YoungLink51423 Před 16 dny

    Starting this series now

  • @ba8e
    @ba8e Před 18 dny

    Why shuffle the array when you can just get a random index? array[Math.floor(Math.random() * array.length)]

    • @gomakethings
      @gomakethings Před 5 dny

      Historically, the Fisher-Yates shuffle produced more random results than a simple Math.random(), which tends to skew towards the middle over time. MDN used to have details about this on their site, but they're not longer there.

  • @CristianKirk
    @CristianKirk Před 20 dny

    Thanks a lot. This series is being very useful and it's hard to believe there are no more channels teaching about web components..

  • @pl4gueis
    @pl4gueis Před 20 dny

    "Developer ergonomics and ease of authoring code" holds true for the first 5 minutes of developing react. Once you add all the hooks, router, redux, component library, jss its all over. Adding abstractions to fix the horrible abstractions until you have a mess that is most react projects.

  • @damvaz
    @damvaz Před 20 dny

    Great content!!! Ideas for new contents? What about "making a new simple design system" (framework agnostic) using web componentes and css best practices?

  • @evilspymace209
    @evilspymace209 Před 20 dny

    i'm guilty for using web components as an alternative to vue. right now i'm rewriting a SPA. i wanted to avoid the excessive tooling and ever changing apis. honestly it's so much more fun!

  • @pl4gueis
    @pl4gueis Před 20 dny

    Great series. How would I go about writing tests for these web components?

    • @gomakethings
      @gomakethings Před 5 dny

      Same way you'd test any DOM manipulation component. Jest is well suited to it, I think.

  • @BenHewart
    @BenHewart Před 21 dnem

    I think its great that a youtube channel is finally doing native web components! I love it... and love web components but I think I disagree with the shadow dom being an anti pattern and styling is way easier being encapsulated... components are mean't to be self contained so they can be used through out any project without clashes with global code. if you want global styling the you simply create a global style sheet and use custom properties ( or css variables ) Global style sheet: :root { --bg-blue: ##4187f7; } component styles: <style> background-color: var(bg-blue); </style> Another issue mixing light and shadow dom is CLS obviously light dom will load first loading content first and then loads in shadom dom after this causing jumping, as far as I can see its better to stick to the shadom dom or the light not to mix them.... otherwise you will have to constantly reserve space for the shadow dom Open if anyone has any other solutions? Still learning all the awesomeness of web components thanks and keep up the great work!

    • @gomakethings
      @gomakethings Před 5 dny

      I think this is a symptom of thinking about Web Components as React components rather than their own, unique thing. React has poisoned the web well. gomakethings.com/html-web-components/

    • @BenHewart
      @BenHewart Před 5 dny

      Oh I totally agree that react has ruined the web.... I am massive on core web vitals and have built a web app using only native web components with html CSS and vanilla js.... That scores 100 across the board... The problem I found and if you have any suggestions is that if you mix the light Dom and the shadow dom it causes CLS... So the only way was to use web components that are self contained.

    • @gomakethings
      @gomakethings Před 5 dny

      @@BenHewart Forgive me, but what does CLS stand for?

    • @BenHewart
      @BenHewart Před 5 dny

      CLS (Cumulative Layout Shift) measures visual stability in Core Web Vitals. It quantifies how much elements on a page move unexpectedly as it loads. High CLS means a poor user experience, as content shifting can disrupt interactions. As the light Dom loads first and then native web components it can make elements jump about as the page loads hence I went for a full shadow dom component to fix this

    • @BenHewart
      @BenHewart Před 5 dny

      Happy to show you if your interested no pressure 😉

  • @rustyprogrammer
    @rustyprogrammer Před 21 dnem

    Thanks, very clear :-). I wonder why, in the count component, you inherit from the HTMLElement and not directly from HTMLButtonElement?

    • @gomakethings
      @gomakethings Před 21 dnem

      This comes up a lot! There are two reasons: 1. The Web Component itself isn't a button. One of it's child elements is. If I wanted the custom element itself to behave like a button, I'd also need to add stuff like a `role` attribute and additional event listeners. 2. That's also unfortunately not how Web Components work. You extend the HTMLElement, then layer in your custom behavior. You can't reliably extend other element types with customElements.define(). There was a spec in the works that would let you extend native elements with custom functionality using `is` attribute. Firefox and Chromium moved forward with it, and then the WebKit team straight up refused to implement it, effectively killing the spec. developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/is My understanding is that there's a replacement spec in the works that WebKit is allegedly onboard with, but I don't know much about it at this time as it's nowhere near production ready.

  • @etherweb6796
    @etherweb6796 Před 23 dny

    The answer is yes

  • @coderlicious6565
    @coderlicious6565 Před 26 dny

    Do you think this is a good way to go, using a cloudflare serverless function, if you're creating a chrome extension that calls the Notion api ( but notion doesn't allow you to make calls from the extension ). I need something somewhere on a paid server, that receives some text data, and then makes the call to notion api which makes notion happy. I was also looking at supabase for their serverless function capability.

    • @gomakethings
      @gomakethings Před 21 dnem

      Could be! Could get expensive for a public extension, of course. The whole benefit of "serverless" is that you don't have to worry about maintaining the server, just the function (or functions) that run on it.

  • @kodejohan
    @kodejohan Před 26 dny

    Very interesting approach!

  • @sonnyl2915
    @sonnyl2915 Před 26 dny

    Luv it! Question: I've got troubled running into swapping elements issue. How do you have all the elements within the web-component readily in order for execution by the DOM? Sometimes in the console window said undefined or not found?

    • @gomakethings
      @gomakethings Před 26 dny

      I wrote a little bit about this a few weeks ago: gomakethings.com/the-different-ways-to-instantiate-a-web-component/ If you have a specific example in a code pen or GitHub repo you'd like me to look at, though, that works too!

  • @cmilne10
    @cmilne10 Před 26 dny

    great series. Informative and simple

  • @terhuneb
    @terhuneb Před 27 dny

    Thank you for mentioning an ES Module implementation too.

  • @dirtdart81
    @dirtdart81 Před 27 dny

    Really enjoying this series! I'm not new to programming, but new to web/js and it is an interesting time to be learning. As flavor of the week frameworks go in and out, this kind of 'back-to-basics' feels timely. Thanks for the videos!

    • @gomakethings
      @gomakethings Před 26 dny

      You're welcome! If you have any questions along the way, feel free to ask!

  • @jonathanoden6854
    @jonathanoden6854 Před 29 dny

    Hello, thank you very much for the work you are doing in sharing good practices on how the web could be done! Web components didn't clicked for me until I saw your daily tips. I had this bad feeling using shadow dom and kind of full javascript components. Now, with 'enhanced html elements' it feels really nice and deeply connected to html and css. I see here you are using attributes without 'data-' prefix, is there a reason for that? Again, thanks a lot!

    • @gomakethings
      @gomakethings Před 28 dny

      They're invalid, and I should probably stop doing it. In my mind, if I'm creating a custom element, I like to use custom attributes with it. An HTML validator will complain about them, but CSS and JavaScript will work with them just fine. For safety, I could also add a dash to the names to ensure no conflicts with future attribute names. I lean heavily on attributes in my web components, and having to write data-* constantly is fatiguing, IMO.

  • @NeilMerton
    @NeilMerton Před měsícem

    I’m enjoying the series, thanks for putting these together 👍 Do you have any plans on showing option on how to encapsulate the web component code within the component itself and how that then gets consumed by the HTML? I hope this makes sense.

    • @gomakethings
      @gomakethings Před měsícem

      Thanks! Can you clarify what you mean by this: "ow to encapsulate the web component code within the component itself and how that then gets consumed by the HTML?" I'd be delighted to make a vide about if, once I better understand what you're asking.

    • @NeilMerton
      @NeilMerton Před měsícem

      Sure. What I see in these two videos is you’ve got the ‘pick-at-random.html’ file that contains ‘pick-at-random’ element and below that the JavaScript to make it work. How is this then reusable? For example, I’d like to use it on a different page, how would I go about doing that. Let me know if you’d like me to elaborate further.

    • @gomakethings
      @gomakethings Před měsícem

      @@NeilMerton Yep, that helps a lot. Thanks Neil!

  • @netssrmrz
    @netssrmrz Před měsícem

    The event management feels clumsy. Do you have or could you do a video covering it in more detail? As in pros and cons compared to other methods. I'm wondering if I should change my approach.

  • @NicklasIsraelsson
    @NicklasIsraelsson Před měsícem

    Thanks for sharing! Very nice. Looking forward to the next session. One thing I would like to see is the thing at the end you briefly mentioned. How would you "upgrade" this to use the dialog element instead of confirm?

    • @gomakethings
      @gomakethings Před měsícem

      GREAT suggestion! Let me add that to the list!

  • @sanderlissenburg1608
    @sanderlissenburg1608 Před měsícem

    It's better to use the connectedCallback instead of the constructor. I ran into an issue that the javascript was loaded before the dom was loaded/ready. This is because I load the javascript in the head instead of the bottom of the page. I know I know I should change that. Either way I think using the connectedCallback is still better.

    • @gomakethings
      @gomakethings Před měsícem

      "Better" isn't the word you're looking for. "Can prevent issues in certain contexts." The problem you're describing can still happen even when using connectedCallback. There are a bunch of strategies to fix it. But in your case, DOM scripts should be loaded in the footer or use async/defer or be wrapped in a DOMContentLoaded event. What you're describing would happen if you were using plain old DOM manipulation methods, too. More on all of that here: gomakethings.com/the-different-ways-to-instantiate-a-web-component/

    • @sanderlissenburg1608
      @sanderlissenburg1608 Před měsícem

      Thnx for the reply and extra info!

  • @aniltheblogger
    @aniltheblogger Před měsícem

    what about lit framework?

    • @gomakethings
      @gomakethings Před měsícem

      I don't like it, personally: gomakethings.com/what-about-lit-for-web-components/

  • @netssrmrz
    @netssrmrz Před měsícem

    Good video. IMO a couple of mistakes though. One, the spec insists we do NOT add/remove elements in the constructor. Two, persistence (localstorage) should be handled externally to the component.

    • @gomakethings
      @gomakethings Před měsícem

      Regarding the spec: it doesn't actually say that, though most people (including me, previously) interpreted it that way. "The specification recommends that, as far as possible, developers should implement custom element setup in this callback rather than the constructor." Does setup mean add/remove elements? Attach events? Something else? It's not clear. Hawk Ticehurst has a great article on this: hawkticehurst.com/writing/you-are-probably-using-connectedcallback-wrong/ What I do know is that setting up elements in connectedCallback is a bad idea, because it can lead to the same elements being rendered multiple times if an element is, for example, moved with the append() method. You can prevent it by using special .loaded properties or whatever, but just doing it once in the constructor() is, IMO, a lot more bulletproof and simple.

    • @gomakethings
      @gomakethings Před měsícem

      Regarding localStorage, there are many ways to handle it. Outside the component (with some event to trigger the behavior) is one possible solution. Calling it a mistake is disingenous, though. What you really mean is "I would have approached this differently." That's fine, of course. The best and worst thing about JS is that there's always more than one way to do a thing. But the approach I used in this unscripted first pass isn't a mistake. It's just not what you would have done.

    • @netssrmrz
      @netssrmrz Před měsícem

      @@gomakethings re constructor: Spec seems very clear to me. MDN: "In the class constructor... you should not add new attributes or children". HTML Standard 4.13.2: "When authoring custom element constructors... The element must not gain attributes or children." And you can prevent double loading by using methods like replaceChidren(). Hawk's post is about event listeners and not rendering child elements.

    • @netssrmrz
      @netssrmrz Před měsícem

      @@gomakethings re localstorage: I'm not going to sugarcoat my take for a grown man. In my opinion, it is a mistake to couple this UI component to a persistence mechanism (you know why, I know why, everyone knows why). Granted your solution is passable as a first draft for educational purposes but it can be easily improved, and should be. In my opinion.

    • @gomakethings
      @gomakethings Před měsícem

      @@netssrmrz I'm not asking you to "sugarcoat" anything. But let's be clear: your opinion is not the same thing as fact. You disliking something doesn't make it wrong. Senior developers constantly and arrogantly insisting something non-obvious is obvious is, frankly, why I have students. I'm asking you to engage in polite discussion. If you want to do the techbro reply guy thing, this isn't the right channel for you. This is the only time I'm going to say it. Next time, you get blocked.

  • @davidluhr
    @davidluhr Před měsícem

    Completely agree on treating the DOM as the state of the application. It's so much simpler and the available DOM APIs are powerful. My personal favorite is using the `append` method. If the appended element is new, it'll add it to the DOM. If it already exists, it'll automatically move it into the new position with no additional work needed.

    • @gomakethings
      @gomakethings Před měsícem

      I obviously had to keep going into the DOM a fair bit for this one, but case studies like this reinforce that it's the better approach for me: gomakethings.com/removing-react-dramatically-improves-performance-a-case-study/

  • @CristianKirk
    @CristianKirk Před měsícem

    Great stuff, thanks a lot!

  • @sueaustin6261
    @sueaustin6261 Před měsícem

    would adding a title to the button svg serve as accessibility? i've heard to not mess with aria unless you really know what you're doing.

    • @gomakethings
      @gomakethings Před měsícem

      In theory, yes, that should be enough. In reality, it's not. 😞 Many screen reader/browser combinations will NOT announce the <title> unless you add an aria-labeledby attribute to the SVG, with a value that points to the ID of the <title>. In the end, since you're messing with ARIA anyways, aria-label is the least complicated way to do that.

    • @davidluhr
      @davidluhr Před měsícem

      @@gomakethings Only downside of `aria-label` is it isn't translatable. For buttons and links, I stick with visually hidden text, which I'm fine appearing if CSS doesn't load. For landmark elements, I use `aria-labelledby` and point it to the corresponding section heading.

    • @gomakethings
      @gomakethings Před měsícem

      @@davidluhr Agreed! I've had accessibility experts argue both approaches to me over the years. For this particular project, I went with the easiest one to implement, but probably could have discussed the tradeoffs a bit more.

  • @PDSRoxas
    @PDSRoxas Před měsícem

    Thank you, thank you, thank you for including aria and accessibility stuff. So many tutorials omit this, and it’s frustrating. Accessibility stuff should be built into codes and projects from the beginning.

    • @gomakethings
      @gomakethings Před měsícem

      Couldn't agree more! It's sad that this isn't the norm in dev education.

  • @tithos
    @tithos Před měsícem

    I know you are The vanilla JS guy, but you teach me more about ARIA that anyone. THANKS

    • @gomakethings
      @gomakethings Před měsícem

      I'm both delighted and saddened to hear that! Glad you appreciate, but a huge bummer that most tech educators never cover it.

  • @HeribertSchuetz
    @HeribertSchuetz Před měsícem

    Are you planning to use the shuffled array for further functionality? Currently it feels like overkill. It should suffice to just use a random index to pick an item. The `shuffle` method could be removed and the body of the `onclick` method would just become let items = this.list.querySelectorAll('li'); let item = items[Math.floor(Math.random() * items.length)]; this.result.textContent = `You picked ${item.textContent}`;

    • @gomakethings
      @gomakethings Před měsícem

      I could do that, yea. Historically, `Math.random()` has provided a less uniformly random shuffle than the Fisher-Yates algorithm. I'm not worried about the 473 extra bytes, personally.

    • @HeribertSchuetz
      @HeribertSchuetz Před měsícem

      @@gomakethings I wasn't worried about the extra bytes, at least not primarily. Sometimes 20%+ extra code might well be worthwhile if the code becomes more readable. But my impression was that the added complexity makes the code harder to read for people who will have to maintain it or, in this particular case, for your audience. And regarding Fisher-Yates: It may well be true that Fisher-Yates is better than other shuffling methods. But here no shuffling is needed. (And BTW, the shuffle method uses Math.random() as well.) Finally, please don't get me wrong if I appear to be nit-picking. I like your videos and I just wanted to help improving. (Unfortunately youtube has no versioning support...)

    • @gomakethings
      @gomakethings Před měsícem

      @@HeribertSchuetz I took this as a kindly discussion among peers, so no worries at all! I agree about making the code harder to read.

  • @patriciodelboca7898
    @patriciodelboca7898 Před měsícem

    I'm extremely excited about Web Components! Thanks for the tutorial! It feels fresh, straight to the point and clear!

    • @gomakethings
      @gomakethings Před měsícem

      Thank you so much for the kind words!

  • @muhaimincs
    @muhaimincs Před měsícem

    How do you organize the code? How do you load the data? How to handle racing condition? How do you handle state of components without shadow dom? How about you just rephrase this YT video title?

    • @gomakethings
      @gomakethings Před měsícem

      1. I addressed state directly in this video already. 2. As I mentioned IN THE VIDEO, there's a part two coming that will cover loading the data. 3. There's no race conditions to worry about in this simple app. 4. This isn't a video about organizing code. 5. How about I just leave the title as is.

  • @cb73
    @cb73 Před měsícem

    I’m not sure how you can say the shadow dom is an anti-pattern - whatever that means. I would think the reason why most devs reach for web components, myself included, is to make our components usable on other peoples websites, the sites we have zero control over. I work for a company that does personalization and it’s critical that our components look and feel are not at all affected by the host site - and vice versa. I don’t think this is an edge case, it’s the promise web components offer.

    • @gomakethings
      @gomakethings Před měsícem

      The Shadow DOM... 1. Adds additional complexity to the Web Component authoring experience. 2. Can introduce accessibility issues. 3. Makes components much harder to style. 4. Prevents the component from taking advantage of global styles. 5. Is often a solution in search of a problem. 6. Tries to let WC's do things "the React way," but React does those things better.

    • @netssrmrz
      @netssrmrz Před měsícem

      I agree with GoMakeThings. I've worked on several WC projects at various companies including building component libraries and 90% of the time we've needed to deliver highly customisable components. From my experience Shadow DOM feels like an edge case. Anyway, once you have "open" components its trivial to wrap them in a closed Shadow DOM version.

    • @cb73
      @cb73 Před měsícem

      The very first paragraph on the web components documentation page immediately highlights encapsulation as its primary feature. I think you’re just trying to sound controversial by calling it an anti-pattern. It’s fine if you don’t prefer to use it that way but please don’t tell your audience they are doing it wrong. Do they make things more complex? Maybe but compared to what? Not all complexity is bad. It depends on the context.

    • @gomakethings
      @gomakethings Před měsícem

      @@cb73 Nope. I've built a LOT of Web Components. The benefits of the Shadow DOM, in my experience, are grossly outweighed by its many disadvantages. Isn't it strange how Web Components have been around for years, but only really started taking off once a bunch of folks started saying, "Hey, you don't actually need the Shadow DOM"?

  • @netssrmrz
    @netssrmrz Před měsícem

    Nice video. 100% agree on shadow dom usage.

    • @pragmasoft
      @pragmasoft Před měsícem

      Shadow dom is not all black or white. It very much depends on the functionality of your web components. Web components scope is not limited to only wrapping forms and inputs, even if in majority of cases it is.

    • @netssrmrz
      @netssrmrz Před měsícem

      @@pragmasoft I've been using Web Components for several years (to build full apps ;) and I agree with "Go Make Things" that shadow DOM functionality is only required in edge cases, for the same reasons he stated. Unfortunately, most tutorials overcomplicate things by appearing to make shadow DOM mandatory.

  • @rupen42
    @rupen42 Před měsícem

    I'd love to watch this but I can't look at a white screen for 30 minutes

    • @gomakethings
      @gomakethings Před měsícem

      Sorry about that! I use a white background for my videos because it has better contrast and is thus a better choice for folks with certain vision issues. I do recognize the white can be intense, though.

    • @d.o.nmuzic3802
      @d.o.nmuzic3802 Před měsícem

      😂 100%!

  • @uiuxaidesign
    @uiuxaidesign Před měsícem

    that's so cool