Custom Events Dispatched from Web Components

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ก.ย. 2024
  • When you build web components, you are generally building a new feature that is intended to be used by other developers and on multiple websites. This means planning the features and building them in a way that won't cause issues on other other websites.
    This tutorial explains how to use CustomEvents, CSS Properties, and private properties inside the component class.
    Code from the video: github.com/pro...
    Custom Web Component Playlist: • Web Components

ความคิดเห็น • 28

  • @Felipekimst
    @Felipekimst 3 หลายเดือนก่อน +3

    Nice, been missing this guy's videos

  • @human_trash_dot_jpeg
    @human_trash_dot_jpeg 2 หลายเดือนก่อน

    I really appreciate your content on web components, and have been building a serious web app using them since early this year.
    I'd personally love to get your thoughts on state management across components, good design patterns like extending a "base" component, etc etc.
    One thing I've been doing is utilizing my own FE cache/state management utility but it can be quite the challenge sometimes haha.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 หลายเดือนก่อน

      That topic is much bigger than any comment. State management can be very challenging and how you approach it depends on how the rest of your system is built.
      I have a video on pub-sub if that helps - th-cam.com/video/aynSM8llOBs/w-d-xo.html

  • @Denis_Victorious
    @Denis_Victorious 3 หลายเดือนก่อน +1

    A hundred subscribers!
    Congratulations, Steve!

    • @Denis_Victorious
      @Denis_Victorious 3 หลายเดือนก่อน

      * one hundred thousand, of course ^_^

  • @antonio_carvalho
    @antonio_carvalho 3 หลายเดือนก่อน

    Excellent video as always! Thank you so much for this content. I hope more people get inspired to create their own components instead of relying on enormous frameworks and libraries for even the simplest projects.

  • @eugeniogonzato
    @eugeniogonzato 3 หลายเดือนก่อน

    Very nice example, you are the best !!!

  • @Vhc706
    @Vhc706 3 หลายเดือนก่อน

    The king is back!

  • @slime_camp
    @slime_camp 3 หลายเดือนก่อน

    Your voice is so nice for this kind of content

  • @user-sr9nh3lc2x
    @user-sr9nh3lc2x 3 หลายเดือนก่อน

    We all have to thank you for your excellent work 🙏

  • @pjosxyz
    @pjosxyz 3 หลายเดือนก่อน

    Best dev channel on youtube

  • @ahmedsabryhussein201
    @ahmedsabryhussein201 3 หลายเดือนก่อน +1

    Hi Steve, can I pass w3. IncludeHTML url to the web component and load it from there? I tried it and no error in the console however the page doesn’t appear. Thank you

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 หลายเดือนก่อน

      Not quite sure what you are asking but, the class that becomes the new HTML element is read and processed as its own module and then exposed to the web page as a valid bit of HTML before you can pass anything to it through attributes.
      In your html head you can load the script for the component as a module or in your main.js file you can import the module.

  • @keshabheda4223
    @keshabheda4223 2 หลายเดือนก่อน

    Hi Steve.
    Thanks for great explanation on web components.
    We have created a web component which will be used by another application.
    There are few events to be passed between the application and component.
    We were looking at Singleton EventBus kind of approach but are not sure how to implement this.
    Can you provide guidance or some sample on how this can be handled ?
    Regards,
    Keshav

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 หลายเดือนก่อน

      Sorry this is the only video that I have made so far about event handling in web components.

  • @user-rm4np9pw2h
    @user-rm4np9pw2h 3 หลายเดือนก่อน

    it's awesome ! some time i really thinking that why we use react if we have web Components in js 😁😉

  • @SnakePliskin30
    @SnakePliskin30 หลายเดือนก่อน

    Hi prof, first thanks for all these lessons which are really helpful for me even though I've been using js for quite some time now.
    So I've followed with the coding and just reused the code for the different videos in your web-component playlist. My question is by the time I switched the script to type='module', the function declarations no longer work and window[this.action] (for the custom event video) is returning undefined. Is there any way to keep that with the type='module' so we only use a single external script file for all the external/custom functions for our web component?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  หลายเดือนก่อน

      When you create functions inside a module, they are never added to the window object. they are accessible via the module object when you import the module.
      import * as mymodule from './module.js';
      or
      const mymodule = import("./module.js");
      both of the above would give you the module as an object and then you can access the name of a function inside the module via the mymodule variable name.
      That works if you don't know the name of the method inside the module.
      If you do know the function name, then call it like any function and the function can return what you want from inside the module / component.

    • @SnakePliskin30
      @SnakePliskin30 หลายเดือนก่อน

      @@SteveGriffith-Prof3ssorSt3v3 understood, thanks for the reply.

  • @netssrmrz
    @netssrmrz 2 หลายเดือนก่อน

    Nice video. Not sure about the shadow DOM though. It's optional so I don't see how it's relevant to the custom event aspect.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 หลายเดือนก่อน

      You CAN build a web component without a shadow DOM, but you lose out on functionality and the valuable encapsulation that really make components useful. If you are not using the shadow DOM then just write standard HTML and CSS.

    • @netssrmrz
      @netssrmrz 2 หลายเดือนก่อน

      @@SteveGriffith-Prof3ssorSt3v3 totally disagree. What functionality do you lose? Slots? Easy to reproduce. And your components become infinitely easier to customise.

  • @tanu6011
    @tanu6011 3 หลายเดือนก่อน

    Web components playlist th-cam.com/play/PLyuRouwmQCjnENQk6NJlckZRXOfQP0x5B.html

  • @paulh6933
    @paulh6933 2 หลายเดือนก่อน

    is there a way to clean up? in your component, you created a listener, can it be destroyed?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 หลายเดือนก่อน

      Absolutely. In one of the other videos in this playlist I talked about using the disconnectedCallback() method in the component class. It is called when the component is removed from the page. You would use a standard removeEventListener call to delete the listener inside of disconnectedCallback().

  • @Nikhil_NnN
    @Nikhil_NnN 3 หลายเดือนก่อน

    I am your New subscriber and new to programming world
    so can you please tell me how to follow your lecture (i mean sequence).
    please help!!!
    🙏🙏

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 หลายเดือนก่อน +1

      There is no specific order for my videos. There are nearly 1000 videos.
      They are grouped into playlists by topic. Some videos appear in multiple playlists.
      Depending on the language or framework that you want to learn or the type of programming that you are doing you will want to use different playlists - www.youtube.com/@SteveGriffith-Prof3ssorSt3v3/playlists
      If you are new to web development then the HTML list is a first step. CSS will help you learn how to style the HTML. Then the two big JS lists - JS from the Start and JS in the Browser.
      JS from the Start is all about JS concepts separate from any specific server or client (browser) features.
      JS in the Browser is all client-side having to do with JS running in the browser.
      I would recommend watching the first 10 or 15 in order but after that, just pick topics that interest you. It will take years to get familiar with and practiced with everything.
      The best way to keep motivated is by picking the topics that interest you at the moment.
      Every tutorial will teach you something. Keep moving forward.

    • @Nikhil_NnN
      @Nikhil_NnN 3 หลายเดือนก่อน

      @@SteveGriffith-Prof3ssorSt3v3 Thank you sir.