Go Make Things
Go Make Things
  • Видео 232
  • Просмотров 84 585
Can I add state-based UI to a Web Component?
Source code: gist.github.com/cferdinandi/3dc2826f88dd5195a113d79e399ffc91
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:32 - Recap of Project
02:15 - What is state-based UI?
05:04 - Converting the Component
32:38 - Debugging Jump-To-Move
41:00 - Wrapping Up
Просмотров: 567

Видео

Can I convert a React app into a vanilla Web Component!?!
Просмотров 1,1 тыс.21 час назад
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...
Episode 146 - It lets me write less JS!
Просмотров 18221 день назад
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!?
Просмотров 1,1 тыс.Месяц назад
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
Просмотров 17428 дней назад
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!
Просмотров 1,1 тыс.Месяц назад
Source code: gist.github.com/cferdinandi/308b4721cf8a8d762098e09398498866 Part 1: ruclips.net/video/2S4-42vjZwY/видео.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:...
Can you build a web app with vanilla Web Components in 2024?!?
Просмотров 5 тыс.Месяц назад
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
Просмотров 655Месяц назад
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
Просмотров 2,1 тыс.Месяц назад
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
Просмотров 1 тыс.2 месяца назад
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
Просмотров 2324 месяца назад
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
Просмотров 1905 месяцев назад
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
Просмотров 1055 месяцев назад
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
Просмотров 1915 месяцев назад
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
Просмотров 4015 месяцев назад
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
Просмотров 896 месяцев назад
Episode 139 - Detecting when a Web Component is loaded with CSS
15 super rad web developer tricks (few people know this!)
Просмотров 43710 месяцев назад
15 super rad web developer tricks (few people know this!)
Two-way data-binding and reactivity with 15 lines of JS
Просмотров 86310 месяцев назад
Two-way data-binding and reactivity with 15 lines of JS
Episode 134: The craft of the web
Просмотров 32110 месяцев назад
Episode 134: The craft of the web
How to build your first Web Component in less than 5 minutes
Просмотров 33110 месяцев назад
How to build your first Web Component in less than 5 minutes
Episode 133: Learning JavaScript
Просмотров 23810 месяцев назад
Episode 133: Learning JavaScript
How to choose between let and const in JavaScript (just use let!)
Просмотров 13810 месяцев назад
How to choose between let and const in JavaScript (just use let!)
Arrow functions vs. traditional functions in JavaScript
Просмотров 22210 месяцев назад
Arrow functions vs. traditional functions in JavaScript
The early return pattern in JavaScript
Просмотров 27310 месяцев назад
The early return pattern in JavaScript
The problem with SPAs (they suck!)
Просмотров 55610 месяцев назад
The problem with SPAs (they suck!)
Episode 132: Dave Letorey on the State of the Browser Conference
Просмотров 16911 месяцев назад
Episode 132: Dave Letorey on the State of the Browser Conference
Episode 131: Using the platform when its not evenly distributed
Просмотров 7311 месяцев назад
Episode 131: Using the platform when its not evenly distributed
Episode 130: The fear of keeping up
Просмотров 9711 месяцев назад
Episode 130: The fear of keeping up
Calling serverless function APIs with vanilla JavaScript
Просмотров 18711 месяцев назад
Calling serverless function APIs with vanilla JavaScript
Deploying serverless functions with Cloudflare Workers
Просмотров 43811 месяцев назад
Deploying serverless functions with Cloudflare Workers

Комментарии

  • @MDABDULMOMINRiyadh
    @MDABDULMOMINRiyadh 5 часов назад

    Love It!

  • @svivian
    @svivian День назад

    Hey, just a little thing but a few times (e.g. 12:15) your coding was covered up by your picture. Might want to scroll a bit in future to keep the code visible :)

    • @gomakethings
      @gomakethings 17 часов назад

      Ah crap, sorry I missed that! I'll do better in the next one!

  • @gianbattistamaricosu1911
    @gianbattistamaricosu1911 День назад

    a tabs system with web components would be very useful

  • @cloudpuncher4615
    @cloudpuncher4615 2 дня назад

    Love your content... I wish I had found it 12years ago... It would have saved me lot of time on my VaJS journey...

  • @TimFegan
    @TimFegan 2 дня назад

    Very interesting. I like how simple you made this look. I was wondering if it would beneficial to make more components as one would tend to do in React. So, even though the Square is basically just a button, it does have state of ' ', 'X' or 'O'. Or on the other hand, from the way you explain Web components before where wrap vanilla HTML in the HTML file with a Web Component, could you take most of the HTML out of the component and place it into the vanilla HTML section.

    • @gomakethings
      @gomakethings 2 дня назад

      The reason I don't do that is because, frankly, I think the "react way" of building most UI is bad. It adds a LOT of extra complexity under the guise of scalability and simplicity.

    • @TimFegan
      @TimFegan 2 дня назад

      @@gomakethings Good point.

  • @davidluhr
    @davidluhr 2 дня назад

    What's your typical threshold for when to use state-based UI? When traditional DOM manipulation is becoming too much? I have a project that might be at this threshold. The project involves an and a UI that modifies content inside the . When the user interacts with the UI, we dispatch a custom event to update the , update it, then dispatch a custom event to update the UI. This was fine for a while but some updates to the UI were getting quite complex. For now, I switched to simply re-rendering the UI and managing keyboard focus for accessibility. It doesn't seem to harm performance at this scale, but it's a potential future issue. With a state-based UI approach, I guess I would maintain a central data object that represents the shared state of both the and the UI? Reef may be a good fit for my needs in this case.

    • @gomakethings
      @gomakethings 2 дня назад

      For me, that threshold is usually when I have multiple pieces of UI all modified by the same piece of data or state. Below that threshold, state-based UI often feels like more work.

    • @davidluhr
      @davidluhr 2 дня назад

      @@gomakethings That's helpful criteria, and is what I'm experiencing with keeping an 's DOM and the representation of that DOM with a UI in sync.

  • @dmh5220
    @dmh5220 2 дня назад

    Great stuff

  • @kanaillaurent526
    @kanaillaurent526 2 дня назад

    Wow glad I inspired u haha. Or maybe not. Let's watch this.... If I understood well, line 118 will act like each time u change the object square it will trigger a rendering.

    • @gomakethings
      @gomakethings 2 дня назад

      That's correct! In most state-based UI libraries, a signal detects changes to its value and automatically causes a render to happen.

  • @rebelmachine88
    @rebelmachine88 3 дня назад

    This is a great showcase of how easy/simple web components are compared to React. I would love to see more direct comparisons like this project!

    • @gomakethings
      @gomakethings 3 дня назад

      Happy to keep creating them. Really appreciate the kind words!

  • @frumbert
    @frumbert 5 дней назад

    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.

    • @gomakethings
      @gomakethings 3 дня назад

      I absolutely love HTML-only stuff like that. And I totally see it. Links, with a few dozen HTML files for the various combinations that could exist.

  • @terryweb
    @terryweb 5 дней назад

    Amazing tricks, except #13... 😀

    • @gomakethings
      @gomakethings 3 дня назад

      I won't hold it against you that you pronounce GIF wrong ❤

  • @IainSimmons
    @IainSimmons 7 дней назад

    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?

    • @gomakethings
      @gomakethings 3 дня назад

      I plan to keep making them. Thanks so much!

  • @kanaillaurent526
    @kanaillaurent526 7 дней назад

    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 7 дней назад

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

    • @chritical_ep
      @chritical_ep 5 дней назад

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

    • @gomakethings
      @gomakethings 3 дня назад

      Oh shit, I totally misspoke. I meant to say "I like to use let for everything." That hilarious, actually! 😂😂😂

  • @dovh49
    @dovh49 8 дней назад

    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 8 дней назад

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

    • @terrencemoore8739
      @terrencemoore8739 7 дней назад

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

    • @gomakethings
      @gomakethings 3 дня назад

      @@terrencemoore8739 Thanks for the kind words, and that's AWESOME to hear!

  • @SuicideDog
    @SuicideDog 9 дней назад

    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 9 дней назад

    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 8 дней назад

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

    • @gomakethings
      @gomakethings 3 дня назад

      I do it all the time. Never run into an issue before.

    • @cloudpuncher4615
      @cloudpuncher4615 3 дня назад

      @@gomakethings My bad, u cant append elements to a CE inside the constructor but you can to the shadowRoot...

    • @gomakethings
      @gomakethings 2 дня назад

      @@cloudpuncher4615 You can do that, too. Here's a demo: gist.github.com/cferdinandi/39774222f289c2d6eee22282350e0eea

    • @cloudpuncher4615
      @cloudpuncher4615 2 дня назад

      @@gomakethings Thanks for the reply.... it appear that you can (in chrome) only if you put the <script> after the Custom Element lest you get this error .."Uncaught DOMException: Failed to construct 'CustomElement': The result must not have children"... .For whatever reason it will append to a shadowRoot or append during the during the Custom Element upgrade. You can just do it with connectedCallback() no issues but it would be nice to just create elements and pass in data in the constructor..

  • @davidluhr
    @davidluhr 9 дней назад

    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.

    • @gomakethings
      @gomakethings 3 дня назад

      Thanks for the kind words, David!

    • @joelhayes9477
      @joelhayes9477 День назад

      My main issue with development is components are supposed to be reusable, but in frameworks, all of my code eventually gets deprecated by the framework. Meanwhile, that one lazy load function I wrote in vanilla JS has lasted 10 years hahha. I'm really glad I found this channel!

  • @k16e
    @k16e 9 дней назад

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

  • @bourge
    @bourge 12 дней назад

    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 9 дней назад

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

    • @bourge
      @bourge 9 дней назад

      @@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.

    • @gomakethings
      @gomakethings 3 дня назад

      @@bourge I wonder if you're seeing flashes of unstyled content, or if the Web Components are being replaced and re-rendered because of hydration.

    • @bourge
      @bourge 3 дня назад

      @@gomakethings it is the rerendering during hydration. I heard that a new spec called declarative shadow dom could help. I wish though that NextJs would better support web components.

  • @Alex-BSD
    @Alex-BSD 13 дней назад

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

  • @FlorianSchommertz
    @FlorianSchommertz 14 дней назад

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

    • @gomakethings
      @gomakethings 9 дней назад

      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 15 дней назад

    I like this, good video thanks

  • @YoungLink51423
    @YoungLink51423 21 день назад

    Starting this series now

  • @ba8e
    @ba8e 22 дня назад

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

    • @gomakethings
      @gomakethings 9 дней назад

      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 24 дня назад

    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 24 дня назад

    "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 24 дня назад

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

    • @gomakethings
      @gomakethings 9 дней назад

      That's a great suggestion, thanks!

  • @evilspymace209
    @evilspymace209 25 дней назад

    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 25 дней назад

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

    • @gomakethings
      @gomakethings 9 дней назад

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

  • @BenHewart
    @BenHewart 25 дней назад

    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 9 дней назад

      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 9 дней назад

      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 9 дней назад

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

    • @BenHewart
      @BenHewart 9 дней назад

      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 9 дней назад

      Happy to show you if your interested no pressure 😉

  • @rustyprogrammer
    @rustyprogrammer 26 дней назад

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

    • @gomakethings
      @gomakethings 25 дней назад

      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 27 дней назад

    The answer is yes

  • @coderlicious6565
    @coderlicious6565 Месяц назад

    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 25 дней назад

      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 Месяц назад

    Very interesting approach!

  • @sonnyl2915
    @sonnyl2915 Месяц назад

    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 Месяц назад

      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 Месяц назад

    great series. Informative and simple

  • @terhuneb
    @terhuneb Месяц назад

    Thank you for mentioning an ES Module implementation too.

  • @dirtdart81
    @dirtdart81 Месяц назад

    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 Месяц назад

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

  • @jonathanoden6854
    @jonathanoden6854 Месяц назад

    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 Месяц назад

      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 Месяц назад

    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 Месяц назад

      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 Месяц назад

      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 Месяц назад

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

  • @netssrmrz
    @netssrmrz Месяц назад

    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.

    • @gomakethings
      @gomakethings Месяц назад

      That's a good suggestion, thanks!

  • @NicklasIsraelsson
    @NicklasIsraelsson Месяц назад

    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 Месяц назад

      GREAT suggestion! Let me add that to the list!

  • @sanderlissenburg1608
    @sanderlissenburg1608 Месяц назад

    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 Месяц назад

      "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 Месяц назад

      Thnx for the reply and extra info!

  • @aniltheblogger
    @aniltheblogger Месяц назад

    what about lit framework?

    • @gomakethings
      @gomakethings Месяц назад

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

  • @netssrmrz
    @netssrmrz Месяц назад

    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 Месяц назад

      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 Месяц назад

      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 Месяц назад

      @@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 Месяц назад

      @@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 Месяц назад

      @@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 Месяц назад

    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 Месяц назад

      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 Месяц назад

    Great stuff, thanks a lot!

    • @gomakethings
      @gomakethings Месяц назад

      Thank you for the kind words!

  • @sueaustin6261
    @sueaustin6261 Месяц назад

    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 Месяц назад

      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 Месяц назад

      @@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 Месяц назад

      @@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.