<?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: Yvan Guekeng Tindo</title>
    <description>The latest articles on DEV Community by Yvan Guekeng Tindo (@gtindo).</description>
    <link>https://dev.to/gtindo</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%2F350158%2Fed263ecf-a47b-46c0-a969-ba4e2a09a7ea.jpeg</url>
      <title>DEV Community: Yvan Guekeng Tindo</title>
      <link>https://dev.to/gtindo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gtindo"/>
    <language>en</language>
    <item>
      <title>The Architect-Executioner Model - Using AI as a Precision Tool, Not a Replacement for Thinking</title>
      <dc:creator>Yvan Guekeng Tindo</dc:creator>
      <pubDate>Wed, 01 Oct 2025 20:25:28 +0000</pubDate>
      <link>https://dev.to/gtindo/the-architect-executioner-model-using-ai-as-a-precision-tool-not-a-replacement-for-thinking-15ip</link>
      <guid>https://dev.to/gtindo/the-architect-executioner-model-using-ai-as-a-precision-tool-not-a-replacement-for-thinking-15ip</guid>
      <description>&lt;h3&gt;
  
  
  The Problem: Confusing Execution with Thought
&lt;/h3&gt;

&lt;p&gt;Developers often make the mistake of treating AI coding agents as partners in &lt;em&gt;thinking&lt;/em&gt; rather than as precision execution tools. Giving a model a vague goal like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Implement the entire new user dashboard"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;asks it to handle complexity, context, and architecture—tasks it struggles with due to context drift and hallucination.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The philosophy:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;You, the developer, are the Architect.&lt;/strong&gt; You define the architecture, manage complexity, and write the blueprint.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AI is the Executioner.&lt;/strong&gt; It performs repetitive, mechanical changes with precision.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The goal: a structured workflow that maximizes both human and AI strengths without replacing thought.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 1: Architect’s Choice – When to Code Manually
&lt;/h2&gt;

&lt;p&gt;Before firing up an agent, decide if the task needs human reasoning or AI execution.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th&gt;Who Handles It&lt;/th&gt;
&lt;th&gt;Why&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;High Conceptual Load&lt;/td&gt;
&lt;td&gt;Human&lt;/td&gt;
&lt;td&gt;Complex algorithms, new service interfaces, tricky concurrency bugs. Human reasoning is critical.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Simple, Isolated Change&lt;/td&gt;
&lt;td&gt;Human&lt;/td&gt;
&lt;td&gt;Typos, variable renames, tiny style adjustments—writing the prompt may take longer than coding.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mechanical, Repetitive Change&lt;/td&gt;
&lt;td&gt;AI&lt;/td&gt;
&lt;td&gt;Generating boilerplate CRUD, migrating components, adding multiple similar unit tests.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;High Context, Low Complexity&lt;/td&gt;
&lt;td&gt;AI&lt;/td&gt;
&lt;td&gt;Tedious changes affecting many files, like renaming props or updating patterns across the app.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Rule of thumb:&lt;/strong&gt; If the task is cognitively heavy, do it yourself. If it's repetitive and mechanical, hand it to the AI.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 2: AI-Driven Prompt Engineering (Planning Phase)
&lt;/h2&gt;

&lt;p&gt;Use an interactive AI (Copilot Chat, ChatGPT, etc.) not to write code, but to &lt;strong&gt;validate your blueprint&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Ask the AI questions like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"What context or instruction is missing for this task?"
"Which conventions or dependencies are unclear?"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ensures the blueprint is complete. The output: a &lt;strong&gt;single, precise prompt&lt;/strong&gt; ready for execution.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 3: Context Constraint – The 10-File Rule
&lt;/h2&gt;

&lt;p&gt;Never let a single AI task touch more than &lt;strong&gt;10 files&lt;/strong&gt;. This enforces:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Context control:&lt;/strong&gt; The LLM can “see” all relevant files, minimizing errors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Faster review:&lt;/strong&gt; Small, focused MRs are easier to validate and merge quickly.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Step 4: The Precision Mandate – Turning AI Into a Diff Machine
&lt;/h2&gt;

&lt;p&gt;Instead of vague instructions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Update the user profile page to support theme toggling."

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Give &lt;strong&gt;line-level, file-specific instructions&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;In src/context/themeContext.js, add setThemeMode.
In src/components/Navbar.jsx, import setThemeMode and call it on button click.
In src/styles/global.css, add a new CSS variable for dark mode color.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why this works:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The AI now executes &lt;strong&gt;exactly what you’ve defined&lt;/strong&gt;, respecting naming conventions, helper methods, and architectural patterns. Accuracy skyrockets (90%+ on the first pass).&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 5: Scaling Complexity – Breaking Down Large Features
&lt;/h2&gt;

&lt;p&gt;For tasks that exceed 10 files, split them into &lt;strong&gt;atomic MRs&lt;/strong&gt;, each with its own blueprint:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;MR 1: Data &amp;amp; Service Layer (Ex: 6 files)&lt;/strong&gt; – Define schema, service methods.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MR 2: State Management &amp;amp; Hooks (Ex: 8 files)&lt;/strong&gt; – Implement global state, fetch data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MR 3: UI Components (Ex: 9 files)&lt;/strong&gt; – Build UI using the new hooks and service layer.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Conclusion: The Modern Developer’s Role
&lt;/h2&gt;

&lt;p&gt;AI is not replacing developers—it’s &lt;strong&gt;elevating them&lt;/strong&gt;. By controlling context, providing precise instructions, and reserving complex thinking for humans:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We speed up execution.&lt;/li&gt;
&lt;li&gt;Reduce cognitive load.&lt;/li&gt;
&lt;li&gt;Maintain architectural integrity.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The Architect-Executioner model:&lt;/strong&gt; you design, AI executes. Clean, fast, and precise.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>productivity</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to Build a Simple Web Component from Scratch</title>
      <dc:creator>Yvan Guekeng Tindo</dc:creator>
      <pubDate>Wed, 22 Jan 2025 15:27:35 +0000</pubDate>
      <link>https://dev.to/gtindo/how-to-build-a-simple-web-component-from-scratch-2b6k</link>
      <guid>https://dev.to/gtindo/how-to-build-a-simple-web-component-from-scratch-2b6k</guid>
      <description>&lt;p&gt;Web components are a set of powerful tools that allow you to create your own custom HTML elements. These elements can be used just like any other HTML tag (e.g., &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt;) but with your own special behavior and design.&lt;/p&gt;

&lt;p&gt;The core technologies behind web components are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements" rel="noopener noreferrer"&gt;&lt;strong&gt;Custom Elements&lt;/strong&gt;&lt;/a&gt;: Allows you to define new HTML tags.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM" rel="noopener noreferrer"&gt;&lt;strong&gt;Shadow DOM&lt;/strong&gt;&lt;/a&gt;: Keeps your element’s structure and styles isolated from the rest of the page.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_templates_and_slots" rel="noopener noreferrer"&gt;&lt;strong&gt;HTML Templates&lt;/strong&gt;&lt;/a&gt;: Lets you define reusable HTML that isn’t rendered until you use it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this guide, we'll build a simple counter component from scratch. This counter will have buttons to increase and decrease a number.&lt;/p&gt;

&lt;p&gt;The component will look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fzzqpuhlwjqjmdz7z5y0l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fzzqpuhlwjqjmdz7z5y0l.png" alt="Image description" width="418" height="196"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the &lt;a href="https://gist.github.com/gtindo/f640e59f2baf7eee7cf7dd8281adae91" rel="noopener noreferrer"&gt;link&lt;/a&gt; for final version with all the source code. &lt;/p&gt;




&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before we begin, here’s what you need to know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Basic &lt;strong&gt;JavaScript&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;A simple understanding of how the &lt;strong&gt;DOM&lt;/strong&gt; (Document Object Model) works (don’t worry if you’re not an expert — we’ll cover what you need).&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Setting Up the Project
&lt;/h2&gt;

&lt;p&gt;First, let’s set up a simple project with two files:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;counter.html&lt;/code&gt;: The HTML file that will hold the page structure.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;counter.js&lt;/code&gt;: The JavaScript file where we define our custom counter element.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;counter.html&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;This file contains the basic HTML structure of your page:&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="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Counter Component&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"./counter.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- The counter component will be inserted here --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Creating the Template
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;template&lt;/strong&gt; is just a way to define the structure of our custom element (like what it looks like). Let’s create one for our counter:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;counter.html&lt;/code&gt; (Add the Template)
&lt;/h3&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;body&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;template&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"x-counter"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"min-btn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;-&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"counter-display"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;0&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"plus-btn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;+&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here’s what each part of this template does:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;&amp;lt;button id="min-btn"&amp;gt;-&amp;lt;/button&amp;gt;&lt;/code&gt;&lt;/strong&gt;: A button to decrease the counter.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;&amp;lt;span id="counter-display"&amp;gt;0&amp;lt;/span&amp;gt;&lt;/code&gt;&lt;/strong&gt;: A place to show the current counter value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;&amp;lt;button id="plus-btn"&amp;gt;+&amp;lt;/button&amp;gt;&lt;/code&gt;&lt;/strong&gt;: A button to increase the counter.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This template will not show up on the page directly. We will use it later to create our custom element.&lt;/p&gt;




&lt;h2&gt;
  
  
  Defining the Custom Counter Element
&lt;/h2&gt;

&lt;p&gt;Now, we’ll write the JavaScript to define how our counter works. We’ll create a &lt;strong&gt;class&lt;/strong&gt; that extends the basic &lt;code&gt;HTMLElement&lt;/code&gt;, which is what all HTML elements are built on.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;counter.js&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;XCounter&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;HTMLElement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&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;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Start the counter at 0&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;elements&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt; &lt;span class="c1"&gt;// To store references to our buttons and display&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&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="c1"&gt;// This runs when the element is added to the page&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;template&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;x-counter&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="nf"&gt;attachShadow&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;open&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="c1"&gt;// Clone the template and add it to our custom element's shadow DOM&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;shadowRoot&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="nx"&gt;template&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cloneNode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

    &lt;span class="c1"&gt;// Get references to the buttons and display&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;elements&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;plusBtn&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;shadowRoot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#plus-btn&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="na"&gt;minBtn&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;shadowRoot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#min-btn&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="na"&gt;counterDisplay&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;shadowRoot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#counter-display&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="c1"&gt;// Show the initial counter value&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;displayCount&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="c1"&gt;// Add event listeners for the buttons&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;elements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;plusBtn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onclick&lt;/span&gt; &lt;span class="o"&gt;=&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;increment&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;elements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;minBtn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onclick&lt;/span&gt; &lt;span class="o"&gt;=&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;decrement&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;increment&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="nx"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&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;displayCount&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;decrement&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="nx"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;1&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;displayCount&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;displayCount&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="nx"&gt;elements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;counterDisplay&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&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;counter&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Register the custom element so we can use it in HTML&lt;/span&gt;
&lt;span class="nx"&gt;customElements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;x-counter&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;XCounter&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Breaking it Down:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The &lt;code&gt;constructor&lt;/code&gt;&lt;/strong&gt;: This is where we set up initial values for our counter and store references to the elements inside the counter.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;connectedCallback&lt;/code&gt;&lt;/strong&gt;: This function runs when the custom element is added to the page. Here, we:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Attach a &lt;strong&gt;shadow DOM&lt;/strong&gt; to keep our element’s structure and styles separate from the rest of the page.&lt;/li&gt;
&lt;li&gt;Clone the template we created earlier and add it to the shadow DOM.&lt;/li&gt;
&lt;li&gt;Set up references to the plus and minus buttons and the display where the counter is shown.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;increment&lt;/code&gt; and &lt;code&gt;decrement&lt;/code&gt;&lt;/strong&gt;: These functions change the value of the counter by 1 and update the display.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;displayCount&lt;/code&gt;&lt;/strong&gt;: This function updates the text inside the &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt; to show the current counter value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Register the element&lt;/strong&gt;: Finally, we tell the browser to recognize &lt;code&gt;&amp;lt;x-counter&amp;gt;&lt;/code&gt; as a custom element that uses the &lt;code&gt;XCounter&lt;/code&gt; class.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Using the Counter Component
&lt;/h2&gt;

&lt;p&gt;Now that our counter is defined, we can use it just like any other HTML element. Here’s how to add it to the page:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;counter.html&lt;/code&gt; (Add the Custom Element)
&lt;/h3&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;body&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;x-counter&amp;gt;&amp;lt;/x-counter&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;template&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"x-counter"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
   ...
  &lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a counter on the page with two buttons — one to increase and one to decrease the number. The counter will start at 0, and you can interact with it by clicking the buttons.&lt;/p&gt;




&lt;h2&gt;
  
  
  Style the element
&lt;/h2&gt;

&lt;p&gt;Styling can be done in a few ways, but when using the Shadow DOM, we can encapsulate the styles to ensure they don’t interfere with other parts of the page. In this section, we will style our counter element using &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/adoptedStyleSheets" rel="noopener noreferrer"&gt;adopteStyleSheet&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  counter.js with Styling
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;...&lt;/span&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="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;attachShadow&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;open&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

         &lt;span class="c1"&gt;// Add styles to the component&lt;/span&gt;
         &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sheet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CSSStyleSheet&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
         &lt;span class="nx"&gt;sheet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replaceSync&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;styles&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;shadowRoot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;adoptedStyleSheets&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;sheet&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

         &lt;span class="c1"&gt;// Clone the template and add it to our custom element's shadow DOM&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;shadowRoot&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="nx"&gt;template&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cloneNode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
        &lt;span class="p"&gt;...&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
    &lt;span class="nf"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`
         :host {
          display: block;
          border: dotted 3px #333;
          width: fit-content;
          height: fit-content;
          padding: 15px;
        }

        button {
          border: solid 1px #333;
          padding: 10px;
          min-width: 35px;
          background: #333;
          color: #fff;
          cursor: pointer;
        }

        button:hover {
          background: #222;
        }

        span {
          display: inline-block;
          padding: 10px;
          width: 50px;
          text-align: center;
        }
      `&lt;/span&gt;
    &lt;span class="p"&gt;}&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;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this tutorial, we learned how to create a simple &lt;strong&gt;web component&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We used an &lt;strong&gt;HTML template&lt;/strong&gt; to define the structure of our custom element.&lt;/li&gt;
&lt;li&gt;We added &lt;strong&gt;shadow DOM&lt;/strong&gt; to isolate the styles and behavior of our component.&lt;/li&gt;
&lt;li&gt;We wrote &lt;strong&gt;JavaScript&lt;/strong&gt; to control the logic of the counter (increment, decrement, and display the count).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Web components are a great way to make your web applications more modular and reusable.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webcomponents</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
