{"id":997,"date":"2019-12-04T08:00:00","date_gmt":"2019-12-04T07:00:00","guid":{"rendered":"http:\/\/cmagazine.test\/thinking-in-web-component\/"},"modified":"2021-12-23T15:30:51","modified_gmt":"2021-12-23T14:30:51","slug":"thinking-in-web-component","status":"publish","type":"post","link":"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/","title":{"rendered":"Thinking in Web Component"},"content":{"rendered":"<p>The development of <span id=\"urn:enhancement-2cdbc8be\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/web_application\">Web Application<\/span> has led us to rewrite some pieces of <span id=\"urn:enhancement-deddede8\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/user_computing\">User<\/span> <span id=\"urn:enhancement-ef66082f\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/interface_computing\">Interface<\/span> so many times in\u00a0 different varieties of <span id=\"urn:enhancement-d1192c03\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/javascript_library\">JavaScript frameworks<\/span> for compatibility and <span id=\"urn:enhancement-2dd2ac33\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/interoperability\">interoperability<\/span>.<\/p>\n<p>When we build our <span id=\"urn:enhancement-2b400a1c\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/user_computing\">User<\/span> <span id=\"urn:enhancement-1b9a2c4b\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/interface_computing\">Interface<\/span>, we have to think about performance, accessibility, compatibility, reusability, extensibility and maintainability. In my personal opinion, many of these aspects are the same challenges we have in any other \u201cclassical\u201d <span id=\"urn:enhancement-b88ba2a\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/application_software\">application<\/span>. <strong><span id=\"urn:enhancement-fb49ec5d\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/object-oriented_programming\">Object Oriented Programming<\/span><\/strong> is a paradigm mostly used to build enterprise <span id=\"urn:enhancement-363a5ea0\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/application_software\">applications<\/span>, it uses concepts such as <span id=\"urn:enhancement-e8de107\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/encapsulation_object-oriented_programming\">encapsulation<\/span>, inheritance, <span id=\"urn:enhancement-5ef076d5\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/interoperability\">interoperability<\/span> to gain robust, reusable portions of code called <span id=\"urn:enhancement-14b6fd55\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/class_computer_programming\">Classes<\/span>. Then we have <strong>SOLID Principles<\/strong> such as Inversion of Control, Single Responsibility and finally, the best one, the simplest principle in programming: <strong>DRY<\/strong> (<strong>D<\/strong>on\u2019t <strong>R<\/strong>epeat <strong>Y<\/strong>ourself).<\/p>\n<p>In the <span id=\"urn:enhancement-c89a2ef2\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/web_development\">Web Development<\/span> world, to achieve these important goals, we need to introduce a new idea, called \u201c<strong><span id=\"urn:enhancement-5da334bb\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/component-based_software_engineering\">Component<\/span><\/strong>\u201d. It\u2019s not a new concept and it has been around for a long time. I can think about <span id=\"urn:enhancement-85c91e6e\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/component-based_software_engineering\">Component<\/span> like a <span id=\"urn:enhancement-1bc2f817\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/class_computer_programming\">Class<\/span> in <span id=\"urn:enhancement-ee4463c4\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/object-oriented_programming\">OOP<\/span>.<\/p>\n<p>One of the first frameworks that introduced the concept of <span id=\"urn:enhancement-20a811d9\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/component-based_software_engineering\">components<\/span> was <strong><span id=\"urn:enhancement-57f55387\" class=\"textannotation disambiguated wl-creative-work\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/angularjs\">AngularJS<\/span><\/strong> (do not confuse with Angular, they are very different).<\/p>\n<p>Today we have a lot of frameworks and libraries, like <strong>Angular<\/strong>, <strong>React<\/strong> or <strong>VueJS<\/strong>, which are trying to solve the problem of \u201c<strong>Thinking in <span id=\"urn:enhancement-4edb2b6b\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/web_components\">Web Components<\/span><\/strong>\u201d; they continue to use the idea of <span id=\"urn:enhancement-548921b4\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/component-based_software_engineering\">Component<\/span>, but they abstract from the <span id=\"urn:enhancement-f9d3b7f4\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">DOM<\/span> (<span id=\"urn:enhancement-d1b0ad3f\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">Document Object Model<\/span>). They give us the power to define our custom <span id=\"urn:enhancement-dfd152eb\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/html_element\">HTML tag<\/span> in order to enrich the \u201cgrammar\u201d of the HTML language. We are able to define our custom behaviour, with some JavaScript code, attached to these new elements.<\/p>\n<p>One of the most powerful features of Angular is to be able to define a new syntax <span id=\"urn:enhancement-c57147da\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/constructor_object-oriented_programming\">constructor<\/span> by using the decorator <code>@Component<\/code>. It allows developers to decorate a <span id=\"urn:enhancement-cc739344\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/class_computer_programming\">class<\/span> with some metadata in order to define the custom tag <span id=\"urn:enhancement-e3f15c36\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/html\">HTML<\/span> with template (View) and a <span id=\"urn:enhancement-bb4f3be8\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/class_computer_programming\">class<\/span>, which defines the behaviour of the <span id=\"urn:enhancement-dee62e32\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/component-based_software_engineering\">component<\/span> itself. In addition, we can take advantage of the <strong>Shadow <span id=\"urn:enhancement-4108a491\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">DOM<\/span><\/strong> to provide complete <span id=\"urn:enhancement-e0c9157a\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/encapsulation_object-oriented_programming\">encapsulation<\/span> for our <span id=\"urn:enhancement-7e1e3af1\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/component-based_software_engineering\">components<\/span>.<\/p>\n<p><i>All elements and styles that belong to an HTML <span id=\"urn:enhancement-a3e115a4\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document\">document<\/span> are defined in one global scope. A Shadow <span id=\"urn:enhancement-7006b43a\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">DOM<\/span> is a \u201c<span id=\"urn:enhancement-a41cec0\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">DOM<\/span> within a <span id=\"urn:enhancement-1d80479a\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">DOM<\/span>\u201d, where we can build an isolated <span id=\"urn:enhancement-8749300\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">DOM<\/span> tree with our own elements and styles.<\/i><\/p>\n<p>These frameworks have their own definition and implementation of what a <span id=\"urn:enhancement-ba083d0c\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/component-based_software_engineering\">component<\/span> is, but they lack a common <span id=\"urn:enhancement-18ecf037\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/application_programming_interface\">API<\/span>. They share only the idea about what a <span id=\"urn:enhancement-a4c99b4b\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/component-based_software_engineering\">component<\/span> should be, but you cannot share a <span id=\"urn:enhancement-e8de9fd0\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/component-based_software_engineering\">component<\/span> with different technology stacks or, at least, it is not a quick <span id=\"urn:enhancement-794a130e\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/job\">job<\/span>. They also implement a custom <span id=\"urn:enhancement-15536162\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">DOM<\/span> like <strong>Virtual <span id=\"urn:enhancement-bbb28095\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">DOM<\/span><\/strong> in React and VueJS or \u201cEmulated Native Scoping\u201d in Angular to emulate Shadow <span id=\"urn:enhancement-873a2245\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">DOM<\/span>.<\/p>\n<p>In \u201c<b>Get hyper-excited for <span id=\"urn:enhancement-e37b9ac5\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/web_standards\">web standard<\/span><\/b>\u201d, Jiayi Hu\u2019s talk at <strong>Codemotion Rome 2019<\/strong>, we saw what a <span id=\"urn:enhancement-c765bc9c\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/web_web_browser\">Web<\/span> <span id=\"urn:enhancement-d85a156\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/component-based_software_engineering\">Component<\/span> is in a \u201cnative\u201d way using standard <span id=\"urn:enhancement-488d1f1d\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/application_programming_interface\">API<\/span>, that tries to resolve this fragmentation caused by the presence of a <span id=\"urn:enhancement-75af6c89\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/standardization\">non-standard<\/span> way of building <span id=\"urn:enhancement-a0d3b882\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/reusability\">reusable<\/span> piece of code.<\/p>\n<p><b><span id=\"urn:enhancement-9b9b4207\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/web_web_browser\">Web<\/span> <span id=\"urn:enhancement-3ef02969\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/component-based_software_engineering\">Component<\/span><\/b> is a set of different <span id=\"urn:enhancement-ddb33c68\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/application_programming_interface\">APIs<\/span> that allow us to create highly <span id=\"urn:enhancement-7417415c\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/reusability\">reusable<\/span> <span id=\"urn:enhancement-cea17384\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/user_interface\">UI<\/span> <span id=\"urn:enhancement-df08f97c\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/component-based_software_engineering\">components<\/span> that will work across modern browsers and they can be used with third party frameworks and libraries. They allow us to define <span id=\"urn:enhancement-81ec1e68\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/reusability\">reusable<\/span> custom elements via standard specifications, such as Custom Element and Shadow <span id=\"urn:enhancement-7610a781\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">DOM<\/span>.<\/p>\n<h2>Custom Elements<\/h2>\n<p>The Custom Elements <span id=\"urn:enhancement-70c45510\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/application_programming_interface\">API<\/span> provides a way for <span id=\"urn:enhancement-a9bf180\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/programmer\">programmers<\/span> to <strong>define our own custom <span id=\"urn:enhancement-5e544184\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/html_element\">HTML tags<\/span><\/strong>, with fully-featured <span id=\"urn:enhancement-3e6fef79\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">DOM<\/span> elements with attached behaviour on them. With Custom Elements <span id=\"urn:enhancement-f8c0452a\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/application_programming_interface\">API<\/span>, we can instruct the <span id=\"urn:enhancement-f0df20ba\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/web_browser\">browser<\/span> parser to properly construct an element and how elements should react to the <span id=\"urn:enhancement-d348aa15\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/user_computing\">user<\/span> events.<\/p>\n<p>To define our custom element, we can use some of the newer <strong><span id=\"urn:enhancement-33447e69\" class=\"textannotation disambiguated wl-creative-work\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/ecmascript\">ES6<\/span> <span id=\"urn:enhancement-c269c6a2\" class=\"textannotation disambiguated wl-creative-work\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/javascript\">JavaScript<\/span><\/strong> features such as <strong><span id=\"urn:enhancement-d09260fc\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/class_computer_programming\">Classes<\/span><\/strong>. We need to extend <b>HTMLElement<\/b> base <span id=\"urn:enhancement-be457c48\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/class_computer_programming\">class<\/span> and call the <code>super()<\/code> <span id=\"urn:enhancement-e459db81\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/method_computer_programming\">method<\/span> inside the <b><span id=\"urn:enhancement-a2111f14\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/constructor_object-oriented_programming\">constructor<\/span><\/b>. Then we can have one <span id=\"urn:enhancement-2e22b059\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/method_computer_programming\">method<\/span> of the lifecycle of a <span id=\"urn:enhancement-ef3467ec\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/component-based_software_engineering\">component<\/span>: <code><b>connectedCallback<\/b><\/code>, but it is not mandatory to have one. This is a particular <span id=\"urn:enhancement-6e4144df\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/method_computer_programming\">method<\/span> that it is invoked when our <span id=\"urn:enhancement-5feba652\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/component-based_software_engineering\">component<\/span> is created and added to the <span id=\"urn:enhancement-7ed9da0\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">DOM<\/span>. Inside this <span id=\"urn:enhancement-1ca79d8c\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/method_computer_programming\">method<\/span> we will do initialisation logic, data fetching or something else that can occur in the beginning.<\/p>\n<p>In the <code>connectedCallback()<\/code> <span id=\"urn:enhancement-d07db46\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/method_computer_programming\">method<\/span> we can set the <code>textContent<\/code> of our element within a timer function like <code>setInterval()<\/code>, but we can have complete access to the <span id=\"urn:enhancement-b4109b69\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">DOM<\/span> tree, such as <code>querySelector<\/code> and other <span id=\"urn:enhancement-28af981e\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/method_computer_programming\">methods<\/span> to get access to the <span id=\"urn:enhancement-b87940e\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">DOM<\/span>. Because of the use of a Timer, we need to write the logic to release it inside the <code><b>disconnectedCallback()<\/b><\/code>, another life-cycle <span id=\"urn:enhancement-43c09409\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/method_computer_programming\">method<\/span> of the Custom Element <span id=\"urn:enhancement-d39c5a32\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/application_programming_interface\">API<\/span>, called when the element is detached from the <span id=\"urn:enhancement-d2ad5e33\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">DOM<\/span> tree.<\/p>\n<p>Finally, we need to register our <span id=\"urn:enhancement-213cb506\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/component-based_software_engineering\">component<\/span> to the <span id=\"urn:enhancement-273013cf\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">DOM<\/span> with the <code><b>define()<\/b><\/code>. We need to make sure we define the name of our custom element with at least one dash in the name, in order to prevent collision with native elements that have no dashes in the name. Here is an example:<\/p>\n<p><script src=\"https:\/\/pastebin.com\/embed_js\/CK2dWNSW\"><\/script><\/p>\n<p>Jiayi continues his talk showing us an implementation of a custom element with <a href=\"https:\/\/www.codemotion.com\/magazine\/dev-hub\/web-developer\/react-project-cra-nextjs-gatsby\/\" target=\"_blank\" rel=\"noopener\">React<\/a>. You can find the code on <a href=\"https:\/\/codepen.io\/jiayihu\/pen\/vQVWNZ\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">Codepen<\/a>.<\/p>\n<h2>Life-cycle Methods<\/h2>\n<p>We already covered a couple of life-cycle <span id=\"urn:enhancement-6d2bd7e5\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/method_computer_programming\">methods<\/span> in the previous example.<\/p>\n<p>Beside\u00a0<code>connectedCallback()<\/code> and <code>disconnectedCallback()<\/code> there are other life-cycle hooks we can use.<\/p>\n<ul>\n<li><code><b>connectedCallback<\/b><\/code>: is called when our element is added to the document <span id=\"urn:enhancement-9e531a96\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">DOM<\/span>.<\/li>\n<li><code><b>disconnectedCallback<\/b><\/code>: is executed when our element is removed from the <span id=\"urn:enhancement-311c9b70\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">DOM<\/span>. You can add some logic to remove listeners or do something else such as disconnecting from <span id=\"urn:enhancement-6131a2e5\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/websocket\">Web Sockets<\/span>.<\/li>\n<li><code><b>adoptedCallback<\/b><\/code>: is called when you move the element to a new document.<\/li>\n<li><code><b>attributeChangedCallback<\/b><\/code>: this is useful whenever <span id=\"urn:enhancement-6c25a25a\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/attribute_computing\">attributes<\/span> of our element have changed.<\/li>\n<\/ul>\n<h2>HyperHTML and HyperHTMLElement<\/h2>\n<p>HyperHTML is a very small library (4kB) made by Andrea Giammarchi. To get started, all you will need to know is <span id=\"urn:enhancement-f28e52f3\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/html\">HTML<\/span> and, of course, a good knowledge of <span id=\"urn:enhancement-3a1a5c70\" class=\"textannotation disambiguated wl-creative-work\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/javascript\">JavaScript<\/span>.<\/p>\n<p><i>HyperHTML is a <span id=\"urn:enhancement-5a55fd43\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">DOM<\/span> &amp; <span id=\"urn:enhancement-ab62535e\" class=\"textannotation disambiguated wl-creative-work\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/ecmascript\">ECMAScript<\/span> <span id=\"urn:enhancement-d360c6fa\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/standardization\">standard<\/span> compliant, zero-dependency, fully <span id=\"urn:enhancement-48fc4cb2\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/cross-platform\">cross-platform<\/span> library suitable for\u00a0<b>declarative<\/b>\u00a0and\u00a0<b>reactive<\/b>\u00a0<span id=\"urn:enhancement-bb6cdc94\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/web_application\">Web Applications<\/span>.<\/i><\/p>\n<p>The core features are built on top of <b>Template Literals<\/b>, they allow us to embed an expression in a string and we can use multi-line strings and interpolation. They were called \u201ctemplate strings\u201d in previous edition of <span id=\"urn:enhancement-d0b63aa1\" class=\"textannotation disambiguated wl-creative-work\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/ecmascript\">ES6<\/span> specifications.<\/p>\n<p>You can try this snippet of code inside Stackblitz, but remember to import the hyperHTML dependencies:<\/p>\n<p><script src=\"\u201chttps:\/\/pastebin.com\/embed_js\/zve7cfuZ&quot;\"><\/script><\/p>\n<p>The <code>bind<\/code> function declares the layout inside an existing <span id=\"urn:enhancement-52d38087\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">DOM<\/span> element. It renders the template inside a <span id=\"urn:enhancement-8a5d7d88\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">DOM<\/span> element. It returns a function that helps us to mounts the nodes inside the binded element the first time, whereas successive changes in the interpolated values will update only the modified nodes.<\/p>\n<p><b>HyperHTMLElement<\/b> is based on top of hyperHTML and it\u2019s part of its ecosystem. It helps to define our Custom Elements by leveraging hyperHTML as a template engine instead of imperative <strong>vanilla <span id=\"urn:enhancement-45a1ae0a\" class=\"textannotation disambiguated wl-creative-work\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/javascript\">JS<\/span><\/strong>.<\/p>\n<p><b>Template literals<\/b> are enclosed by the back-tick (<code>` `<\/code>) character instead of double or single quotes; they can contain placeholders. The dollar sign and curly braces (${expression}) indicate the presence of a placeholder. You can find a quick example below:<\/p>\n<p><script src=\"https:\/\/pastebin.com\/embed_js\/3B3wcgi1\"><\/script><\/p>\n<p>contain a list of static chunks between interpolations: <code>[\u20181\u2019,\u2019 3\u2019]<\/code>. The second argument is a rest operators argument that will contain the dynamic interpolated values: <code>[\u20182\u2019,\u20194\u2019]<\/code>.<\/p>\n<p>HyperHTML uses the <b>Levenshtein<\/b> distance algorithm to update the internal list of items or nodes. Thanks to this, we have an efficient \u201cupdating <span id=\"urn:enhancement-439a67ab\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">DOM<\/span>\u201d algorithm because it needs the smallest amount of <span id=\"urn:enhancement-5cfb8c14\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/document_object_model\">DOM<\/span> operations to update to the latest template.<\/p>\n<p>Finally, <b>ViperHTML<\/b> is another library from Andrea Giammarchi where we can write <span id=\"urn:enhancement-b5120844\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/web_components\">Web Components<\/span> for \u201c<b><span id=\"urn:enhancement-4937208f\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/server_computing\">Server<\/span> Side Rendering<\/b>\u201d.<\/p>\n<p>In conclusion, there are many interests around Web <span id=\"urn:enhancement-54bae96c\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/component-based_software_engineering\">Component<\/span>. Companies such as <span id=\"urn:enhancement-b8c3d846\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/google\">Google<\/span>, Tencent and <span id=\"urn:enhancement-d1ec374b\" class=\"textannotation disambiguated wl-creative-work\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/github\">GitHub<\/span> are going to use the new <span id=\"urn:enhancement-ce63ca46\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/web_api\">Web API<\/span> <span id=\"urn:enhancement-a8da5948\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/standardization\">standard<\/span> for some of our <span id=\"urn:enhancement-ddbc2df9\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/project\">projects<\/span>. Of course, Web <span id=\"urn:enhancement-677f9377\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/component-based_software_engineering\">Component<\/span> will not replace our mode to write an <span id=\"urn:enhancement-7e2ffdc8\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/application_software\">application<\/span> and you can happily continue to use Angular or other frameworks.<\/p>\n<p><span id=\"urn:enhancement-6aa40055\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/software_standard\">Standards<\/span> are the best way, if not the only one, to move the Web forward (by Andrea Giammarchi). Happy hacking!<\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>The development of Web Application has led us to rewrite some pieces of User Interface so many times in\u00a0 different varieties of JavaScript frameworks for compatibility and interoperability. When we build our User Interface, we have to think about performance, accessibility, compatibility, reusability, extensibility and maintainability. In my personal opinion, many of these aspects are&#8230; <a class=\"more-link\" href=\"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/\">Read more<\/a><\/p>\n","protected":false},"author":79,"featured_media":955,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_editorskit_title_hidden":false,"_editorskit_reading_time":0,"_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","_uag_custom_page_level_css":"","_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[8],"tags":[4,63],"collections":[],"class_list":{"0":"post-997","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-javascript","8":"tag-codemotion-rome","9":"tag-html","10":"entry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v26.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Thinking in Web Component - Codemotion Magazine<\/title>\n<meta name=\"description\" content=\"Web Components extend HTML grammar by defining new custom tags: learn more about them and which libraries to use to properly support this paradigm.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Thinking in Web Component\" \/>\n<meta property=\"og:description\" content=\"Web Components extend HTML grammar by defining new custom tags: learn more about them and which libraries to use to properly support this paradigm.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/\" \/>\n<meta property=\"og:site_name\" content=\"Codemotion Magazine\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Codemotion.Italy\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-12-04T07:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-23T14:30:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Lorenzo Franceschini\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@CodemotionIT\" \/>\n<meta name=\"twitter:site\" content=\"@CodemotionIT\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Lorenzo Franceschini\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/\"},\"author\":{\"name\":\"Lorenzo Franceschini\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/c48e30a376daa81f0b5099d3e0c16b04\"},\"headline\":\"Thinking in Web Component\",\"datePublished\":\"2019-12-04T07:00:00+00:00\",\"dateModified\":\"2021-12-23T14:30:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/\"},\"wordCount\":1305,\"publisher\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920.jpg\",\"keywords\":[\"Codemotion Rome\",\"HTML\"],\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/\",\"name\":\"Thinking in Web Component - Codemotion Magazine\",\"isPartOf\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920.jpg\",\"datePublished\":\"2019-12-04T07:00:00+00:00\",\"dateModified\":\"2021-12-23T14:30:51+00:00\",\"description\":\"Web Components extend HTML grammar by defining new custom tags: learn more about them and which libraries to use to properly support this paradigm.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/#primaryimage\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920.jpg\",\"contentUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920.jpg\",\"width\":1200,\"height\":675},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.codemotion.com\/magazine\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Frontend\",\"item\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Web Developer\",\"item\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/web-developer\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Thinking in Web Component\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#website\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/\",\"name\":\"Codemotion Magazine\",\"description\":\"We code the future. Together\",\"publisher\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.codemotion.com\/magazine\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\",\"name\":\"Codemotion\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png\",\"contentUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png\",\"width\":225,\"height\":225,\"caption\":\"Codemotion\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/Codemotion.Italy\/\",\"https:\/\/x.com\/CodemotionIT\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/c48e30a376daa81f0b5099d3e0c16b04\",\"name\":\"Lorenzo Franceschini\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/adfbaabe86bc433a00657b5827f9f5d47c1d66c20519afedcf67805ef30c9fb2?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/adfbaabe86bc433a00657b5827f9f5d47c1d66c20519afedcf67805ef30c9fb2?s=96&d=mm&r=g\",\"caption\":\"Lorenzo Franceschini\"},\"url\":\"https:\/\/www.codemotion.com\/magazine\/author\/lorenzo-franceschini\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Thinking in Web Component - Codemotion Magazine","description":"Web Components extend HTML grammar by defining new custom tags: learn more about them and which libraries to use to properly support this paradigm.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/","og_locale":"en_US","og_type":"article","og_title":"Thinking in Web Component","og_description":"Web Components extend HTML grammar by defining new custom tags: learn more about them and which libraries to use to properly support this paradigm.","og_url":"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/","og_site_name":"Codemotion Magazine","article_publisher":"https:\/\/www.facebook.com\/Codemotion.Italy\/","article_published_time":"2019-12-04T07:00:00+00:00","article_modified_time":"2021-12-23T14:30:51+00:00","og_image":[{"width":1200,"height":675,"url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920.jpg","type":"image\/jpeg"}],"author":"Lorenzo Franceschini","twitter_card":"summary_large_image","twitter_creator":"@CodemotionIT","twitter_site":"@CodemotionIT","twitter_misc":{"Written by":"Lorenzo Franceschini","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/#article","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/"},"author":{"name":"Lorenzo Franceschini","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/c48e30a376daa81f0b5099d3e0c16b04"},"headline":"Thinking in Web Component","datePublished":"2019-12-04T07:00:00+00:00","dateModified":"2021-12-23T14:30:51+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/"},"wordCount":1305,"publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920.jpg","keywords":["Codemotion Rome","HTML"],"articleSection":["JavaScript"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/","url":"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/","name":"Thinking in Web Component - Codemotion Magazine","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/#primaryimage"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920.jpg","datePublished":"2019-12-04T07:00:00+00:00","dateModified":"2021-12-23T14:30:51+00:00","description":"Web Components extend HTML grammar by defining new custom tags: learn more about them and which libraries to use to properly support this paradigm.","breadcrumb":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/#primaryimage","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920.jpg","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920.jpg","width":1200,"height":675},{"@type":"BreadcrumbList","@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/thinking-in-web-component\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codemotion.com\/magazine\/"},{"@type":"ListItem","position":2,"name":"Frontend","item":"https:\/\/www.codemotion.com\/magazine\/frontend\/"},{"@type":"ListItem","position":3,"name":"Web Developer","item":"https:\/\/www.codemotion.com\/magazine\/frontend\/web-developer\/"},{"@type":"ListItem","position":4,"name":"Thinking in Web Component"}]},{"@type":"WebSite","@id":"https:\/\/www.codemotion.com\/magazine\/#website","url":"https:\/\/www.codemotion.com\/magazine\/","name":"Codemotion Magazine","description":"We code the future. Together","publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codemotion.com\/magazine\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codemotion.com\/magazine\/#organization","name":"Codemotion","url":"https:\/\/www.codemotion.com\/magazine\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","width":225,"height":225,"caption":"Codemotion"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Codemotion.Italy\/","https:\/\/x.com\/CodemotionIT"]},{"@type":"Person","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/c48e30a376daa81f0b5099d3e0c16b04","name":"Lorenzo Franceschini","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/adfbaabe86bc433a00657b5827f9f5d47c1d66c20519afedcf67805ef30c9fb2?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/adfbaabe86bc433a00657b5827f9f5d47c1d66c20519afedcf67805ef30c9fb2?s=96&d=mm&r=g","caption":"Lorenzo Franceschini"},"url":"https:\/\/www.codemotion.com\/magazine\/author\/lorenzo-franceschini\/"}]}},"featured_image_src":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920-600x400.jpg","featured_image_src_square":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920-600x600.jpg","author_info":{"display_name":"Lorenzo Franceschini","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/lorenzo-franceschini\/"},"uagb_featured_image_src":{"full":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920.jpg",1200,675,false],"thumbnail":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920-150x150.jpg",150,150,true],"medium":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920-300x169.jpg",300,169,true],"medium_large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920-768x432.jpg",768,432,true],"large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920-1024x576.jpg",1024,576,true],"1536x1536":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920.jpg",1200,675,false],"2048x2048":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920.jpg",1200,675,false],"small-home-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920.jpg",100,56,false],"sidebar-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920-180x128.jpg",180,128,true],"genesis-singular-images":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920-896x504.jpg",896,504,true],"archive-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920-400x225.jpg",400,225,true],"gb-block-post-grid-landscape":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920-600x400.jpg",600,400,true],"gb-block-post-grid-square":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/09\/code-3337044_1920-600x600.jpg",600,600,true]},"uagb_author_info":{"display_name":"Lorenzo Franceschini","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/lorenzo-franceschini\/"},"uagb_comment_info":0,"uagb_excerpt":"The development of Web Application has led us to rewrite some pieces of User Interface so many times in\u00a0 different varieties of JavaScript frameworks for compatibility and interoperability. When we build our User Interface, we have to think about performance, accessibility, compatibility, reusability, extensibility and maintainability. In my personal opinion, many of these aspects are&#8230;&hellip;","lang":"en","_links":{"self":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/997","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/users\/79"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/comments?post=997"}],"version-history":[{"count":3,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/997\/revisions"}],"predecessor-version":[{"id":15210,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/997\/revisions\/15210"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media\/955"}],"wp:attachment":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media?parent=997"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/categories?post=997"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/tags?post=997"},{"taxonomy":"collections","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/collections?post=997"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}