<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: weedshaker </title>
    <description>The latest articles on DEV Community by weedshaker  (@weedshaker).</description>
    <link>https://dev.to/weedshaker</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F185287%2Ff485a0bb-7751-45ad-81d2-378c84a02170.jpeg</url>
      <title>DEV Community: weedshaker </title>
      <link>https://dev.to/weedshaker</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/weedshaker"/>
    <language>en</language>
    <item>
      <title>Build an Event Driven TodoMVC App with 8 lightweight VanillaJS Web Components</title>
      <dc:creator>weedshaker </dc:creator>
      <pubDate>Sat, 03 Jul 2021 14:31:31 +0000</pubDate>
      <link>https://dev.to/weedshaker/build-an-event-driven-todomvc-app-with-8-lightweight-vanillajs-web-components-5b65</link>
      <guid>https://dev.to/weedshaker/build-an-event-driven-todomvc-app-with-8-lightweight-vanillajs-web-components-5b65</guid>
      <description>&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;First try out the TodoMVC App to get an idea what it is capable todo: &lt;a href="https://mits-gossau.github.io/todomvc-app/examples/WebComponents/src/" rel="noopener noreferrer"&gt;https://mits-gossau.github.io/todomvc-app/examples/WebComponents/src/&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Note about Browser compatibility: This example uses the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/is" rel="noopener noreferrer"&gt;attribute "is"&lt;/a&gt;, which is not yet supported by IOS. It is possible to simply avoid this problem by wrapping elements with web components. As can be seen at our &lt;a href="https://github.com/mits-gossau/event-driven-web-components-realworld-example-app" rel="noopener noreferrer"&gt;Real World Example&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  HTML Overview
&lt;/h2&gt;

&lt;p&gt;Starting at the todomvc-app-template and looking at it's HTML: &lt;a href="https://github.com/tastejs/todomvc-app-template/blob/master/index.html" rel="noopener noreferrer"&gt;https://github.com/tastejs/todomvc-app-template/blob/master/index.html&lt;/a&gt; respectively at the extended HTML with &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/is" rel="noopener noreferrer"&gt;#attr-is&lt;/a&gt; tags: &lt;a href="https://github.com/mits-gossau/todomvc-app/blob/master/examples/WebComponents/src/index.html" rel="noopener noreferrer"&gt;https://github.com/mits-gossau/todomvc-app/blob/master/examples/WebComponents/src/index.html&lt;/a&gt; gives us some idea of which elements are going to have logic: &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F92fav1lgaquxk0vzeyqr.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F92fav1lgaquxk0vzeyqr.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;the "input.new-todo" field is at the top of the application and emits the event new-todo with a value for creation of a new todo item.&lt;/li&gt;
&lt;li&gt;the "section.main" holds the "input.toggle-all" and the "ul.todo-list" and must be hidden, if there are zero items. It listens to the event all-items to toggle between hidden and shown.&lt;/li&gt;
&lt;li&gt;the "input.toggle-all" is the arrow facing down on the left hand side of the "input.new-todo". It emits the event toggle-all to toggle all items to checked or unchecked (completed or incomplete). It also listens to the event all-items to toggle itself checked or unchecked.&lt;/li&gt;
&lt;li&gt;the "ul.todo-list" holds all todo items. It listens to item emitted events regarding: edit, toggle, destroy. It also listens to the events: new-todo (where it loads TodoItem.js and appends it as child), toggle-all, clear-completed. It emits the event all-items once things change and takes care of saving to the localStorage.&lt;/li&gt;
&lt;li&gt;the "footer.footer" inherits the same web component as at entry 2. "section.main" does. It must be hidden, if there are zero items. It listens to the event all-items to toggle between hidden and shown.&lt;/li&gt;
&lt;li&gt;the "span.todo-count" listens to the event all-items and counts accordingly.&lt;/li&gt;
&lt;li&gt;the "ul.filters" listens to the global hashchange event and toggles it's selected class accordingly.&lt;/li&gt;
&lt;li&gt;the "button.clear-completed" emits the event clear-completed and listens for the event all-items to toggle if it is hidden or shown.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The list above already holds a rough description of 7 out of 8 web components &lt;em&gt;(element 2. and 5. share the same web component)&lt;/em&gt;. The 8th web component is the TodoItem.js. This one gets created by the "ul.todo-list" and listens to the events toggle-all and the global hashchange. It emits toggle, destroy and edit (edit is a reuse of the new-todo web component and bubbles through the todo item web component).&lt;/p&gt;
&lt;h2&gt;
  
  
  Loading the Web Components
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft7h7409gjv2uaqma6mme.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft7h7409gjv2uaqma6mme.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Loading web components is fairly straight forward.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./es/components/TodoList.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;todo-list&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;extends&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ul&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Import a JavaScript file. Then you receive the module object on which you find the class as module.default, as long as you also export it as default.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TodoList&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;HTMLUListElement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Give it a node tagName and for the usecase of &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/is" rel="noopener noreferrer"&gt;#attr-is&lt;/a&gt; add the option telling the DOM which exact HTMLElement it shall extend. This option must correspond with the class extends HTMLElement. All the imports can be wrapped into a Promise.all and then we throw it at &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define" rel="noopener noreferrer"&gt;customElements.define&lt;/a&gt;. Now our seven nodes are hooked with the web component classes. The &lt;a href="https://github.com/mits-gossau/todomvc-app/tree/master/examples/WebComponents/src/es/components/TodoItem.js" rel="noopener noreferrer"&gt;TodoItem.js&lt;/a&gt; is going to be loaded by the &lt;a href="https://github.com/mits-gossau/todomvc-app/tree/master/examples/WebComponents/src/es/components/TodoList.js" rel="noopener noreferrer"&gt;TodoList.js&lt;/a&gt; as soon as it is required, eg. there is an actual entry/item.&lt;/p&gt;

&lt;h2&gt;
  
  
  Event Driven
&lt;/h2&gt;

&lt;p&gt;An event driven architecture means that these web components are only communicating through events. The only two exceptions are found at &lt;a href="https://github.com/mits-gossau/todomvc-app/tree/master/examples/WebComponents/src/es/components/TodoList.js#L24" rel="noopener noreferrer"&gt;TodoList.js&lt;/a&gt;, when it loads the &lt;a href="https://github.com/mits-gossau/todomvc-app/tree/master/examples/WebComponents/src/es/components/TodoItem.js" rel="noopener noreferrer"&gt;TodoItem.js&lt;/a&gt; and passes the value to the constructor:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TodoItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;detail&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;as well as at the &lt;a href="https://github.com/mits-gossau/todomvc-app/tree/master/examples/WebComponents/src/es/components/TodoItem.js#L106" rel="noopener noreferrer"&gt;TodoItem.js&lt;/a&gt; itself, when it loads &lt;a href="https://github.com/mits-gossau/todomvc-app/tree/master/examples/WebComponents/src/es/components/NewTodo.js" rel="noopener noreferrer"&gt;NewTodo.js&lt;/a&gt; for it's editing input field. Then it passes a few attributes to the web component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"edit"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"${this.value}"&lt;/span&gt; &lt;span class="na"&gt;is=&lt;/span&gt;&lt;span class="s"&gt;"new-todo"&lt;/span&gt; &lt;span class="na"&gt;new-todo=&lt;/span&gt;&lt;span class="s"&gt;"edit"&lt;/span&gt; &lt;span class="na"&gt;allow-empty&lt;/span&gt; &lt;span class="na"&gt;allow-escape&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The beauty about events is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the components are independent&lt;/li&gt;
&lt;li&gt;nice overview on what they listen can be found at the connectedCallback&lt;/li&gt;
&lt;li&gt;FireFox DevTools let you inspect the event listeners&lt;/li&gt;
&lt;li&gt;reusable web components&lt;/li&gt;
&lt;li&gt;scaling to large size architecture&lt;/li&gt;
&lt;li&gt;using same architecture as the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model" rel="noopener noreferrer"&gt;DOM&lt;/a&gt; itself&lt;/li&gt;
&lt;li&gt;no dependencies/frameworks required =&amp;gt; pure standard&lt;/li&gt;
&lt;li&gt;simple to use&lt;/li&gt;
&lt;li&gt;state management is obsolete&lt;/li&gt;
&lt;li&gt;super fast and greatly lightweight: &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fphpw1vo6z3e0aqvpmqsn.PNG" alt="Alt Text"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Overview of each Web Component
&lt;/h2&gt;

&lt;h4&gt;
  
  
  1. the "input.new-todo" gets &lt;a href="https://github.com/mits-gossau/todomvc-app/tree/master/examples/WebComponents/src/es/components/NewTodo.js" rel="noopener noreferrer"&gt;NewTodo.js&lt;/a&gt; applied to it.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;connectedCallback &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blur&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;valueListener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;keyup&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;valueListener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All the logic this component holds is inside the valueListener, which basically has a few flags, some decide upon the received attributes, when to dispatch the event 'new-todo'. The 'new-todo' event can also be renamed by passing an attribute called "new-todo" and is used as such at the &lt;a href="https://github.com/mits-gossau/todomvc-app/tree/master/examples/WebComponents/src/es/components/TodoItem.js#L106" rel="noopener noreferrer"&gt;TodoItem.js&lt;/a&gt;, which makes it dispatch the event 'edit' instead of 'new-todo'.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. the "section.main" gets &lt;a href="https://github.com/mits-gossau/todomvc-app/tree/master/examples/WebComponents/src/es/components/NoItemsHidden.js" rel="noopener noreferrer"&gt;NoItemsHidden.js&lt;/a&gt; applied to it.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;connectedCallback &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;all-items&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;allItemsListener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The allItemsListener holds the logic for this web component. It sets hide=true when the allItemsListener event.detail.items.length is falsy.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. the "input.toggle-all" gets &lt;a href="https://github.com/mits-gossau/todomvc-app/tree/master/examples/WebComponents/src/es/components/ToggleAll.js" rel="noopener noreferrer"&gt;ToggleAll.js&lt;/a&gt; applied to it.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;connectedCallback &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;clickListener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;all-items&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;allItemsListener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The clickListener listens to the input checkbox being clicked and emits the event 'toggle-all' with the boolean checked as event.detail. It also listens with the allItemsListener to the 'all-items' event. There it decides, if it is still checked or not.&lt;/p&gt;

&lt;h4&gt;
  
  
  4. the "ul.todo-list" gets &lt;a href="https://github.com/mits-gossau/todomvc-app/tree/master/examples/WebComponents/src/es/components/TodoList.js" rel="noopener noreferrer"&gt;TodoList.js&lt;/a&gt; applied to it.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;connectedCallback &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;edit&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;updateListener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;toggle&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;updateListener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;destroy&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;updateListener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;new-todo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;newTodoListener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;toggle-all&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toggleAllListener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;clear-completed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;clearCompletedListener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loadAllItems&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dispatchAllItems&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It listens to the events 'edit', 'toggle', 'destroy' emitted by it's &lt;a href="https://github.com/mits-gossau/todomvc-app/tree/master/examples/WebComponents/src/es/components/TodoList.js#L60" rel="noopener noreferrer"&gt;child&lt;/a&gt; component &lt;a href="https://github.com/mits-gossau/todomvc-app/tree/master/examples/WebComponents/src/es/components/TodoItem.js" rel="noopener noreferrer"&gt;TodoItem.js&lt;/a&gt;, which indicates that something on the items list changed and shall be propagated through dispatching the event 'all-items'. The same plus a little extra logic is executed at 'toggle-all' and 'clear-completed'. It also creates new &lt;a href="https://github.com/mits-gossau/todomvc-app/tree/master/examples/WebComponents/src/es/components/TodoItem.js" rel="noopener noreferrer"&gt;TodoItem.js&lt;/a&gt; on the event 'new-todo'. At the updateListener it also saves the changes to the localStorage, which gets loaded on connectedCallback.loadAllItems.&lt;/p&gt;

&lt;h4&gt;
  
  
  5. the "span.todo-count" gets &lt;a href="https://github.com/mits-gossau/todomvc-app/tree/master/examples/WebComponents/src/es/components/TodoCount.js" rel="noopener noreferrer"&gt;TodoCount.js&lt;/a&gt; applied to it.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;connectedCallback &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;all-items&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;allItemsListener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It listens to the event 'all-items' and does update it's innerHTML accordingly to the latest count.&lt;/p&gt;

&lt;h4&gt;
  
  
  6. the "ul.filters" gets &lt;a href="https://github.com/mits-gossau/todomvc-app/tree/master/examples/WebComponents/src/es/components/TodoFilters.js" rel="noopener noreferrer"&gt;TodoFilters.js&lt;/a&gt; applied to it.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;connectedCallback &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hashchange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hashchangeListener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hashchangeListener&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It listens to the global 'hashchange' event and updates it's selected CSS according to the global route.&lt;/p&gt;

&lt;h4&gt;
  
  
  7. the "button.clear-completed" gets &lt;a href="https://github.com/mits-gossau/todomvc-app/tree/master/examples/WebComponents/src/es/components/ClearCompleted.js" rel="noopener noreferrer"&gt;ClearCompleted.js&lt;/a&gt; applied to it.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;connectedCallback &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;clickListener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;all-items&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;allItemsListener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The clickListener listens to the button being clicked and emits the event 'clear-completed'. It also listens with the allItemsListener to the 'all-items' event. There it decides, if it is hidden or shown.&lt;/p&gt;

&lt;h4&gt;
  
  
  8. the &lt;a href="https://github.com/mits-gossau/todomvc-app/tree/master/examples/WebComponents/src/es/components/TodoItem.js" rel="noopener noreferrer"&gt;TodoItem.js&lt;/a&gt; gets loaded by &lt;a href="https://github.com/mits-gossau/todomvc-app/tree/master/examples/WebComponents/src/es/components/TodoList.js" rel="noopener noreferrer"&gt;TodoList.js&lt;/a&gt; when loadAllItems loads from localStorage or at the event 'new-todo'.
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;connectedCallback &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shouldComponentRender&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hashchangeListener&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;inputListener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;clickListener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dblclick&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dblclickListener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;edit&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;editListener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;toggle-all&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toggleAllListener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hashchange&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hashchangeListener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The event 'input' applies to the checkbox and dispatches the event 'toggle' checked. The event 'click' applies to the delete button and dispatches the event 'destroy'. The event 'dblclick' sets the class editing. The event 'edit' is dispatched and bubbles further up by it's &lt;a href="https://github.com/mits-gossau/todomvc-app/tree/master/examples/WebComponents/src/es/components/TodoItem.js#L117" rel="noopener noreferrer"&gt;child&lt;/a&gt; input field &lt;a href="https://github.com/mits-gossau/todomvc-app/tree/master/examples/WebComponents/src/es/components/NewTodo.js" rel="noopener noreferrer"&gt;NewTodo.js&lt;/a&gt;. The editListener then applies the new value. The event 'toggle-all' sets itself checked or unchecked. The global event 'hashchange' decides if this todo item shall be hidden or shown. The hashchangeListener is also triggered at the connectedCallback as well as at the inputListener, when it's own checked status changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  ShadowDOM and encapsulated CSS
&lt;/h2&gt;

&lt;p&gt;You must have encountered the term &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM" rel="noopener noreferrer"&gt;ShadowDOM&lt;/a&gt; and it's fabulous feature to encapsulate CSS. The TodoMVC App Template already delivers a global CSS. In this spirit, it made no sense to break out CSS and encapsulate it into the web components. But I have some examples where we use this feature:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/mits-gossau/web-components" rel="noopener noreferrer"&gt;https://github.com/mits-gossau/web-components&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/mits-gossau/web-components-cms-template" rel="noopener noreferrer"&gt;https://github.com/mits-gossau/web-components-cms-template&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is certainly what sets it apart of all other approaches and is worth a separate article how to newly deal with CSS in this new environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I hope this gave an overview about the &lt;a href="https://github.com/mits-gossau/event-driven-web-components-todomvc-app" rel="noopener noreferrer"&gt;https://github.com/mits-gossau/event-driven-web-components-todomvc-app&lt;/a&gt; and how you could build it. I believe that an event driven architecture is the future of all frontend stacks/applications as well as it is often already applied under the hood of some framework logic, which could be redundant, if you learn how to immerse into the DOM.&lt;/p&gt;

&lt;h2&gt;
  
  
  Related Video Tutorials
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://weedshaker.github.io/event-driven-web-components-tutorial/src/#/one" rel="noopener noreferrer"&gt;https://weedshaker.github.io/event-driven-web-components-tutorial/src/#/one&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>eventdriven</category>
      <category>webcomponents</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Web Components and now what?</title>
      <dc:creator>weedshaker </dc:creator>
      <pubDate>Mon, 14 Jun 2021 11:25:57 +0000</pubDate>
      <link>https://dev.to/weedshaker/web-components-and-now-what-k97</link>
      <guid>https://dev.to/weedshaker/web-components-and-now-what-k97</guid>
      <description>&lt;p&gt;Finally, you jumped on the bandwagon of web components! Congrats! 😆&lt;/p&gt;

&lt;p&gt;Web Components are going to solve ALL your troubles with CSS, Frameworks and Life... not really... right? 😏 What about stores? Immutable data? 😨 And all the other buzzwords? Just forget about them! 😵 VanillaJS Web Components is all you need, since the architecture to make them work for complex applications is already there. It is called the DOM and it is Event Driven. 😄&lt;/p&gt;

&lt;p&gt;An Event Driven Architecture makes stuff like stores obsolete. Your components react on events and if they need something, they emit their event to ask for it. Sure, at this level you are free to decide, if you want to cache certain events, fetches, etc. or if you just want to fire and forget. We chose to simply cancel ongoing fetches at some endpoints (&lt;a href="https://github.com/mits-gossau/event-driven-web-components-realworld-example-app/blob/master/src/es/components/controllers/Article.js#L81" rel="noopener noreferrer"&gt;https://github.com/mits-gossau/event-driven-web-components-realworld-example-app/blob/master/src/es/components/controllers/Article.js#L81&lt;/a&gt;) but not all those approaches require any difficult logic anymore. Why should you even try to bloat your frontend with a bunch of business logic, if you have an endpoint with that logic already implemented? Keep it simple! 🤯&lt;/p&gt;

&lt;p&gt;Even more important is to keep the process of using Web Components simple. They already bring everything you need with them and if something is missing you can extend your Web Component with some convenient setters and getters, a mutation observer and even an intersection observer: &lt;a href="https://github.com/mits-gossau/web-components-cms-template/tree/master/src/es/components/prototypes" rel="noopener noreferrer"&gt;https://github.com/mits-gossau/web-components-cms-template/tree/master/src/es/components/prototypes&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The death of IE11 made any transpiler redundant. 🥳 BUUUUUT what about TypeScript? Yes, also the TypeScript transpiler just puts additional complexity to your project, which you can spare yourself the trouble with: &lt;a href="https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html" rel="noopener noreferrer"&gt;https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html&lt;/a&gt; JSDoc Types nearly do everything you can wish for but do not enforce additional dependencies on you, if you already work with VSCode, it works out of the box. And yes, I love type highlighting!&lt;/p&gt;

&lt;p&gt;The next of your concerns may is the loading of the Web Components. For an SPA it is simple, just load them when required: &lt;a href="https://github.com/mits-gossau/event-driven-web-components-realworld-example-app/blob/master/src/index.html" rel="noopener noreferrer"&gt;https://github.com/mits-gossau/event-driven-web-components-realworld-example-app/blob/master/src/index.html&lt;/a&gt; In case of server side rendering, you could ether have the backend template engine decide what to render when, although my backend colleagues are not very keen dealing with JavaScript, so I wrote a simple loader script for them: &lt;a href="https://github.com/mits-gossau/web-components-cms-template/blob/master/wc-config.js" rel="noopener noreferrer"&gt;https://github.com/mits-gossau/web-components-cms-template/blob/master/wc-config.js&lt;/a&gt; the only disadvantage is, that you likely loose couple milliseconds for the request to the wc-config.js 🚽 plus some more milliseconds to load the required Web Components. In case you need a Lighthouse score of 100 you better just render those Web Component Classes straight into your html file but I think the convenience is worth the price of losing a few milliseconds. This is anyway, what you at least save by not loading and interpreting a framework. 😄&lt;/p&gt;

&lt;p&gt;Conclusion, it is worth to look into the nature of the DOM, an Event Driven Architecture, once you feel ready to start working with Web Components. This will make a lot of classical complexity nonessential and keeps your application easy, simple, scalable and reusable.&lt;/p&gt;

&lt;p&gt;The Real World Example of an Event Driven Architecture: &lt;a href="https://github.com/mits-gossau/event-driven-web-components-realworld-example-app" rel="noopener noreferrer"&gt;https://github.com/mits-gossau/event-driven-web-components-realworld-example-app&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fteukmqhlym3bqx52e5qc.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fteukmqhlym3bqx52e5qc.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The TodoMVC Example of an Event Driven Architecture: &lt;a href="https://github.com/mits-gossau/event-driven-web-components-todomvc-app" rel="noopener noreferrer"&gt;https://github.com/mits-gossau/event-driven-web-components-todomvc-app&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fau3ipkxcecg5h441mepf.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fau3ipkxcecg5h441mepf.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Related Video Tutorials
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://weedshaker.github.io/event-driven-web-components-tutorial/src/#/one" rel="noopener noreferrer"&gt;https://weedshaker.github.io/event-driven-web-components-tutorial/src/#/one&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webcomponents</category>
      <category>showdev</category>
      <category>webdev</category>
    </item>
    <item>
      <title>DOM and the event driven architecture - Introduction </title>
      <dc:creator>weedshaker </dc:creator>
      <pubDate>Thu, 09 Jul 2020 13:16:41 +0000</pubDate>
      <link>https://dev.to/weedshaker/dom-and-the-event-driven-architecture-1519</link>
      <guid>https://dev.to/weedshaker/dom-and-the-event-driven-architecture-1519</guid>
      <description>&lt;p&gt;At times of IE6 we were exited to have a primitive console. 📺  Later came firebug bug 🔥🐜 and libraries like JQuery, which made it possible to easily navigate different web api implementations by browser vendors. While those issues started to be harmonized out of our ways (thank you W3C) compilers solved modularity and frameworks like react or angular solved state management/single page app and DOM concerns. And while all this was happening Macro Medias Flash with it’s powerful Action Script was mercilessly assassinated. 🔫😢&lt;/p&gt;

&lt;p&gt;Today, our web api’s reach a depth, which Action Script delivered in 2005 🥳 . At the same time our laziness and division about frontend technology has not only created a uniform, uncreative appearance by bootstrap and material UI. But opened the JavaScript, HTML and CSS stack for discussion by wasm (rust, .net, C++) solutions.&lt;/p&gt;

&lt;p&gt;In general I see wasm as an enrichment of JavaScript but others see it as the end of such. This prediction is going to full fill, the more divided  the frontend dev camps become. React vs. VueJs vs. Ember vs. Angular vs. etc etc. The only huge savior of JavaScript is by adopting the won learnings out of such frameworks and start using W3C web components with VanillaJS. #useWebApi !!! 🔨😎🤙 and wake up to the fact that the W3C standard, tc39 (ES6) solved most past and future concerns. Since IE11 died ⚰️, we can use the fancy 🦄  stuff anywhere without polyfills nor webpack, nor framework only one thing to learn: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API"&gt;https://developer.mozilla.org/en-US/docs/Web/API&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, things are becoming simple again. 🤪 But then you will ask me how to solve your applications state management? My answer is “When in Rome, do as the Romans do”. Your application is in the DOM so do as the Domans do! How does the DOM do? The DOM is event driven and CustomEvents is a standard &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent"&gt;https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent&lt;/a&gt;, by which your web components &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Web_Components"&gt;https://developer.mozilla.org/en-US/docs/Web/Web_Components&lt;/a&gt; will be communicating. ShadowDOM, event driven web components, asynchronicity and http2 are so much optimized that your site feels as fast as a static site and at the same time let’s you make it static, if desired and hydratable by the nature of web components. 🌊&lt;/p&gt;

&lt;p&gt;Your time to interactivity is going to be lower than ever before. No more threat blocking code! 🆘🔨&lt;/p&gt;

&lt;p&gt;Web components are a perfect match for complex single page apps with reusable components, micro frontends on static pages and at the same time flexible enough for any other use case running in or on the DOM.&lt;/p&gt;

&lt;p&gt;To visualize the statements above in code, I started the real world conduit example, which is similar to the TodoMVC (&lt;a href="https://github.com/mits-gossau/event-driven-web-components-todomvc-app"&gt;https://github.com/mits-gossau/event-driven-web-components-todomvc-app&lt;/a&gt;) but more specific for a web application scenario: &lt;a href="https://github.com/Weedshaker/event-driven-web-components-realworld-example-app"&gt;https://github.com/Weedshaker/event-driven-web-components-realworld-example-app&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I would be very happy, if some of you guys would join the development process!? 🥰&lt;/p&gt;

&lt;p&gt;Thanks for reading! 🙏&lt;/p&gt;

&lt;h2&gt;
  
  
  Related Video Tutorials
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://weedshaker.github.io/event-driven-web-components-tutorial/src/#/one"&gt;https://weedshaker.github.io/event-driven-web-components-tutorial/src/#/one&lt;/a&gt;&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
