<?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: Marc Backes</title>
    <description>The latest articles on DEV Community by Marc Backes (@themarcba).</description>
    <link>https://dev.to/themarcba</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%2F174026%2F2a7f33cc-b1d3-4038-8f62-fcd47108bf84.jpg</url>
      <title>DEV Community: Marc Backes</title>
      <link>https://dev.to/themarcba</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/themarcba"/>
    <language>en</language>
    <item>
      <title>Unlock "sudo" with TouchID on your Mac</title>
      <dc:creator>Marc Backes</dc:creator>
      <pubDate>Thu, 04 Jan 2024 17:51:08 +0000</pubDate>
      <link>https://dev.to/themarcba/unlock-sudo-with-touchid-on-your-mac-3d0f</link>
      <guid>https://dev.to/themarcba/unlock-sudo-with-touchid-on-your-mac-3d0f</guid>
      <description>&lt;p&gt;Since I got my &lt;a href="https://www.apple.com/shop/product/MK293LL/A/magic-keyboard-with-touch-id-for-mac-models-with-apple-silicon-us-english"&gt;Magic Keybord with integrated TouchID&lt;/a&gt;, I don't rely on my password anymore to authenticate myself on my local machine. &lt;strong&gt;So I thought why not enable it for "sudo" commands in the Terminal as well?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here is how:&lt;/p&gt;

&lt;h2&gt;
  
  
  Copy &lt;code&gt;sudo_local&lt;/code&gt; file
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo cp&lt;/span&gt; /etc/pam.d/sudo_local.template /etc/pam.d/sudo_local
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Edit &lt;code&gt;sudo_local&lt;/code&gt; file
&lt;/h2&gt;

&lt;p&gt;Uncomment the following line in the newly copied &lt;code&gt;sudo_local&lt;/code&gt; file (e.g. with &lt;code&gt;sudo vi /etc/pam.d/sudo_local&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;auth       sufficient     pam_tid.so
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save the file, and voilà!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;You might have to &lt;code&gt;exit&lt;/code&gt; your current shell or open a new one before it works&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>What is Vue Storefront?</title>
      <dc:creator>Marc Backes</dc:creator>
      <pubDate>Wed, 11 May 2022 08:35:46 +0000</pubDate>
      <link>https://dev.to/vue-storefront/what-is-vue-storefront-5e0h</link>
      <guid>https://dev.to/vue-storefront/what-is-vue-storefront-5e0h</guid>
      <description>&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%2Fm2bxrw1rdah8z4p7ott7.gif" 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%2Fm2bxrw1rdah8z4p7ott7.gif" alt="GIF showing a man saying "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You might have seen the presence of Vue Storefront on social media, conferences, and so on. But do you know what Vue Storefront is?&lt;/p&gt;

&lt;p&gt;In this article I will take you through a journey of getting to know the basics of what Vue Storefront as a frontend framework does.&lt;/p&gt;

&lt;h1&gt;
  
  
  What actually is Vue Storefront? 🤷‍♂️
&lt;/h1&gt;

&lt;p&gt;Vue Storefront is an eCommerce frontend framework that connects to&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An eCommerce backend (such as Shopify, Magento, etc.)&lt;/li&gt;
&lt;li&gt;Other third-party services (CMS, payment, authentication, etc.)&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Connecting services 🔗
&lt;/h1&gt;

&lt;p&gt;So if you want to create an eCommerce shop, Vue Storefront helps you combine all these services you need in order to create a shop.&lt;/p&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%2Fsvdzhpdj68ib4n9asgew.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%2Fsvdzhpdj68ib4n9asgew.png" alt="An image showing how Vue Storefront connects to eCommerce, CMS, payment, authentication, search services"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Example:
&lt;/h2&gt;

&lt;p&gt;You might have a Shopify eCommerce platform, but want to add copy for a promotion you're having, provide a separate payment option with PayPal, authenticate your user to give them a a personalized experience, include a search in your shop.&lt;/p&gt;

&lt;p&gt;With Vue Storefront, you can get this done by adding a CMS for the copy, the PayPal integration for the checkout, the Auth0 integration for authenticating your users, and the Algolia integration for adding search functionality.&lt;/p&gt;

&lt;h1&gt;
  
  
  What does Vue Storefront do for you? 👀
&lt;/h1&gt;

&lt;p&gt;As you can see in the example above, you can integrate different services to fit your needs, and Vue Storefront does the rest of the heavy lifting 🏋️‍♂️&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Providing a lightning-fast online shop for you to work with&lt;/li&gt;
&lt;li&gt;Facilitate extensivility&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Lightning-fast online shop ⚡
&lt;/h2&gt;

&lt;p&gt;Vue Storefront provides a lightning-fast online shop by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keeping the bundle size small (Using modern technologies)&lt;/li&gt;
&lt;li&gt;It only loads what’s needed (Leveraging Code Splitting, Lazy Loading, Lazy Hydration)&lt;/li&gt;
&lt;li&gt;It loads already-visited pages instantly (By caching the page on the first visit, Preloading resources that might be needed in the future)&lt;/li&gt;
&lt;li&gt;Is hosts and executes as much as possible on the server (So the part served to the users is much lighter and faster)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Extensibility 🔌
&lt;/h2&gt;

&lt;p&gt;You can extend Vue Storefront to your liking&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;By using some of the integrations maintained by the Vue Storefront team or community&lt;/li&gt;
&lt;li&gt;Or choosing between hundreds of Nuxt modules&lt;/li&gt;
&lt;li&gt;As a developer, you can also create new integrations for a certain platform, and make it available to other users&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Tech Stack 🥞
&lt;/h1&gt;

&lt;p&gt;Vue Storefront is essentially a &lt;a href="https://nuxtjs.org/" rel="noopener noreferrer"&gt;Nuxt&lt;/a&gt; application, which is extended by modules and plugins.&lt;/p&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%2Fa2nwbpoz10llbr7ywxia.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%2Fa2nwbpoz10llbr7ywxia.png" alt="Nuxt + Modules + Plugins"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;☝️ The frontend is largely handled by Nuxt.&lt;br&gt;
💪 Vue Storefront adds eCommerce capabilities through Nuxt &lt;em&gt;modules&lt;/em&gt; and &lt;em&gt;plugins&lt;/em&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Storefront UI
&lt;/h1&gt;

&lt;p&gt;Vue Storefront also includes &lt;a href="https://www.vuestorefront.io/storefront-ui" rel="noopener noreferrer"&gt;Storefront UI&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A Vue.js &lt;strong&gt;design system&lt;/strong&gt; and &lt;strong&gt;UI&lt;/strong&gt; for headless commerce.&lt;/p&gt;

&lt;p&gt;It’s installed &lt;strong&gt;by default&lt;/strong&gt; to all Vue Storefront project, but you can install the UI library you prefer.&lt;/p&gt;

&lt;p&gt;Storefront UI is&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;100% customizable&lt;/li&gt;
&lt;li&gt;Open-Source&lt;/li&gt;
&lt;li&gt;Made and optimized for eCommerce and Vue Storefront&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Summary 📋
&lt;/h1&gt;

&lt;p&gt;Let's summarize the most important take-aways from this blog post&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Vue Storefront  is a frontend app to build online shops&lt;/li&gt;
&lt;li&gt;It does a lot of the heavy lifting for you in terms of performance&lt;/li&gt;
&lt;li&gt;It is a Nuxt application, extended with eCommerce capabilities&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  More questions? ❓
&lt;/h1&gt;

&lt;p&gt;If you have any more questions about Vue Storefront, then please join our &lt;a href="https://discord.vuestorefront.io" rel="noopener noreferrer"&gt;Discord server&lt;/a&gt;. Our team is happy to talk to you 😊&lt;/p&gt;

</description>
      <category>vuestorefront</category>
      <category>vue</category>
      <category>ecommerce</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Bug, Error, Defect, Failure Explained</title>
      <dc:creator>Marc Backes</dc:creator>
      <pubDate>Thu, 15 Oct 2020 12:36:06 +0000</pubDate>
      <link>https://dev.to/themarcba/bug-error-defect-failure-explained-1mkd</link>
      <guid>https://dev.to/themarcba/bug-error-defect-failure-explained-1mkd</guid>
      <description>&lt;p&gt;Often, terms like error, bug, defect, failure are used interchangeably. But each one has its own meaning. In this post, I will explain the differences.&lt;/p&gt;

&lt;h1&gt;
  
  
  TD;DR
&lt;/h1&gt;

&lt;p&gt;The following quote explains in a nutshell what you need to know about the differences between error, bug, defect, failure.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A coding mistake is called an &lt;strong&gt;error&lt;/strong&gt;. The error found by the tester is called a &lt;strong&gt;defect&lt;/strong&gt;. A defect accepted by the development team is called &lt;strong&gt;bug&lt;/strong&gt;. If the software does not meet the requirements, then it is &lt;strong&gt;failure&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Error
&lt;/h1&gt;

&lt;p&gt;An error happens during coding. This can be a range of things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Syntax error (wrongly using the programming syntax)&lt;/li&gt;
&lt;li&gt;Compiling error (the syntax is fine, but there is another problem during compilation, for example, the wrong use of a variable)&lt;/li&gt;
&lt;li&gt;Runtime error (the program crashes when it is running)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In short, something that breaks the code. This always happens at the &lt;strong&gt;development side&lt;/strong&gt;, so this is something the programmer/developer detects.&lt;/p&gt;

&lt;h1&gt;
  
  
  Defect
&lt;/h1&gt;

&lt;p&gt;When a tester detects that the program does not behave the way it is supposed to, that is a &lt;strong&gt;defect&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A defect could be caused by an underlying &lt;em&gt;error&lt;/em&gt; (but not necessarily). For example, this would happen if a JavaScript error is thrown due to a DOM element not being yet available, but the code is trying to access it. This would result in the rest of the code not running, ergo: Resulting in unexpected behavior.&lt;/p&gt;

&lt;p&gt;However, the code could run error-free, but there still could be mistakes in the logic of the code. For example, updating a value in the database and forgetting to save that change. This would not cause an error; however, it would be a &lt;em&gt;defect&lt;/em&gt; because the program doesn't behave as it is supposed to.&lt;/p&gt;

&lt;p&gt;Defects are usually detected by testers.&lt;/p&gt;

&lt;h1&gt;
  
  
  Bug
&lt;/h1&gt;

&lt;p&gt;When a &lt;em&gt;defect&lt;/em&gt;, detected by a tester, is sent to the developer and they find that indeed it is due to a programming mistake, it is &lt;strong&gt;accepted as a bug&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The developer looks for the cause of the bug (debugging) and once the culprit is found, the bug is being &lt;em&gt;fixed&lt;/em&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Fun fact: It is called &lt;em&gt;bug&lt;/em&gt;, because in the early days of computing when electromechanical relays were used, and an actual &lt;em&gt;bug&lt;/em&gt; (e.g., a moth) is trapped in a relay, causing the program to malfunction.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Failure
&lt;/h1&gt;

&lt;p&gt;A failure is when the program can't work the way it was intended to, but not due to a programming mistake.&lt;/p&gt;

&lt;p&gt;For example, this could be faulty software requirements (not specifying that something needs to be implemented) or other reasons, such as network problems not caused by the software. (Although the software should catch those programs and show the user an error).&lt;/p&gt;

&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;p&gt;Well, there you have it - the differences between an error, a defect, a bug, and a failure. So if next time there is a problem with the program, you can use the correct term, so everyone knows the &lt;em&gt;nuance&lt;/em&gt; of the problem at hand.&lt;/p&gt;

</description>
      <category>beginners</category>
    </item>
    <item>
      <title>What is a Senior Developer *Really*?</title>
      <dc:creator>Marc Backes</dc:creator>
      <pubDate>Thu, 15 Oct 2020 12:34:38 +0000</pubDate>
      <link>https://dev.to/themarcba/what-is-a-senior-developer-really-59dg</link>
      <guid>https://dev.to/themarcba/what-is-a-senior-developer-really-59dg</guid>
      <description>&lt;p&gt;There is a common misconception of what a senior developer is. Some may tell you it's the years of experience, others may say it's the "bugfixes per second". It's none of those.&lt;/p&gt;

&lt;h1&gt;
  
  
  What a senior developer is &lt;em&gt;NOT&lt;/em&gt; ☝️
&lt;/h1&gt;

&lt;p&gt;When you look for a developer/software engineer job and read through the postings, you find a pattern where recruiters seem to define a &lt;strong&gt;senior developer&lt;/strong&gt; on the number of years they have experience in the field. Well, this is not how it works. Determining what and what, not a senior developer is, is more complicated than that.&lt;/p&gt;

&lt;p&gt;Let's start with what they are &lt;strong&gt;not&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;People that know &lt;em&gt;everything&lt;/em&gt; about a programming language&lt;/li&gt;
&lt;li&gt;Know all the answers&lt;/li&gt;
&lt;li&gt;The absolute truth&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Problem solving 💡
&lt;/h1&gt;

&lt;p&gt;One of the essential traits of a senior developer is the ability to solve problems quickly while also:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;staying efficient&lt;/li&gt;
&lt;li&gt;making sure not to introduce unnecessary sources of errors&lt;/li&gt;
&lt;li&gt;creating as little friction with the existing system as possible&lt;/li&gt;
&lt;li&gt;thinking of the bigger picture&lt;/li&gt;
&lt;li&gt;having expandability/reusability in mind&lt;/li&gt;
&lt;li&gt;make decisions about potential trade-offs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is not always enough time to make perfect solutions. A senior developer must know which sub-optimal solution they can accept for the moment, but be sure to raise awareness that it's a quick solution &lt;em&gt;for now&lt;/em&gt; but that it needs to be changed sometime in the future.&lt;/p&gt;

&lt;h1&gt;
  
  
  Tech skills &amp;amp; experience 🛠
&lt;/h1&gt;

&lt;p&gt;Of course, it is important that a senior developer has a vast amount of technical skills experience. This does &lt;strong&gt;not&lt;/strong&gt; mean that they know every syntax by heart and can list all the array functions available.&lt;/p&gt;

&lt;p&gt;No, this has more to do with knowing what tools and software patterns are out there, so they can choose the correct one for the problem at hand.&lt;/p&gt;

&lt;p&gt;Often, a senior developer has some sixth sense when it comes to possible roadblocks. This experience is drawn from previous projects. They can't immediately explain why one road may be worse, but they can almost bet on why one solution would be better. When they look closely at the problem, they will eventually find what's wrong exactly with a given approach, though.&lt;/p&gt;

&lt;p&gt;It's also vital to &lt;em&gt;know what you don't know&lt;/em&gt; and do some more research to learn more about the problem.&lt;/p&gt;

&lt;h1&gt;
  
  
  Knowledge of technologies ⚙️
&lt;/h1&gt;

&lt;p&gt;A great senior developer also knows about tools available, even if they are not using them and even if they don't remember &lt;em&gt;exactly&lt;/em&gt; how they work. They know when the occasion arises that there is something &lt;em&gt;out there&lt;/em&gt; that could be a great fit.&lt;/p&gt;

&lt;p&gt;They are experts in pairing the perfect tool with a given problem. They might have to do some research to ensure that a tool is right for the job, but they know what to look for.&lt;/p&gt;

&lt;p&gt;Especially at the beginning of a new project, a senior developer should make wise choices of which decisions pay off in the long run.&lt;/p&gt;

&lt;h1&gt;
  
  
  From start to the end 🌟
&lt;/h1&gt;

&lt;p&gt;A senior developer is capable of handling every step of the way to build a part of the software:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Analyze the problem&lt;/li&gt;
&lt;li&gt;Understand the problem&lt;/li&gt;
&lt;li&gt;Form a viable solution for the problem&lt;/li&gt;
&lt;li&gt;Implement the solution&lt;/li&gt;
&lt;li&gt;Test the solution&lt;/li&gt;
&lt;li&gt;Integrate the solution&lt;/li&gt;
&lt;li&gt;Deploy the solution&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Mentoring 😊
&lt;/h1&gt;

&lt;p&gt;One important quality that every senior developer should possess is to be able to &lt;strong&gt;lead others&lt;/strong&gt;. This means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Help them to up their skills&lt;/li&gt;
&lt;li&gt;Guide them to better solutions and help them understand why&lt;/li&gt;
&lt;li&gt;Help them when they are stuck&lt;/li&gt;
&lt;li&gt;Don't look down on them&lt;/li&gt;
&lt;li&gt;Provide them with interesting and helpful resources&lt;/li&gt;
&lt;li&gt;Cheer others on&lt;/li&gt;
&lt;li&gt;Share what you know&lt;/li&gt;
&lt;li&gt;Give credit where credit is due&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Communication 💬
&lt;/h1&gt;

&lt;p&gt;Senior developers should be great communicators:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Explain a problem to someone in an understandable way (even to non-tech people)&lt;/li&gt;
&lt;li&gt;Present a solution and explain why among all the solutions, his is the best&lt;/li&gt;
&lt;li&gt;Navigate political situations in the workplace&lt;/li&gt;
&lt;li&gt;Try to shield other developers from bad management decisions&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Humbleness 🙏
&lt;/h1&gt;

&lt;p&gt;A senior developer is not always right, and they should know that. Everyone makes mistakes, and when they make one, they should own up to them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Raise awareness of a problem&lt;/li&gt;
&lt;li&gt;Claiming responsibility&lt;/li&gt;
&lt;li&gt;Analyze the severity of a problem&lt;/li&gt;
&lt;li&gt;Have a range of solutions to solve the problem&lt;/li&gt;
&lt;li&gt;Accept help&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, a senior developer should &lt;strong&gt;never&lt;/strong&gt; assume they are always right. They should analyze input from others and be prepared to accept it as a better solution. However, they should not be easily influenced by others either. They should always have the best solution in mind. There is no place for ego.&lt;/p&gt;

&lt;h1&gt;
  
  
  Summary ✨
&lt;/h1&gt;

&lt;p&gt;In summary, a senior developer is really good at solving problems, choosing the right technology for a job, and helping others excel at their own job.&lt;/p&gt;

</description>
      <category>career</category>
    </item>
    <item>
      <title>Create Your Own Vue.js From Scratch - Part 5 (Bringing it all together)</title>
      <dc:creator>Marc Backes</dc:creator>
      <pubDate>Sat, 23 May 2020 12:51:14 +0000</pubDate>
      <link>https://dev.to/themarcba/create-your-own-vue-js-from-scratch-part-5-bringing-it-all-together-4eb3</link>
      <guid>https://dev.to/themarcba/create-your-own-vue-js-from-scratch-part-5-bringing-it-all-together-4eb3</guid>
      <description>&lt;p&gt;If you like this article, chances are you'd like what I tweet as well. If you are curious, have a look at my &lt;a href="https://twitter.com/_marcba"&gt;Twitter profile&lt;/a&gt;. 🚀&lt;/p&gt;

&lt;p&gt;This post is the fifth part of a series called &lt;strong&gt;Create Your Own Vue.js From Scratch&lt;/strong&gt;, where I teach you how to create the fundamentals of a reactive framework such as Vue.js. To follow this blog post, I suggest you first read the other parts of the series.&lt;/p&gt;

&lt;h1&gt;
  
  
  Roadmap 🚘
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Introduction (this post)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://marc.dev/blog/vue-from-scratch-part-2"&gt;Virtual DOM basics&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/_marcba/create-your-own-vue-js-from-scratch-part-2-building-the-vdom-3bp2"&gt;Implementing the virtual DOM &amp;amp; rendering&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/_marcba/create-your-own-vue-js-from-scratch-part-3-building-the-reactivity-5162"&gt;Building reactivity&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/_marcba/create-your-own-vue-js-from-scratch-part-5-bringing-it-all-together-4eb3"&gt;Bringing it all together&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Recap
&lt;/h1&gt;

&lt;p&gt;In the last posts, we &lt;a href="https://marc.dev/blog/vue-from-scratch-part-3"&gt;created our own virtual DOM&lt;/a&gt; and &lt;a href="https://marc.dev/blog/vue-from-scratch-part-4"&gt;replicated a rudimentary Vue 2 reactivity&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For the virtual DOM, we created an engine that allows us to create virtual nodes, mount/unmount them to/from the actual DOM. The code can be found on &lt;a href="https://gist.github.com/themarcba/2a471e1f0592201fc5036cb40bdbee1f"&gt;Github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For the reactivity, we built a dependency class, which we then use to detect changes in object property changes, we bound using &lt;code&gt;Object.definePropert()&lt;/code&gt;. The code can be found on &lt;a href="https://gist.github.com/themarcba/618264a12f277f10570c30759c592546"&gt;Github&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Preparation
&lt;/h1&gt;

&lt;p&gt;First, we create a new HTML-file add a &lt;code&gt;div&lt;/code&gt; with the ID &lt;code&gt;app&lt;/code&gt;, and &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag.&lt;/p&gt;

&lt;p&gt;Second, we copy the following functions from the VDOM example into the &lt;code&gt;&amp;lt;script&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt;-tag:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;h&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;mount&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;unmount&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;patch&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Third, we copy the following elements from the reactivity example into the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt;-tag:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;Dep&lt;/code&gt;-class&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;watchEffect&lt;/code&gt;-function&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;reactive&lt;/code&gt;-function&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;activeEffect&lt;/code&gt; variable declaration&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Writing our template
&lt;/h1&gt;

&lt;p&gt;Let's assume we want to create a very simple click-counter like this one:&lt;/p&gt;

&lt;p&gt;&lt;a href="//images.ctfassets.net/r1crnaxclhxs/79NewCkTOeI76hEPSRuCS4/5afd9804552ed093944f6af7b300a18f/mini-vue-click-counter.gif" class="article-body-image-wrapper"&gt;&lt;img src="//images.ctfassets.net/r1crnaxclhxs/79NewCkTOeI76hEPSRuCS4/5afd9804552ed093944f6af7b300a18f/mini-vue-click-counter.gif" alt="mini-vue-click-counter"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We would need a structure like this:&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;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;NUMBER_OF_CLICKS&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;clicks&lt;span class="nt"&gt;&amp;lt;/p&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;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;#app&lt;/code&gt;-div is the mounting point for our application, so we just need to create a template for the &lt;code&gt;.clickContainer&lt;/code&gt; and it's content. For this, we write a function that returns the template we will render to the DOM later, using the &lt;code&gt;h&lt;/code&gt;-function from the VDOM:&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;clickCount&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="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;div&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="na"&gt;class&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;container&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="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;h1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;clickCount&lt;/span&gt;&lt;span class="p"&gt;)],&lt;/span&gt;
        &lt;span class="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;p&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;clicks&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Create our reactive state
&lt;/h1&gt;

&lt;p&gt;In this simple example, we only have one variable, so one property in our reactive state:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;reactive&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&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;h1&gt;
  
  
  Make our VDOM reactive
&lt;/h1&gt;

&lt;p&gt;We're almost done. What we need to do now is to call the &lt;code&gt;watchEffect&lt;/code&gt; function, so we can react upon changes in the &lt;code&gt;state.count&lt;/code&gt; property. There are two scenarios for this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It's the first time our callback function gets called: We need to mount the template to the DOM&lt;/li&gt;
&lt;li&gt;It's not the first time our callback function gets called: We need to &lt;code&gt;patch()&lt;/code&gt; the node in the DOM&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To differenciate between this, let's create a variable &lt;code&gt;previousNode&lt;/code&gt;.&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;previousVnode&lt;/span&gt;
&lt;span class="nf"&gt;watchEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;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="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;previousVnode&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// No previous node. We must mount it to the DOM&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// There is a previous node. We need to patch it (update)&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;For the first case, we create a new node with our &lt;code&gt;render&lt;/code&gt; function and mount it to the DOM:&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="nx"&gt;previousVnode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="nf"&gt;mount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;previousVnode&lt;/span&gt;&lt;span class="p"&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="s1"&gt;app&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;For the second case, we create a new node and patch it to the &lt;code&gt;previousNode&lt;/code&gt;. (Compare and see what the differences are).&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newVnode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="nf"&gt;patch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;previousVnode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;newVnode&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;previousVnode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;newVnode&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Create the click event
&lt;/h1&gt;

&lt;p&gt;Our reactive DOM is now done. It will react to changes to the &lt;code&gt;state.count&lt;/code&gt; variable. The last thing left for our counter to work is to increment the counter on the click of the &lt;code&gt;#app&lt;/code&gt; element:&lt;/p&gt;

&lt;p&gt;We just add &lt;code&gt;onclick="state.count++"&lt;/code&gt; to it:&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;app&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;onclick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;state.count++&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And voilà! We have a simple click counter, we built on top of our own reactive library.&lt;/p&gt;

&lt;p&gt;Congratulations! 🎉&lt;/p&gt;

&lt;h1&gt;
  
  
  Add some style
&lt;/h1&gt;

&lt;p&gt;This of course still looks ugly. To make it a little bit fancier, add a &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt;-tag to the top of the document and add the following CSS code to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;user-select&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'Helvetica Neue'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Helvetica&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Arial&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;#app&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#41b883&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#ffffff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;900&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;text-align&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3rem&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;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;p&gt;This is a very simple example, and could be done with &lt;strong&gt;way&lt;/strong&gt; less code in simple JavaScript. However, keep in mind that this series is for educational purposes, so you get an insight to the internals of a frontend framework. It's not meant for you to create your own framework and use it in production. (Of course, you could.)&lt;/p&gt;

&lt;p&gt;In this last part (for now), there we learned how to put together our own reactivity with our own virtual DOM to create a rudimentary reactive frontend framework. If you are keen to build more stuff on top of this, go ahead. You'll learn a lot in the process. If you built something, let me know and I'll check it out. Curious if someone uses this to learn stuff.&lt;/p&gt;

&lt;p&gt;There might be a bonus coming some day where I build something more advanced with this "framework".&lt;/p&gt;

&lt;p&gt;The code of this last part can be found on &lt;a href="https://gist.github.com/themarcba/4975abf6340fd3816172c77d4cb8c3ef"&gt;Github&lt;/a&gt; as well.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Original cover photo by &lt;a href="https://unsplash.com/@joshuaearle?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Joshua Earle&lt;/a&gt; on Unplash, edited by &lt;a href="https://marc.dev/"&gt;Marc Backes&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Create Your Own Vue.js From Scratch - Part 4 (Building The Reactivity)</title>
      <dc:creator>Marc Backes</dc:creator>
      <pubDate>Sat, 25 Apr 2020 10:41:03 +0000</pubDate>
      <link>https://dev.to/themarcba/create-your-own-vue-js-from-scratch-part-3-building-the-reactivity-5162</link>
      <guid>https://dev.to/themarcba/create-your-own-vue-js-from-scratch-part-3-building-the-reactivity-5162</guid>
      <description>&lt;p&gt;If you like this article, chances are you'd like what I tweet as well. If you are curious, have a look at my &lt;a href="https://twitter.com/_marcba"&gt;Twitter profile&lt;/a&gt;. 🚀&lt;/p&gt;

&lt;p&gt;This post is the fourth part of a series called &lt;strong&gt;Create Your Own Vue.js From Scratch&lt;/strong&gt;, where I teach you how to create the fundamentals of a reactive framework such as Vue.js. To follow this blog post, I suggest you read about the other parts of this series first.&lt;/p&gt;

&lt;h1&gt;
  
  
  Roadmap 🚘
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/_marcba/coding-a-vue-js-like-framework-from-scratch-part-1-introduction-3nbf"&gt;Introduction&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/_marcba/create-your-own-vue-js-from-scratch-part-2-virtual-dom-basics-58fm"&gt;Virtual DOM basics&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://marc.dev/blog/vue-from-scratch-part-3"&gt;Implementing the virtual DOM &amp;amp; rendering&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Building reactivity (this post)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/_marcba/create-your-own-vue-js-from-scratch-part-5-bringing-it-all-together-4eb3"&gt;Bringing it all together&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  What is state reactivity?
&lt;/h1&gt;

&lt;p&gt;State reactivity is when we &lt;em&gt;do something&lt;/em&gt; (react) when the state of our application (set of variables) changes. We do this in two steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a &lt;em&gt;"reactive dependency"&lt;/em&gt; (We get notified when a variable changes)&lt;/li&gt;
&lt;li&gt;Create a "&lt;em&gt;reactive state&lt;/em&gt;" (Basically a collection of dependency variables)&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  1. Building a reactive dependency
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Function to watch over changes
&lt;/h2&gt;

&lt;p&gt;For this to work, we first need a function that is executed when a reactive dependency changes. As in Vue, this is called &lt;code&gt;watchEffect&lt;/code&gt;; we'll also call our function that.&lt;/p&gt;

&lt;p&gt;In our example, this function looks like this:&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;watchEffect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;activeEffect&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fn&lt;/span&gt;
    &lt;span class="nf"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nx"&gt;activeEffect&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The global variable &lt;code&gt;activeEffect&lt;/code&gt; is a temporary variable where we store our function, passed to &lt;code&gt;watchEffect&lt;/code&gt;. This is necessary, so we can access the function when itself reads a dependency that refers to that function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dependency class
&lt;/h2&gt;

&lt;p&gt;We can see a &lt;em&gt;reactive dependency&lt;/em&gt; as a variable that notifies to its subscribers when it's value changes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  It can be created with an initial value, so we need a &lt;strong&gt;constructor&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;  We need to &lt;em&gt;subscribe&lt;/em&gt; a function to changes on the dependency. We'll call this &lt;code&gt;depend()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  We need a to &lt;em&gt;notify&lt;/em&gt; subscribed functions of the dependency when the value changes. We'll call this &lt;code&gt;notify()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  We need to do something when the value gets read or written, so we need a &lt;strong&gt;getter&lt;/strong&gt; and a &lt;strong&gt;setter&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So our skeleton will look like this:&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Dep&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Initialize the value of the reactive dependency&lt;/span&gt;
    &lt;span class="nf"&gt;constructor&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;span class="p"&gt;{}&lt;/span&gt;

    &lt;span class="c1"&gt;// Subscribe a new function as observer to the dependency&lt;/span&gt;
    &lt;span class="nf"&gt;depend&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

    &lt;span class="c1"&gt;// Notify subscribers of a value change&lt;/span&gt;
    &lt;span class="nf"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

    &lt;span class="c1"&gt;// Getter of the dependency. Executed when a part of the software reads the value of it.&lt;/span&gt;
    &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="nf"&gt;value&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

    &lt;span class="c1"&gt;// Setter of the dependency. Executed when the value changes&lt;/span&gt;
    &lt;span class="kd"&gt;set&lt;/span&gt; &lt;span class="nf"&gt;value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newValue&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;p&gt;The class has two fields: &lt;code&gt;value&lt;/code&gt; (value of the dependency) and &lt;code&gt;subscribers&lt;/code&gt; (set of subscribed functions).&lt;/p&gt;

&lt;p&gt;We implement this step by step.&lt;/p&gt;

&lt;h3&gt;
  
  
  Constructor
&lt;/h3&gt;

&lt;p&gt;In the constructor, we initialize the two fields.&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="nf"&gt;constructor&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;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;_value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="c1"&gt;// not `value` because we add getter/setter named value&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;subscribers&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;Set&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;&lt;code&gt;subscribers&lt;/code&gt; needs to be a &lt;code&gt;Set&lt;/code&gt;, so we don't repeatedly subscribe to the same function.&lt;/p&gt;

&lt;h3&gt;
  
  
  Subscribe a function
&lt;/h3&gt;

&lt;p&gt;Here, we need to subscribe a new function as an observer to the dependency. We call this &lt;code&gt;depend&lt;/code&gt;.&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="nf"&gt;depend&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="nx"&gt;activeEffect&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;subscribers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;activeEffect&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;&lt;code&gt;activeEffect&lt;/code&gt; is a temporary variable that is set in the &lt;code&gt;watchEffect&lt;/code&gt; which is explained later on in this tutorial.&lt;/p&gt;

&lt;h3&gt;
  
  
  Notify subscribers of a dependency change
&lt;/h3&gt;

&lt;p&gt;When a value changes, we call this function, so we can notify all subscribers when the dependency value changes.&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="nf"&gt;notify&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;subscribers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;subscriber&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;subscriber&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;What we do here is to execute every &lt;em&gt;subscriber&lt;/em&gt;. Remember: This is a &lt;em&gt;subscriber&lt;/em&gt; is a &lt;code&gt;function&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Getter
&lt;/h3&gt;

&lt;p&gt;In the &lt;em&gt;getter&lt;/em&gt; of the dependency, we need to add the &lt;code&gt;activeEffect&lt;/code&gt; (function that will be executed when a change in the dependency occurs) to the list of subscribers. In other words, use the &lt;code&gt;depend()&lt;/code&gt; method we defined earlier.&lt;/p&gt;

&lt;p&gt;As a result, we return the current value.&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="kd"&gt;get&lt;/span&gt; &lt;span class="nf"&gt;value&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;depend&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;return&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;_value&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Setter
&lt;/h3&gt;

&lt;p&gt;In the &lt;em&gt;setter&lt;/em&gt; of the dependency, we need to execute all functions that are &lt;em&gt;watching&lt;/em&gt; this dependency (subscribers). In other words, use the &lt;code&gt;notify()&lt;/code&gt; method we defined earlier.&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="kd"&gt;set&lt;/span&gt; &lt;span class="nf"&gt;value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newValue&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;_value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;newValue&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;notify&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;
  
  
  Try it out
&lt;/h2&gt;

&lt;p&gt;The implementation of dependency is done. Now it's time we try it out. To achieve that, we need to do 3 things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Define a dependency&lt;/li&gt;
&lt;li&gt;  Add a function to be executed on dependency changes&lt;/li&gt;
&lt;li&gt;  Change the value of the dependency
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Create a reactive dependency with the value of 1&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;count&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;Dep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Add a "watcher". This logs every change of the dependency to the console.&lt;/span&gt;
&lt;span class="nf"&gt;watchEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;👻 value changed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;count&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;span class="p"&gt;})&lt;/span&gt;

&lt;span class="c1"&gt;// Change value&lt;/span&gt;
&lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the console log you should be able to see something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;👻 value changed 1
👻 value changed 2
👻 value changed 3
👻 value changed 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can find the complete code for the dependency on 👉 &lt;a href="https://gist.github.com/themarcba/f4d15000999f8921c584b6f78bff2867"&gt;Github&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  2. Building a reactive state
&lt;/h1&gt;

&lt;p&gt;This is only the first part of the puzzle and mainly necessary to understand better what is going to happen next.&lt;/p&gt;

&lt;p&gt;To recap: We have a &lt;em&gt;reactive dependency&lt;/em&gt; and a &lt;em&gt;watch function&lt;/em&gt; that together give us the possibility to execute a function whenever the variable (dependency) changes. Which is already pretty damn cool. But we want to go a step further and create a &lt;em&gt;state&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Instead of somthing like this:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Dep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Dep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Marc&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Johnny&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We want to do something like this:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;reactive&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Marc&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="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Johnny&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To achieve this, we need to make some changes to our code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Add the &lt;code&gt;reactive&lt;/code&gt; function. This created the "&lt;em&gt;state&lt;/em&gt;" object.&lt;/li&gt;
&lt;li&gt;  Move &lt;em&gt;getter&lt;/em&gt; and &lt;em&gt;setter&lt;/em&gt; to the state instead of the dependency (because this is where the changes happen)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So the dependency (&lt;code&gt;Dep&lt;/code&gt;) will only serve as such. Just the dependency part, not containing any value. The values are stored in the &lt;em&gt;state&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The reactive function
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;reactive()&lt;/code&gt; function can be seen as an initialization for the state. We pass an object to it with initial values, which is then converted to dependencies.&lt;/p&gt;

&lt;p&gt;For each object property, the following must be done:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Define a dependency (&lt;code&gt;Dep&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;  Definer &lt;em&gt;getter&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;  Define &lt;em&gt;setter&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;reactive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dep&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;Dep&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;defineProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nx"&gt;dep&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;depend&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newValue&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="nx"&gt;newValue&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;newValue&lt;/span&gt;
                    &lt;span class="nx"&gt;dep&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;notify&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="p"&gt;})&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Changes on the dependency
&lt;/h2&gt;

&lt;p&gt;Also, we need to remove the &lt;em&gt;getter&lt;/em&gt; and &lt;em&gt;setter&lt;/em&gt; from the dependency, since we do it now in the reactive state:&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Dep&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;subscribers&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;Set&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;depend&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="nx"&gt;activeEffect&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;subscribers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;activeEffect&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;notify&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;subscribers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;sub&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;p&gt;The &lt;code&gt;watchEffect&lt;/code&gt; function stays the same.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try out the code
&lt;/h2&gt;

&lt;p&gt;And we are already done with converting our dependency variable into a reactive state. Now we can try out the code:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;reactive&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Marc&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="nf"&gt;watchEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;👻 state changed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
    &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Johnny&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the console log you should see something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;👻 state changed 1 Marc
👻 state changed 2 Marc
👻 state changed 2 Johnny
👻 state changed 3 Johnny
👻 state changed 4 Johnny
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can find the complete code for the reactive state on 👉 &lt;a href="https://gist.github.com/themarcba/618264a12f277f10570c30759c592546"&gt;Github&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Summary ✨
&lt;/h1&gt;

&lt;p&gt;That's it for this part of the series. We did the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a dependency with a value inside, which notifies a subscribed function when the value changes&lt;/li&gt;
&lt;li&gt;Create a state where a subscribed function is called for the change of every value&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Original cover photo by &lt;a href="https://unsplash.com/@joshuaearle?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Joshua Earle&lt;/a&gt; on Unplash, edited by &lt;a href="https://marc.dev/"&gt;Marc Backes&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Create Your Own Vue.js From Scratch - Part 3 (Building The VDOM)</title>
      <dc:creator>Marc Backes</dc:creator>
      <pubDate>Sun, 29 Mar 2020 10:29:44 +0000</pubDate>
      <link>https://dev.to/themarcba/create-your-own-vue-js-from-scratch-part-2-building-the-vdom-3bp2</link>
      <guid>https://dev.to/themarcba/create-your-own-vue-js-from-scratch-part-2-building-the-vdom-3bp2</guid>
      <description>&lt;p&gt;Create Your Own Vue.js From Scratch - Part 3 (Building The VDOM)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you like this article, chances are you'd like what I tweet as well. If you are curious, have a look at my &lt;a href="https://twitter.com/_marcba"&gt;Twitter profile&lt;/a&gt;. 🚀&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This is this third part of a series called &lt;em&gt;Create Your Own Vue.js From Scratch&lt;/em&gt;, where I teach you how to create the fundamentals of a reactive framework such as Vue.js. To follow this blog post, I suggest you read about the &lt;a href="https://marc.dev/blog/vue-from-scratch-part-1"&gt;first&lt;/a&gt; and &lt;a href="https://marc.dev/blog/vue-from-scratch-part-2"&gt;second&lt;/a&gt; part of this series.&lt;/p&gt;

&lt;p&gt;This post might be long at first, but probably not as technical as it looks like. It describe every step of the code, that's why it looks pretty complicated. But bear with me, all of this will make perfect sense at the end 😊&lt;/p&gt;

&lt;h1&gt;
  
  
  Roadmap 🚘
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://marc.dev/blog/vue-from-scratch-part-1"&gt;Introduction&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://marc.dev/blog/vue-from-scratch-part-2"&gt;Virtual DOM basics&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Implementing the virtual DOM &amp;amp; rendering (this post)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/_marcba/create-your-own-vue-js-from-scratch-part-3-building-the-reactivity-5162"&gt;Building reactivity&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/_marcba/create-your-own-vue-js-from-scratch-part-5-bringing-it-all-together-4eb3"&gt;Bringing it all together&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Building the Virtual DOM
&lt;/h1&gt;

&lt;h2&gt;
  
  
  The skeleton
&lt;/h2&gt;

&lt;p&gt;In the &lt;a href="https://marc.dev/blog/vue-from-scratch-part-2"&gt;second part of this series&lt;/a&gt;, we learned about the basics of how the virtual DOM works. You copy the VDOM skeleton from the last point from &lt;a href="https://gist.github.com/themarcba/2a471e1f0592201fc5036cb40bdbee1f"&gt;this gist&lt;/a&gt;. We use that code to follow along. You'll also find there the finished version of the VDOM engine. I also created a &lt;a href="https://codepen.io/_marcba/pen/qBdLeqj"&gt;Codepen&lt;/a&gt;, where you can play around with it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a virtual node
&lt;/h2&gt;

&lt;p&gt;So, to create a virtual node, we need the &lt;strong&gt;tag&lt;/strong&gt;, &lt;strong&gt;properties&lt;/strong&gt;, and &lt;strong&gt;children&lt;/strong&gt;. So, our function looks something like this:&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;children&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;p&gt;&lt;strong&gt;(In Vue, the function for creating virtual nodes is named &lt;code&gt;h&lt;/code&gt;, so that's how we're going to call it here.)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this function, we need a JavaScript object of the following structure.&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="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;div&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;class&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;container&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="nx"&gt;children&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;p&gt;To achieve this, we need to wrap the tag, properties, and child nodes parameters in an object and return it:&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;children&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="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nx"&gt;children&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;p&gt;That's it already for the virtual node creation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mount a virtual node to the DOM
&lt;/h2&gt;

&lt;p&gt;What I mean with &lt;em&gt;mount&lt;/em&gt; the virtual node to the DOM is, appending it to any given container. This node can be the original container (in our example, the &lt;code&gt;#app&lt;/code&gt;-div) or another virtual node where it will be mounted on (for example, mountaing a &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt; inside a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;This will be a recursive function, because we will have to walk through all of the nodes' children and &lt;em&gt;mount&lt;/em&gt; the to the respective containers.&lt;/p&gt;

&lt;p&gt;Our &lt;code&gt;mount&lt;/code&gt; function will look like this:&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;mount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vnode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;container&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  1) We need to create a DOM element
&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;const&lt;/span&gt; &lt;span class="nx"&gt;el&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vnode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;el&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;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vnode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2) We need to set the properties (&lt;code&gt;props&lt;/code&gt;) as attributes to the DOM element:
&lt;/h3&gt;

&lt;p&gt;We do this by iterating over them, like such:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (const key in vnode.props) {
    el.setAttribute(key, vnode.props[key])
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3) We need to mount the children inside the element
&lt;/h3&gt;

&lt;p&gt;Remember, there are two types of children:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  A simple text&lt;/li&gt;
&lt;li&gt;  An array of virtual nodes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We handle both:&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="c1"&gt;// Children is a string/text&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;typeof&lt;/span&gt; &lt;span class="nx"&gt;vnode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&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="nx"&gt;el&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="nx"&gt;vnode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Chilren are virtual nodes&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;vnode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;child&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;mount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;child&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Recursively mount the children&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;As you can see in the second part of this code, the children are being mounted with the same &lt;code&gt;mount&lt;/code&gt; function. This continues recursively until there are only "text nodes" left. Then the recursion stops.&lt;/p&gt;

&lt;h3&gt;
  
  
  As the last part of this mounting function, we need to add the created DOM element to the respective container:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;container&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;el&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Unmount a virtual node from the DOM
&lt;/h2&gt;

&lt;p&gt;In the &lt;code&gt;unmount&lt;/code&gt; function, we remove a given virtual node from its parent in the real DOM. The function only takes the virtual node as a parameter.&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;unmount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vnode&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;vnode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;parentNode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vnode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;el&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;
  
  
  Patch a virtual node
&lt;/h2&gt;

&lt;p&gt;This means taking two virtual nodes, compare them, and figure out what's the difference between them.&lt;/p&gt;

&lt;p&gt;This is by far the most extensive function we'll write for the virtual DOM, but bear with me.&lt;/p&gt;

&lt;h3&gt;
  
  
  1) Assign the DOM element we will work with
&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;const&lt;/span&gt; &lt;span class="nx"&gt;el&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;n1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2) Check if the nodes are of different tags
&lt;/h3&gt;

&lt;p&gt;If the nodes are of different tags, we can assume that the content is entirely different, and we'd just replace the node entirely. We do this by mounting the new node and unmounting the old one.&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;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tag&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;n2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Replace node&lt;/span&gt;
    &lt;span class="nf"&gt;mount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;parentNode&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;unmount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Nodes have different tags&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the nodes are of the same tags; however, it can mean two different things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The new node has string children&lt;/li&gt;
&lt;li&gt;  The new node has an array of children&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3) Case where a node has string children
&lt;/h3&gt;

&lt;p&gt;In this case, we just go ahead and replace the &lt;code&gt;textContent&lt;/code&gt; of the element with the "children" (which in reality is just a string).&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="p"&gt;...&lt;/span&gt;
    &lt;span class="c1"&gt;// Nodes have different tags&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;typeof&lt;/span&gt; &lt;span class="nx"&gt;n2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&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="nx"&gt;el&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="nx"&gt;n2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&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;h3&gt;
  
  
  4) If the node has an array of children
&lt;/h3&gt;

&lt;p&gt;In this case, we have to check the differences between the children. There are three scenarios:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The length of the children is the same&lt;/li&gt;
&lt;li&gt;  The old node has more children than the new node. In this case, we need to remove the "exceed" children from the DOM&lt;/li&gt;
&lt;li&gt;  The new node has more children than the old node. In this case, we need to add additional children to the DOM.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So first, we need to determine the &lt;em&gt;common length&lt;/em&gt; of children, or in other terms, the minimal of the children count each of the nodes have:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;c1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;n1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;c2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;n2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;commonLength&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;c1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;c2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5) Patch common children
&lt;/h3&gt;

&lt;p&gt;For each of the cases from point &lt;code&gt;4)&lt;/code&gt;, we need to &lt;code&gt;patch&lt;/code&gt; the children that the nodes have in common:&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;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&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="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;commonLength&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&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;patch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;c1&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;c2&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&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;In the case where the lengths are equal, this is already it. There is nothing left to do.&lt;/p&gt;

&lt;h3&gt;
  
  
  6) Remove unneeded children from the DOM
&lt;/h3&gt;

&lt;p&gt;If the new node has fewer children than the old node, these need to be removed from the DOM. We already wrote the &lt;code&gt;unmount&lt;/code&gt; function for this, so now we need to iterate through the extra children and unmount them:&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;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;c1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;c2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;c1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;c2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;child&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;unmount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;child&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;h3&gt;
  
  
  7) Add additional children to the DOM
&lt;/h3&gt;

&lt;p&gt;If the new node has more children than the old node, we need to add those to the DOM. We also already wrote the &lt;code&gt;mount&lt;/code&gt; function for that. We now need to iterate through the additional children and mount them:&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;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;c2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;c1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;c2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;c1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;child&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;mount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;child&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;el&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;p&gt;&lt;em&gt;That's it. We found every difference between the nodes and corrected the DOM accordingly. What this solution does not implement though, is the patching of properties. It would make the blog post even longer and would miss the point.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Rendering a virtual tree in the real DOM
&lt;/h2&gt;

&lt;p&gt;Our virtual DOM engine is ready now. To demonstrate it, we can create some nodes and render them. Let's assume we want the following HTML structure:&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;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello World 🌍&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Thanks for reading the marc.dev blog 😊&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  1) Create the virtual node with &lt;code&gt;h&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;const&lt;/span&gt; &lt;span class="nx"&gt;node1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;div&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="na"&gt;class&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;container&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="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;div&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;X&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;span&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;span&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;world&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2) Mount the node to the DOM
&lt;/h3&gt;

&lt;p&gt;We want to mount the newly created DOM. Where? To the &lt;code&gt;#app&lt;/code&gt;-div at the very top of the file:&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="nf"&gt;mount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;node1&lt;/span&gt;&lt;span class="p"&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="s1"&gt;app&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;The result should look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="//images.ctfassets.net/r1crnaxclhxs/7JWFiBn6qnHcUeYgjlFYzG/eb0b07c5a5af563a3d90406a976feeb3/Screenshot_2020-03-29_at_11.02.34.png" class="article-body-image-wrapper"&gt;&lt;img src="//images.ctfassets.net/r1crnaxclhxs/7JWFiBn6qnHcUeYgjlFYzG/eb0b07c5a5af563a3d90406a976feeb3/Screenshot_2020-03-29_at_11.02.34.png" alt="VDOM Demo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3) Create a second virtual node
&lt;/h3&gt;

&lt;p&gt;Now, we can create a second node with some changes in it. Let's add a few nodes so that the result will be this:&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;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello Dev 💻&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&amp;lt;span&amp;gt;&lt;/span&gt;Thanks for reading the &lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://marc.dev"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;marc.dev&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;span&amp;gt;&lt;/span&gt; blog&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://media.giphy.com/media/26gsjCZpPolPr3sBy/giphy.gif"&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"width: 350px; border-radius: 0.5rem;"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the code for creating that node:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;node2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;div&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="na"&gt;class&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;container&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="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;h1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello Dev 💻&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;p&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;span&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Thanks for reading the &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;a&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="na"&gt;href&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://marc.dev&lt;/span&gt;&lt;span class="dl"&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;marc.dev&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;span&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; blog&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="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;img&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="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://media.giphy.com/media/26gsjCZpPolPr3sBy/giphy.gif&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;width: 350px; border-radius: 0.5rem;&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="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;p&gt;As you can see, we added some nodes, and also changed a node.&lt;/p&gt;

&lt;h3&gt;
  
  
  4) Render the second node
&lt;/h3&gt;

&lt;p&gt;We want to replace the first node with the second one, so we don't use &lt;code&gt;mount&lt;/code&gt;. What we want to do is to find out the difference between the two, make changes, and then render it. So we &lt;code&gt;patch&lt;/code&gt; it:&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="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;patch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;node1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;node2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;I added a timeout here, so you can see the code DOM changing. If not, you would only see the new VDOM rendered.&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;p&gt;That's it! We have a very basic version of a DOM engine which lets us:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create virtual nodes&lt;/li&gt;
&lt;li&gt;Mount virtual nodes to the DOM&lt;/li&gt;
&lt;li&gt;Remove virtual nodes from the DOM&lt;/li&gt;
&lt;li&gt;Find differences between two virtual nodes and update the DOM accordingly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can find the code we did in this post, on a &lt;a href="https://gist.github.com/themarcba/2a471e1f0592201fc5036cb40bdbee1f"&gt;Github Gist I prepared for you&lt;/a&gt;. If you just want to play around with it, I also created a &lt;a href="https://codepen.io/_marcba/pen/qBdLeqj"&gt;Codepen&lt;/a&gt;, so you can do that.&lt;/p&gt;

&lt;p&gt;If you have any more questions about this, feel free to reach out to me via &lt;a href="https://www.twitter.com/_marcba"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Original cover photo by &lt;a href="https://unsplash.com/@joshuaearle?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Joshua Earle&lt;/a&gt; on Unplash, edited by &lt;a href="https://marc.dev/"&gt;Marc Backes&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
    </item>
    <item>
      <title>7 Essential Tips for Working From Home</title>
      <dc:creator>Marc Backes</dc:creator>
      <pubDate>Wed, 18 Mar 2020 12:01:07 +0000</pubDate>
      <link>https://dev.to/themarcba/7-essential-tips-for-working-from-home-4ob2</link>
      <guid>https://dev.to/themarcba/7-essential-tips-for-working-from-home-4ob2</guid>
      <description>&lt;p&gt;Due to the &lt;em&gt;Covid-19&lt;/em&gt; pandemic, many people had to switch to remote work in a short time. This can be a significant change for people not prepared for it, or even not wanting it. I have more than a year of experience working entirely remotely, just visiting my clients once in a while on-site. In this post, I will show you 7 essential tips for working remotely.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Disclaimer: These are my personal tips. Not all of this might be "for you," or you find better ways to achieve a great experience working from home. There are many more ways of doing it. But this is an excellent way to get started.&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  1. Have a dedicated working space 🖥
&lt;/h1&gt;

&lt;p&gt;Probably the most essential thing of all when it comes to working remotely is having a dedicated working space. It would be best if you had a place that is only designated to work. If you don't have a room for that, create a space that is for work only. There should be the least amount of distraction possible in this place.&lt;/p&gt;

&lt;p&gt;Having your own working space will help you to separate work and your personal life and is right for your mental health. Once you leave this space, you're off the clock.&lt;/p&gt;

&lt;p&gt;This goes both ways: If you were to work from your living room, there would be a high chance you could be distracted by other people living with you, or tempted to swoop in some household chores while you're actually still "on the clock."&lt;/p&gt;

&lt;h1&gt;
  
  
  2. Make your working place comfortable ☀️
&lt;/h1&gt;

&lt;p&gt;Now that you have a dedicated space make it as comfortable as possible. It should be free of clutter, and enough natural light should enter.&lt;/p&gt;

&lt;p&gt;Also, decorate it in a way that you feel comfortable working with.&lt;/p&gt;

&lt;p&gt;Having proper equipment (screen, chair, desk, etc.) helps to make work from home great. You most likely can make your home office even better than your regular office.&lt;/p&gt;

&lt;h1&gt;
  
  
  3. Create boundaries with people around you 🚦
&lt;/h1&gt;

&lt;p&gt;Whether if it's your partner, your children, or your roommates. Have a sit-down with them and explain that it's essential that the time you are in your working space, you don't want to be disturbed. Some people have a hard time grasping the concept of "working from home," so it's well invested time explaining to them what you do and why you don't need to be physically in an office.&lt;/p&gt;

&lt;h1&gt;
  
  
  4. Dress as if you were going to the office 👔
&lt;/h1&gt;

&lt;p&gt;Many people (even including myself some days) tend to work in their pajamas. While this might feel nice, it could distract you from the fact that it's not a lazy Sunday, but an actual workday. You don't have to take it to the extreme and put on a tie and suit, but shower, clean yourself up and put on clothes.&lt;/p&gt;

&lt;p&gt;You will feel better about yourself if you work all cleaned up.&lt;/p&gt;

&lt;h1&gt;
  
  
  5. Maintain regular work hours ⏰
&lt;/h1&gt;

&lt;p&gt;A fantastic advantage of working from home is that you &lt;em&gt;could&lt;/em&gt; be working at the times you prefer. And if it's okay with your employer or clients, you can work at the hours you want. But it's essential to set a schedule and stick to it. Also, this gives you a better work-life balance.&lt;/p&gt;

&lt;p&gt;However, you can be a bit flexible about this, if needed. After all, having flexible hours is one of the most significant advantages of working remotely. If, for instance, you finish up something and make "overtime" because of it, make sure to recompensate those hours by sleeping longer the next day or calling it a day earlier another day. This all of course, if it's alright with your employer.&lt;/p&gt;

&lt;h1&gt;
  
  
  6. Schedule your breaks ☕️
&lt;/h1&gt;

&lt;p&gt;When working at home, it's easy to forget about time or get obsessed with the work you currently do. Make sure to schedule regular breaks - and stick to them.&lt;/p&gt;

&lt;p&gt;A great way to schedule your breaks (and working hours) is the &lt;a href="https://lifehacker.com/productivity-101-a-primer-to-the-pomodoro-technique-1598992730"&gt;Pomodoro Technique&lt;/a&gt;. Not only makes it sure you comply, but it also makes your working times more productive. There are various "Pomodoro timers" available online that help you stick to the schedule.&lt;/p&gt;

&lt;h1&gt;
  
  
  7. Create a morning- and after-work routing 📄
&lt;/h1&gt;

&lt;p&gt;To get into the mindset of working, it helps if you have a routine that gets you started instead of "just deciding to sit down and get some work done." This could be as easy as preparing a cup of your favorite hot beverage, getting dressed, going for a walk with your dog. A little routine that signalizes that you are about to work.&lt;/p&gt;

&lt;p&gt;As important as a morning routine is an after-work routine. Going for an evening walk with your dog, watch your favorite news channel, sign off from Slack. Be consistent about it. It will get you in the "off work" set of mind.&lt;/p&gt;

&lt;h1&gt;
  
  
  Summary ✨
&lt;/h1&gt;

&lt;p&gt;There you have it, my six essential tips for working from home. Most are designed to keep a healthy attitude about the whole thing and train your mind to separate work from your personal life.&lt;/p&gt;

&lt;p&gt;I hope some of this helps you get comfortable with your work from home experience.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Photo by &lt;a href="https://unsplash.com/@markusspiske?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Markus Spiske&lt;/a&gt; on Unsplash&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Create Your Own Vue.js From Scratch - Part 2 (Virtual DOM Basics)</title>
      <dc:creator>Marc Backes</dc:creator>
      <pubDate>Mon, 16 Mar 2020 10:20:40 +0000</pubDate>
      <link>https://dev.to/themarcba/create-your-own-vue-js-from-scratch-part-2-virtual-dom-basics-58fm</link>
      <guid>https://dev.to/themarcba/create-your-own-vue-js-from-scratch-part-2-virtual-dom-basics-58fm</guid>
      <description>&lt;p&gt;This is the second part of a series called &lt;em&gt;Create Your Own Vue.js From Scratch&lt;/em&gt;, where I teach you how to create the fundamentals of a reactive framework such as Vue.js. In the &lt;a href="https://dev.to/_marcba/coding-a-vue-js-like-framework-from-scratch-part-1-introduction-3nbf"&gt;first part&lt;/a&gt;, I described the pieces we need and the road map to follow. If you haven't read it, I suggest you do that before reading this post.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I only have 1 year of professional experience working with Vue.js, but I attended an 8-hour course given by &lt;a href="https://evanyou.me/"&gt;Evan You&lt;/a&gt; himself (as part of &lt;a href="https://vuejs.amsterdam/"&gt;Vue.js Amsterdam&lt;/a&gt; where I learned how Vue.js works on the inside and made me really understand how the "magic" behind the scenes works. This blog series is meant to teach everyone who is interested what I learned on that fantastic workshop, &lt;strong&gt;in a comprehensive way&lt;/strong&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Roadmap 🚘
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/_marcba/coding-a-vue-js-like-framework-from-scratch-part-1-introduction-3nbf"&gt;Introduction&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Virtual DOM basics (this post)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/_marcba/create-your-own-vue-js-from-scratch-part-2-building-the-vdom-3bp2"&gt;Implementing the virtual DOM &amp;amp; rendering&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/_marcba/create-your-own-vue-js-from-scratch-part-3-building-the-reactivity-5162"&gt;Building reactivity&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/_marcba/create-your-own-vue-js-from-scratch-part-5-bringing-it-all-together-4eb3"&gt;Bringing it all together&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  What is a virtual DOM?
&lt;/h1&gt;

&lt;p&gt;💡 DOM = &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model"&gt;Document Object Model&lt;/a&gt;, the HTML structure of a website 💡 VDOM = Representative copy of that structure&lt;/p&gt;

&lt;p&gt;A &lt;em&gt;virtual&lt;/em&gt; DOM is a representation of the real DOM into a JavaScript format, where it's easier and cheaper to manipulate it than manipulating the real DOM every time something changes.&lt;/p&gt;

&lt;p&gt;It's also useful if you don't want to render the DOm to the browser, but to a string for instance (handy when it comes to server-side rendering).&lt;/p&gt;

&lt;h1&gt;
  
  
  Virtual nodes
&lt;/h1&gt;

&lt;p&gt;So, the virtual DOM is composed of &lt;em&gt;virtual nodes&lt;/em&gt;, which in the example we're going to code will look something like this:&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="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;div&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;class&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;container&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="nx"&gt;children&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="na"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;h1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt;
            &lt;span class="na"&gt;children&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello World&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="na"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;p&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt;
            &lt;span class="na"&gt;children&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Lorem ipsum dolor sit amet.&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The example above is the equivalent to this HTML code:&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;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello World&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Lorem ipsum dolor sit amet.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So all a virtual node is composed of is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  An HTML tag as &lt;em&gt;String&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;  An &lt;em&gt;Object&lt;/em&gt; of properties&lt;/li&gt;
&lt;li&gt;  A list of children than can either be:

&lt;ul&gt;
&lt;li&gt;  Another node&lt;/li&gt;
&lt;li&gt;  A text (representing the content)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Virtual DOM skeleton
&lt;/h1&gt;

&lt;p&gt;In our example, we will not build a full-fledged virtual DOM &lt;em&gt;"engine"&lt;/em&gt;, but enough to understand the basics.&lt;/p&gt;

&lt;p&gt;Let's take a look at the coding of the virtual DOM. We will base all future code on the following lines. So, create an HTML-file with the following content:&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;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/app&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;

    &lt;span class="c1"&gt;// Create virtual node&lt;/span&gt;
    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;h&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tag&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Return the virtual node&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Mount a virtual node to the DOM&lt;/span&gt;
    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;mount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vnode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Create the element&lt;/span&gt;
        &lt;span class="c1"&gt;// Set props&lt;/span&gt;
        &lt;span class="c1"&gt;// Handle children&lt;/span&gt;
        &lt;span class="c1"&gt;// Mount to the DOM&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Unmount a virtual node from the DOM&lt;/span&gt;
    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;unmount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vnode&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Unmount the virtual node&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Take 2 vnodes, compare &amp;amp; figure out what's the difference&lt;/span&gt;
    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;patch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;n2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Case where the nodes are of the same tag&lt;/span&gt;
        &lt;span class="c1"&gt;// Case where the new vnode has string children&lt;/span&gt;
        &lt;span class="c1"&gt;// Case where the new vnode has an array of vnodes&lt;/span&gt;
        &lt;span class="c1"&gt;// Case where the nodes are of different tags&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Render a virtual node with a given message&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Create virtual nodes &amp;amp; render them below this line...&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, we have five different functions which all do their part to create and render a virtual DOM:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;h&lt;/code&gt; creates a virtual node (but does not mount it yet to the real DOM). I called this &lt;code&gt;h&lt;/code&gt;, because that's how it is called in the Vue.js project as well&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;mount&lt;/code&gt; will take a given virtual node and mount it to a given container in the real DOM. For the first element, this will be the &lt;code&gt;#app&lt;/code&gt; node we created at the very top of the file.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;unmount&lt;/code&gt; will remove the virtual node from it's parent node&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;patch&lt;/code&gt; is by far the biggest function we will write for the VDOM. This is, because we have to compare two different nodes and check all the differences in a recursive manner (doing it for all the children recursively).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;render&lt;/code&gt; is a simplified version of a render function. In our example, it creates various virtual nodes with a given the message inside (which we later change to demonstrate our VDOM &lt;em&gt;"engine"&lt;/em&gt; works.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What's next ⚡️
&lt;/h2&gt;

&lt;p&gt;In part 1, we saw the building parts we'll need for building our own Vue.js-like framework and in this part, we saw the basics of how we are going to build the virtual dom.&lt;/p&gt;

&lt;p&gt;In the next chapter, we will then actually implement the complete virtual DOM part.&lt;/p&gt;

&lt;p&gt;Stay tuned 😉&lt;/p&gt;

&lt;p&gt;If you like my content and updates, your best bet would be to follow me on Twitter. That's where I usually hang out under the handle &lt;a href="https://twitter.com/_marcba/"&gt;@_marcba&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Original cover photo by &lt;a href="https://unsplash.com/@joshuaearle?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Joshua Earle&lt;/a&gt; on Unplash, edited by &lt;a href="https://marc.dev/"&gt;Marc Backes&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Create Your Own Vue.js From Scratch - Part 1 (Introduction)</title>
      <dc:creator>Marc Backes</dc:creator>
      <pubDate>Sun, 08 Mar 2020 14:29:25 +0000</pubDate>
      <link>https://dev.to/themarcba/coding-a-vue-js-like-framework-from-scratch-part-1-introduction-3nbf</link>
      <guid>https://dev.to/themarcba/coding-a-vue-js-like-framework-from-scratch-part-1-introduction-3nbf</guid>
      <description>&lt;p&gt;A lot of developers see these reactive frameworks such as Vue.js, React.js, Angular.js as "magic" since they do - well as it seems magic. But that's not the case. In fact, recreating Vue-like functionality is not all that difficult, and I want to prove it to you in this series where we create &lt;strong&gt;step-by-step a reactive framework&lt;/strong&gt; (or at least a prototype of it), similar to how Vue 2 works in the inside.&lt;/p&gt;

&lt;p&gt;I only have 1 year of professional experience working with Vue.js, but I attended an 8-hour course given by &lt;a href="https://evanyou.me/"&gt;Evan You&lt;/a&gt; himself (as part of &lt;a href="https://vuejs.amsterdam/"&gt;Vue.js Amsterdam&lt;/a&gt; where I learned how Vue.js works on the inside and made me really understand how the "magic" behind the scenes works. This blog series is meant to teach everyone who is interested what I learned on that fantastic workshop, &lt;strong&gt;in a comprehensive way&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Roadmap 🚘
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introduction (this post)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/_marcba/create-your-own-vue-js-from-scratch-part-2-virtual-dom-basics-58fm"&gt;Virtual DOM basics&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/_marcba/create-your-own-vue-js-from-scratch-part-2-building-the-vdom-3bp2"&gt;Implementing the virtual DOM &amp;amp; rendering&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/_marcba/create-your-own-vue-js-from-scratch-part-3-building-the-reactivity-5162"&gt;Building reactivity&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/_marcba/create-your-own-vue-js-from-scratch-part-5-bringing-it-all-together-4eb3"&gt;Bringing it all together&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The Pieces We Need 🧩
&lt;/h2&gt;

&lt;p&gt;In order to build our prototype, we actually just need &lt;strong&gt;two major&lt;/strong&gt; parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  A virtual DOM&lt;/li&gt;
&lt;li&gt;  Reactivity&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Virtual DOM
&lt;/h3&gt;

&lt;p&gt;💡 DOM = &lt;em&gt;Document Object Model&lt;/em&gt;, the HTML structure of a website&lt;br&gt;
💡 VDOM = Representative copy of that structure&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In a gist, a virtual DOM (&lt;em&gt;VDOM&lt;/em&gt;) is lightweight JavaScript data format to represent what the actual DOM &lt;em&gt;should&lt;/em&gt; look like at a given point in time.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It is meant to &lt;strong&gt;decouple the rendering logic&lt;/strong&gt; from the actual DOM. This is helpful to reuse it in non-browser contexts (think about server-side rendering for example).&lt;/p&gt;

&lt;p&gt;Also, having a VDOM makes &lt;strong&gt;updating the UI more performant&lt;/strong&gt;. You can manipulate the virtual DOM with the full power of JavaScript (create nodes, clone nodes, inspect nodes, etc.) which is really fast and when you're finished with the manipulation, just update the elements in the actual DOM.&lt;/p&gt;

&lt;p&gt;In our little project, we'll create our own functionality to create a virtual DOM and how to render it to the actual DOM (renderer).&lt;/p&gt;

&lt;h3&gt;
  
  
  Reactivity
&lt;/h3&gt;

&lt;p&gt;Once we have our VDOM, we need to write our &lt;em&gt;reactivity&lt;/em&gt;. This is a set of functions and classes to &lt;strong&gt;have our system react to a state change&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So in simple terms, &lt;strong&gt;when the state changes, we get notified&lt;/strong&gt; so we can do &lt;em&gt;something&lt;/em&gt;. That something at the end is rendering the VDOM to the actual DOM. And that it where our experiment stops. It will be the proof-of-concept the our own tiny Vue.js&lt;/p&gt;

&lt;h2&gt;
  
  
  What follows ⚡️
&lt;/h2&gt;

&lt;p&gt;In the next couple of weeks I'll try to write a guide as comprehensive as possible so you can get a good grasp on what the &lt;em&gt;magic&lt;/em&gt; of Vue.js is actually about. Once you understand what's going on under the hood, you'll definitely have a better time understanding the framework as a whole.&lt;/p&gt;

&lt;p&gt;Stay tuned 😉&lt;/p&gt;

&lt;p&gt;If you like my content and updates, your best bet would be to follow me on Twitter. That's where I usually hang out under the handle &lt;a href="https://twitter.com/_marcba/"&gt;@_marcba&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Original cover photo by &lt;a href="https://unsplash.com/@joshuaearle?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Joshua Earle&lt;/a&gt; on Unplash, edited by &lt;a href="https://marc.dev/"&gt;Marc Backes&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Vue.js Amsterdam 2020 Recap</title>
      <dc:creator>Marc Backes</dc:creator>
      <pubDate>Thu, 27 Feb 2020 18:55:15 +0000</pubDate>
      <link>https://dev.to/themarcba/vue-js-amsterdam-2020-recap-1141</link>
      <guid>https://dev.to/themarcba/vue-js-amsterdam-2020-recap-1141</guid>
      <description>&lt;p&gt;From the &lt;strong&gt;&lt;em&gt;20th to the 22nd of February 2020&lt;/em&gt;&lt;/strong&gt; I went to the biggest Vue.js conference in the world - &lt;strong&gt;Vue.js Amsterdam&lt;/strong&gt;. The three days have been fantastic, filled with lots of adventure, knowledge and getting to know amazing people. In this post I'll talk about the talks and a little bit about my personal experience.&lt;/p&gt;

&lt;h1&gt;
  
  
  The experience 🤩
&lt;/h1&gt;

&lt;p&gt;When I signed up for the event, I didn't know much about it, so I didn't expect much. When I entered, it was a pleasant athmosphere. Everyone talking tech, donuts, coffee, and everyone eager to get started. Cool.&lt;/p&gt;

&lt;p&gt;But when I entered the seating area, I was in awe at once. The most gigantic screen I have ever seen. Seriously. I don't think even Apple has these to introduce their new products to the public.&lt;/p&gt;

&lt;p&gt;Every time someone got on stage, they played a song chosen by the speaker, which was a nice touch.&lt;/p&gt;

&lt;h1&gt;
  
  
  The speakers 👩‍💻👨‍💻
&lt;/h1&gt;

&lt;p&gt;This conference had an amazing lineup. The &lt;em&gt;crème de la crème&lt;/em&gt; of the Vue.js world was there. Of course, there was Evan You, the creator of Vue.js himself. But the house was filled with either core team members or otherwise important people of the Vue world. Trust me, it was wild. Just to mention only a few incredible speakers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Thorsten Lünborg, Vue.js core team member&lt;/li&gt;
&lt;li&gt;  Sarah Drasner, Vue.js core team member, VP of developer experience at Netlify&lt;/li&gt;
&lt;li&gt;  Thorsten Lünborg, Vue.js core team member&lt;/li&gt;
&lt;li&gt;  Eduardo San Martin Morote, Vue.js core team member, vue-router&lt;/li&gt;
&lt;li&gt;  Pooya Parsa, Nuxt.js core team&lt;/li&gt;
&lt;li&gt;  Sébastien Chopin, Nuxt.js author&lt;/li&gt;
&lt;li&gt;  Gregg Pollack, &lt;a href="https://www.vuemastery.com/"&gt;Vue Mastery&lt;/a&gt;. (Fun fact: With his course for Ruby on Rails I started getting into web development in the first place.)&lt;/li&gt;
&lt;li&gt;  Jessica Sachs, Vue.js Test Utils maintainer&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  The talks 🎙
&lt;/h1&gt;

&lt;p&gt;All the talks, without exception was amzing. You can check the complete programme on the &lt;a href="https://vuejs.amsterdam/program"&gt;website of Vue.js Amsterdam&lt;/a&gt;. But here are some takeaways from those talks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Vue.js 3 is coming soon
&lt;/h2&gt;

&lt;p&gt;Everyone has been waiting for it for a long time. And people are eager to get their hands on it. Evan You explained that they are very close to the beta version. In fact, he said that &lt;strong&gt;most definitely&lt;/strong&gt; it will be out by the end of Q1. He also said that the final version would probably be out by the end of Q2.&lt;/p&gt;

&lt;p&gt;The most significant changes in the new version will be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Composition API&lt;/strong&gt;. The Vue-pendant to React hooks. THE feature everyone is waiting for.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Portals&lt;/strong&gt;. Render certain content outside the current component.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Fragments&lt;/strong&gt;. Allows multiple root nodes.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Updated &lt;code&gt;v-model&lt;/code&gt;-API&lt;/strong&gt;. It now accepts multiple models.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Suspense&lt;/strong&gt;. Mostly for UX stuff. Waits to render multiple components, until all are ready. Shows a fallback-component until ready.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;TypeScript&lt;/strong&gt;. Vue now has full TypeScript support.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Vue.js is heading towards the next era with Vue 3
&lt;/h2&gt;

&lt;p&gt;Evan You also talked about the current state of development of Vue.js. It's very close to completion. Most of the work that is yet to do are tests, benchmarks, optimizations, and some renaming.&lt;/p&gt;

&lt;p&gt;What I really found amazing is that the whole ecosystem is going &lt;strong&gt;ALL-IN&lt;/strong&gt; with Vue 3. There are several projects that made major or entire rewrites of their code to take advantage of the newest features of Vue 3. When the maintainers of Vue, Nuxt, Vuelidate, Vuetify, etc. talked, I really got the perception that they all worked very closely together to really bring the whole Vue ecosystem to a new era. So, brace yourselves, because I really think Vue 3 will be a huge success.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use more SVG
&lt;/h2&gt;

&lt;p&gt;A talk by &lt;a href="https://twitter.com/dimshik100"&gt;Dima Vishnevetsky&lt;/a&gt; really sensibilized me for using more SVGs. He for example had some interesting examples of micro interactions with SVG on input fields, showed that cool animations can be done, and reminded everyone that SVG is such a slim format with so much power. He also pointed out that SVGs are great for Vue.js, because they can be built easily with a component.&lt;/p&gt;

&lt;p&gt;What I for exmaple didn't know is that SVG has media query support. Which means, you can create one single logo file in SVG, and depending on the size displayed, the logo looks different (squared). Check out &lt;a href="https://slides.com/dimshik/scalable-vue-graphics-for-the-modern-web"&gt;the slides of his talk&lt;/a&gt; to see some great examples of SVG.&lt;/p&gt;

&lt;p&gt;Main takeaway from his talk: Ask youself if it could be done in SVG. If yes... do it in SVG!&lt;/p&gt;

&lt;h2&gt;
  
  
  Climate change is also the responsability of developers
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://twitter.com/callumacrae"&gt;Callum Macrae&lt;/a&gt; had a &lt;a href="https://speakerdeck.com/callumacrae/climate-change-and-the-tech-community"&gt;compelling talk&lt;/a&gt; about climate change and how it affects all of us. To be honest, at first it took everyone's mood way down after everyone's excitement about the talks before. Because all the facts he stated from a research made me think "We're doomed. We're all going to die". The situation of our planet is no joke and there are little steps we can do as developers to help reduce CO2 consumption.&lt;/p&gt;

&lt;p&gt;Where is a website called &lt;a href="https://www.websitecarbon.com"&gt;Website Carbon&lt;/a&gt; which analyzes your site and tells you how much CO2 one request to this websites generates. I was pretty happy with myself that my website is in the top 15% of the tested websites 💪. Callum pointed out that by creating more optimized websites in size and logic performance, we could actually make a difference.&lt;/p&gt;

&lt;p&gt;But he also mentioned that the biggest CO2 are the backends. The APIs that dig through a lot of data. Also here, the advice is to make as effective and performant code as possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  a11y is extremely important
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://twitter.com/MariaLamardo"&gt;Maria Lamardo&lt;/a&gt;, an instructor at &lt;a href="https://vueschool.io"&gt;vueschool.io&lt;/a&gt; showed based on a Memory game some interesting techniques to make like a lot easier for people who need screen readers. There are some neat techniques to optimize a website for screen readers. For example, you can create an invisible element where you write link changes for JS-powered websites that don't actually do a site load, but rather change content on the website with JavaScript instead. Also, &lt;code&gt;aria-label&lt;/code&gt; and &lt;code&gt;aria-descriptions&lt;/code&gt; go a long way!&lt;/p&gt;

&lt;p&gt;Check out her &lt;a href="https://docs.google.com/presentation/d/1IBygfnoKyGfKc--XtTCmP6NLzplUkBv1M_Yj8SmuGbE"&gt;amazing talk&lt;/a&gt; and the &lt;a href="https://github.com/mlama007/Vue-Memory-Game"&gt;repository&lt;/a&gt; that's going along with it.&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript Proxys are fun
&lt;/h2&gt;

&lt;p&gt;There is this thing called &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy"&gt;Proxy&lt;/a&gt; in JavaScript, which is something I didn't know about and it turns out it's pretty darn interesting. Escpecially, because Vue.js 3 reactivity is built on proxies, as Evan You pointed out.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A proxy is an object that encases another object or function and allows you to intercept it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's how &lt;a href="https://twitter.com/sarah_edo"&gt;Sarah Drasner&lt;/a&gt;, VP of Developer Experience at &lt;a href="https://www.netlify.com"&gt;Netlify&lt;/a&gt; explained it, and she showed us how proxies work in &lt;a href="https://github.com/sdras/animated-guide-vue3/blob/master/reactivity-vue3.pdf"&gt;practical and understandable examples&lt;/a&gt;. It's something I will definitely take a look at and play with.&lt;/p&gt;

&lt;h2&gt;
  
  
  Vue Testing Utils
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://twitter.com/frontstuff_io"&gt;Sarah Dayan&lt;/a&gt; made a really comprehensive and fun live-coding session where she showed us how we can do TDD on Vue components with &lt;a href="https://vue-test-utils.vuejs.org/"&gt;Vue Test Utils&lt;/a&gt;. In &lt;a href="https://noti.st/sarahdayan/q0xtRN"&gt;her talk&lt;/a&gt; she explained the red-green-blue TDD strategy and explained reasons why it's important:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  TDD helps you write robust test. Not too many, not too few!&lt;/li&gt;
&lt;li&gt;  TDD encourages refactors which lead to better software design&lt;/li&gt;
&lt;li&gt;  Fixing bug is far more costy than preventing them&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;She also mentioned that it's more important to have tests than have an ultra-clean and maintainable code base. Because having tests in place gives you more confidence to go ahead and refactor some code.&lt;/p&gt;

&lt;p&gt;To the same topic, later that day &lt;a href="https://twitter.com/_JessicaSachs"&gt;Jessica Sachs&lt;/a&gt; gave a &lt;a href="https://slides.com/jessicasachs/vuetest-utils-in-2020"&gt;talk&lt;/a&gt; what VTU is and what's coming next. Among other things, they are preparing to support the Composition API (but will still work with Vue 2) and migrate TypeScript.&lt;/p&gt;

&lt;h1&gt;
  
  
  After-party 🕺
&lt;/h1&gt;

&lt;p&gt;You might think programmers are all geeks, but Evan You (and some others) showed us that the opposite is true. After all the talks finished, the Master of Ceremonies &lt;a href="https://twitter.com/shortdiv"&gt;Divya Sasidharan&lt;/a&gt; announced a special surprise, and boy - a surprise it was.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://twitter.com/youyuxi"&gt;Evan You&lt;/a&gt; and &lt;a href="https://twitter.com/lukevscostas"&gt;Luke Thomas&lt;/a&gt; got on stage and started rapping &lt;em&gt;Forgot About Dre&lt;/em&gt;. If you haven't seen it, &lt;a href="https://twitter.com/_marcba/status/1230911682416869383"&gt;check out the video I took if&lt;/a&gt;. They did it so great.&lt;/p&gt;

&lt;p&gt;The after-party was nice as well. I There was some more karaoke (featuring Evan You, &lt;a href="https://twitter.com/debs_obrien"&gt;Debbie O'Brien&lt;/a&gt;, &lt;a href="https://twitter.com/josgerards88"&gt;Jos Gerards&lt;/a&gt;, and others) and drinks. We all had a great time.&lt;/p&gt;

&lt;p&gt;I also got a chance to greet Evan You himself. I thanked him for this work in the community and told him a little about what I'm doing with Vue.js and he seemed genuinly happy that his work is improving so many people's lives.&lt;/p&gt;

&lt;p&gt;I even got him to pose for a photo with me 👇&lt;br&gt;
&lt;a href="//images.ctfassets.net/r1crnaxclhxs/7CsPjlR3lJk5X9IopKz5NQ/443843ff1ccdc98a8b860c166587f467/ERU3zdNWAAAKyTp.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="//images.ctfassets.net/r1crnaxclhxs/7CsPjlR3lJk5X9IopKz5NQ/443843ff1ccdc98a8b860c166587f467/ERU3zdNWAAAKyTp.jpeg" alt="Marc Backes and Evan You"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Workshop 🤓
&lt;/h1&gt;

&lt;p&gt;The day after the conference there was an optional workshop where Evan You take us to a deep dive with Vue 3.&lt;/p&gt;

&lt;p&gt;It was a quite intense workshop, because Evan was typing so fast and the topic at hand was quite complex to grasp in such a short time, but it was absolutely amazing. We built a tiny version of Vue.js (how it currently works in version 2) &lt;strong&gt;FROM SCRATCH&lt;/strong&gt;, which consisted of two parts: A renderer and the reactive part. Unfortunately we didn't get to build to compiler, that would have been fun as well.&lt;/p&gt;

&lt;p&gt;The second part of the workshop was to get familiarized with the Composition API, which is fascinating. It was so many use cases where it makes code more readable and better maintainable.&lt;/p&gt;

&lt;p&gt;The really cool part was that Evan was practically live coding for 8 hours without errors. That's amazing, because a lot of people fail in even a 5-minute live code. It was really impressive see the thought process that leads to the results Evan showed it.&lt;/p&gt;

&lt;p&gt;At the end, I even got him to sign my laptop 😁&lt;/p&gt;

&lt;h1&gt;
  
  
  Summary ✨
&lt;/h1&gt;

&lt;p&gt;I had such an amazing time at the conference and will for sure be participanting next year. Without exception, all talks were amazing. I met many great people, including my hero Gregg Pollack, and the master himself Evan You.&lt;/p&gt;

&lt;p&gt;If Jos, Nick, or someone else from the organization team is reading this: I just want to thank you for creating this insane event. I went in a Vue.js user, and I came out a Vue.js enthusiast!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Photo credit for cover photo: Vue.js Amsterdam&lt;/em&gt;&lt;/p&gt;

</description>
      <category>vue</category>
    </item>
    <item>
      <title>MineSweeper Game In Vanilla JavaScript</title>
      <dc:creator>Marc Backes</dc:creator>
      <pubDate>Wed, 12 Feb 2020 12:04:44 +0000</pubDate>
      <link>https://dev.to/themarcba/minesweeper-game-in-vanilla-javascript-dk8</link>
      <guid>https://dev.to/themarcba/minesweeper-game-in-vanilla-javascript-dk8</guid>
      <description>&lt;p&gt;I wanted to code a little game and I thought "why not MineSweeper", you remember, the old classic from Windows where as a kid we all didn't know how it worked? Yes, that one!&lt;/p&gt;

&lt;p&gt;Here is what it looks like:&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%2Fi%2Fut8p3wisgmwkyo1vh2uq.gif" 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%2Fi%2Fut8p3wisgmwkyo1vh2uq.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can play the demo here 👉 &lt;a href="https://minesweeper.marc.dev" rel="noopener noreferrer"&gt;MineSweeper Game Demo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And if you're interested how I coded this, I uploaded the code to &lt;a href="https://github.com/themarcba/minesweeper" rel="noopener noreferrer"&gt;Github&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>css</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
