<?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: Aiden Bai</title>
    <description>The latest articles on DEV Community by Aiden Bai (@aidenybai).</description>
    <link>https://dev.to/aidenybai</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%2F366159%2Fa2bc4615-adfb-4ffc-af19-c66890f60dd9.png</url>
      <title>DEV Community: Aiden Bai</title>
      <link>https://dev.to/aidenybai</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aidenybai"/>
    <language>en</language>
    <item>
      <title>Unleashing Million.js v2.0.0</title>
      <dc:creator>Aiden Bai</dc:creator>
      <pubDate>Fri, 10 Mar 2023 20:53:58 +0000</pubDate>
      <link>https://dev.to/aidenybai/unleashing-millionjs-v200-2f96</link>
      <guid>https://dev.to/aidenybai/unleashing-millionjs-v200-2f96</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://github.com/aidenybai/million" rel="noopener noreferrer"&gt;&lt;em&gt;An extremely fast virtual DOM that makes React up to 70% faster!&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the past 5 months, I've been gearing up for Million.js new direction: React, augmented with performance-improving utilities. In &lt;a href="https://dev.to/aidenybai/millionjs-100-release-3pna"&gt;v1.0.0&lt;/a&gt;, I announced that we would be embarking to replace React with a compiler--an ambitious goal with ambitious results.&lt;/p&gt;

&lt;p&gt;However, I've come to realize that replacing React shouldn't have been the goal--you lose the React ecosystem and the architecture is fragile to change.&lt;/p&gt;

&lt;p&gt;So today, I'm more than excited to announce a fully, ground-up rewritten version: &lt;strong&gt;Million.js v2.0.0&lt;/strong&gt;!&lt;/p&gt;

&lt;h2&gt;
  
  
  What's new?
&lt;/h2&gt;

&lt;p&gt;Million.js is up to &lt;strong&gt;&lt;em&gt;70% faster*&lt;/em&gt;&lt;/strong&gt; than React. But that's not all:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;⚛️ React.js compatibility&lt;/li&gt;
&lt;li&gt;🔼 Next.js compatibility&lt;/li&gt;
&lt;li&gt;🛠️ Opt-in optimizing compiler&lt;/li&gt;
&lt;li&gt;☑️ Internal Block virtual DOM&lt;/li&gt;
&lt;li&gt;💥Custom JSX runtime (for simple use cases)&lt;/li&gt;
&lt;/ul&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%2Fv7h0t4a1lumcsfmewm19.jpeg" 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%2Fv7h0t4a1lumcsfmewm19.jpeg" alt="Million.js is faster than other libraries in local JS Framework Benchmark"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;* &lt;a href="https://github.com/aidenybai/js-framework-benchmark" rel="noopener noreferrer"&gt;Local benchmark&lt;/a&gt; of JS Framework benchmark, PR currently pending.&lt;/p&gt;

&lt;p&gt;It's now super easy to integrate into any React app. Yep, it's literally just one function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;block&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;million/react&lt;/span&gt;&lt;span class="dl"&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;BigStatelessComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;test&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;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nc"&gt;Array&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;fill&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="nf"&gt;map&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;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// that's it! you can use it like a normal component now:&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;BigButFast&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;block&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;BigStatelessComponent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why Million?
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;(and not Preact, Inferno, Solid...)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;React "alternatives" like Preact and Inferno are awesome. They are great for building performant yet deeply interactive web apps, and even support &lt;a href="https://preactjs.com/guide/v10/switching-to-preact" rel="noopener noreferrer"&gt;some&lt;/a&gt; &lt;a href="https://www.npmjs.com/package/inferno-compat" rel="noopener noreferrer"&gt;compatibility&lt;/a&gt;. Libraries like Solid sport the best performance, and are the top-of-the-line options for building extremely fast web apps.&lt;/p&gt;

&lt;p&gt;However, these libraries can sometimes lack the things that make React great (namely the rich ecosystem, concurrent rendering, etc). Plus, most web apps don't need hyper optimized performance for their entire app, meaning migration to these tools is not always possible or necessary.&lt;/p&gt;

&lt;p&gt;Million.js takes a different approach. Instead of replacing React, it augments it with performance optimizations &lt;strong&gt;when you need it&lt;/strong&gt;. Million.js works out of the box, alongside your favorite metaframeworks (Next.js, Remix, etc.) and React libraries. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TL;DR: Don't replace React, augment it.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How does this work?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Million.js takes heavy inspiration from the work of &lt;a href="https://github.com/ged-odoo/blockdom" rel="noopener noreferrer"&gt;blockdom&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Million operates off of the concept of a block virtual DOM. Normally, virtual DOM's diff all of the nodes on a tree, which can become computationally expensive.&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%2Fxrupmk7bom4xsdrrpdrj.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%2Fxrupmk7bom4xsdrrpdrj.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Million's block tree requires much less updates, as nodes are grouped together into blocks.&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%2Fqqe4rghrfgl7eblbxz3c.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%2Fqqe4rghrfgl7eblbxz3c.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The React integration operates off of the same virtual DOM block core, but &lt;em&gt;does not&lt;/em&gt; need its own React reconciler. Rather, it mounts an &lt;a href="https://docs.astro.build/en/concepts/islands/" rel="noopener noreferrer"&gt;"island"&lt;/a&gt; into 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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;million&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;island&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="c"&gt;&amp;lt;!--&lt;/span&gt; &lt;span class="nx"&gt;block&lt;/span&gt; &lt;span class="nx"&gt;renders&lt;/span&gt; &lt;span class="nx"&gt;here&lt;/span&gt;&lt;span class="o"&gt;--&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/million-island&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I highly recommend reading over &lt;a href="https://github.com/ged-odoo/blockdom/blob/main/doc/performance_notes.md" rel="noopener noreferrer"&gt;blockdom's performance notes&lt;/a&gt; to understand why it's fast.&lt;/p&gt;

&lt;h2&gt;
  
  
  Acknowledgements
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/ged-odoo/blockdom" rel="noopener noreferrer"&gt;&lt;code&gt;blockdom&lt;/code&gt;&lt;/a&gt; (&lt;a href="https://github.com/ged-odoo" rel="noopener noreferrer"&gt;Géry Debongnie&lt;/a&gt;)&lt;br&gt;
Thank you to Géry pioneering the concept of "blocks" in the virtual DOM. Many parts of the Million.js codebase either directly or indirectly derive from his work.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/vobyjs/voby" rel="noopener noreferrer"&gt;&lt;code&gt;voby&lt;/code&gt;&lt;/a&gt; (&lt;a href="https://github.com/fabiospampinato" rel="noopener noreferrer"&gt;Fabio Spampinato&lt;/a&gt;)&lt;br&gt;
The Million.js "template" concept is derived from Voby's &lt;code&gt;template()&lt;/code&gt; API.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://bun.sh" rel="noopener noreferrer"&gt;&lt;code&gt;bun&lt;/code&gt;&lt;/a&gt; for their homepage. The Million.js homepage is a remix of what they have currently.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/localvoid/ivi" rel="noopener noreferrer"&gt;&lt;code&gt;ivi&lt;/code&gt;&lt;/a&gt;, &lt;a href="https://github.com/preactjs/preact" rel="noopener noreferrer"&gt;Preact&lt;/a&gt;, &lt;a href="https://krausest.github.io/js-framework-benchmark/2021/table_chrome_96.0.4664.45.html" rel="noopener noreferrer"&gt;and more&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Sukka, Tom, and all of the other contributors!&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Are you as excited as me? &lt;a href="https://millionjs.org" rel="noopener noreferrer"&gt;Get started!&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>opensource</category>
      <category>webdev</category>
    </item>
    <item>
      <title>I made React with a faster Virtual DOM</title>
      <dc:creator>Aiden Bai</dc:creator>
      <pubDate>Wed, 01 Jun 2022 06:04:15 +0000</pubDate>
      <link>https://dev.to/aidenybai/i-made-react-with-a-faster-virtual-dom-37hd</link>
      <guid>https://dev.to/aidenybai/i-made-react-with-a-faster-virtual-dom-37hd</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Plug: I help develop &lt;a href="https://github.com/aidenybai/million"&gt;&lt;code&gt;Million&lt;/code&gt;&lt;/a&gt;: Virtual DOM into the future! 💥🦁✨&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Million is a lightweight (&lt;code&gt;&amp;lt;1kb&lt;/code&gt;) Virtual DOM. It's &lt;a href="https://millionjs.org/benchmarks"&gt;&lt;em&gt;&lt;strong&gt;really fast&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt; and makes it easy to create user interfaces.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Oh man... Another &lt;a href="https://regexr.com/6mr5f"&gt;&lt;code&gt;/virtual dom|javascript/gim&lt;/code&gt;&lt;/a&gt; library? I'm fine with &lt;a href="https://reactjs.org"&gt;React&lt;/a&gt; already, why should I bother switching?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Million makes creating user interfaces as easy as &lt;a href="https://reactjs.org"&gt;React&lt;/a&gt;, but with faster performance and smaller bundle size for the end user. By computing the user interface beforehand with a compiler, Million reduces the overhead of traditional Virtual DOM.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Okay cool... but why should I use Million if I can just use &lt;a href="https://preactjs.com/"&gt;Preact&lt;/a&gt; if I need something a bit more lightweight?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;While alternative libraries like &lt;a href="https://preactjs.com/"&gt;Preact&lt;/a&gt; reduce bundle sizes by efficient code design, Million takes it a step further by &lt;strong&gt;leveraging compilation&lt;/strong&gt; to make a quantum leap in improving bundle size &lt;strong&gt;and&lt;/strong&gt; render speed.&lt;/p&gt;

&lt;p&gt;Think of it as if &lt;a href="https://preactjs.com/"&gt;Preact&lt;/a&gt; and &lt;a href="https://svelte.dev/"&gt;Svelte&lt;/a&gt; had a baby. &lt;a href="https://millionjs.org/benchmarks"&gt;A baby with &lt;em&gt;&lt;strong&gt;super speed! 👶&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Using &lt;code&gt;million/react&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Here is an extremely simple implementation of a Counter app using Million.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;compat&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;createRoot&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;million/react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Counter&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;init&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&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="nx"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;init&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Counter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;setValue&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;1&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Increment&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;setValue&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;1&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Decrement&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&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;root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createRoot&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="nx"&gt;querySelector&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;span class="c1"&gt;// Million wraps render functions inside a compat function&lt;/span&gt;
&lt;span class="nx"&gt;compat&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;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Counter&lt;/span&gt; &lt;span class="nx"&gt;init&lt;/span&gt;&lt;span class="o"&gt;=&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="sr"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, you can write React code. Million will automagically optimize it during compile time, allowing for a super speedy Virtual DOM.&lt;/p&gt;

&lt;p&gt;Open the project to start tinkering:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://stackblitz.com/github/aidenybai/million-react-compat"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--urWHDBKJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://developer.stackblitz.com/img/open_in_stackblitz.svg" alt="Open in StackBlitz" width="162" height="32"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Need help on using React? Check out the &lt;a href="https://beta.reactjs.org/apis"&gt;React documentation&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;This is very, &lt;strong&gt;VERY&lt;/strong&gt; early stage, so be prepared for weird bugs / plugin incompatibility / etc. If you have any suggestions, I'd be more than happy if you replied in a comment with it!&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Turning MPA to SPA with Virtual DOM</title>
      <dc:creator>Aiden Bai</dc:creator>
      <pubDate>Sun, 17 Apr 2022 08:05:03 +0000</pubDate>
      <link>https://dev.to/aidenybai/turning-mpa-to-spa-with-virtual-dom-5abd</link>
      <guid>https://dev.to/aidenybai/turning-mpa-to-spa-with-virtual-dom-5abd</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Plug: I help develop &lt;a href="https://github.com/aidenybai/million"&gt;&lt;code&gt;Million&lt;/code&gt;&lt;/a&gt;: Virtual DOM into the future! 💥🦁✨&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Motivation
&lt;/h2&gt;

&lt;p&gt;Whether you use a static site generator like Eleventy, have a server rendered application with Ruby on Rails, or just have a plain HTML/CSS/JS site, you're probably using some sort of multi-page application.&lt;/p&gt;

&lt;p&gt;The main issue with MPA is that each navigation (e.g. clicking a link, form submission) requires a full page reload, meaning more time is wasted. &lt;/p&gt;

&lt;p&gt;We could rewrite our entire app as a SPA with React/Vue, but that would be time consuming and unnecessarily complex.&lt;/p&gt;

&lt;p&gt;This is why tools like &lt;a href="https://turbo.hotwired.dev/handbook/drive"&gt;Turbo Drive&lt;/a&gt; exist. Turbo Drive &lt;em&gt;"watches for link clicks and form submissions, performs them in the background, and updates the page without doing a full reload."&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;However, I feel like Turbo Drive is sometimes too overcomplicated -- I just want something small that works without much configuration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;Using &lt;a href="https://millionjs.org"&gt;Million&lt;/a&gt;, a modern Virtual DOM library, I created a &lt;a href="https://millionjs.org/docs/api/extra/router"&gt;MPA to SPA router&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;All you have to do is add this in your HTML files&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://unpkg.com/million?module&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And it's that easy!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>opensource</category>
      <category>react</category>
    </item>
    <item>
      <title>Exploring Blockdom: Fastest Virtual DOM (ever!)</title>
      <dc:creator>Aiden Bai</dc:creator>
      <pubDate>Sat, 26 Feb 2022 08:27:31 +0000</pubDate>
      <link>https://dev.to/aidenybai/exploring-blockdom-fastest-virtual-dom-ever-28nl</link>
      <guid>https://dev.to/aidenybai/exploring-blockdom-fastest-virtual-dom-ever-28nl</guid>
      <description>&lt;p&gt;If you've been around in the JavaScript UI library development space, you've likely heard about &lt;a href="https://github.com/ged-odoo/blockdom" rel="noopener noreferrer"&gt;blockdom&lt;/a&gt;, which claims to be &lt;em&gt;probably&lt;/em&gt; the fastest Virtual DOM that currently exists.&lt;/p&gt;

&lt;p&gt;Its even been praised by Ryan Carniato as an example of hyper performant Virtual DOM, even being comparable to Solid.js' performance:&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1435721745344831494-360" src="https://platform.twitter.com/embed/Tweet.html?id=1435721745344831494"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1435721745344831494-360');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1435721745344831494&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;h2&gt;
  
  
  Blockdom is &lt;em&gt;really&lt;/em&gt; fast
&lt;/h2&gt;

&lt;p&gt;Compared with other virtual DOMs (see &lt;a href="https://github.com/snabbdom/snabbdom" rel="noopener noreferrer"&gt;snabbdom&lt;/a&gt;, &lt;a href="https://github.com/Matt-Esch/virtual-dom" rel="noopener noreferrer"&gt;virtual-dom&lt;/a&gt;), it's significantly faster. These older methods use node-by-node diffing, or the traversal and comparison of the node tree in order to calculate the optimal DOM modifications to reduce reflow and repaints.&lt;/p&gt;

&lt;p&gt;The main way that Blockdom can achieve such high performance is by performing block-by-block diffing. Why are we doing node-by-node diffing when we know most trees will be static? We have a serialized version of the block, and we can do super simple string comparisons &lt;code&gt;O(1)&lt;/code&gt; instead of tree traversals &lt;code&gt;O(n)&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Old method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[A, B, C, D] diff() [A, B, C, D]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;New Method&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;A,B,C,D&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;A,B,C,D&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Additionally, creating elements is much faster. Instead of individually creating elements and constructing a DOM node tree, we can just used the serialized format of the block and   use the &lt;code&gt;cloneNode(true)&lt;/code&gt; method to quickly create a DOM tree.&lt;/p&gt;

&lt;p&gt;Here's what the syntax looks like:&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;// create block types&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;block&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createBlock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&amp;lt;div class="some-class"&amp;gt;&amp;lt;p&amp;gt;hello&amp;lt;/p&amp;gt;&amp;lt;blockdom-child-0/&amp;gt;&amp;lt;/div&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;subBlock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createBlock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&amp;lt;span&amp;gt;some value: &amp;lt;blockdom-text-0/&amp;gt;&amp;lt;/span&amp;gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// create a blockdom virtual tree&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tree&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;block&lt;/span&gt;&lt;span class="p"&gt;([],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;subBlock&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;blockdom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])]);&lt;/span&gt;

&lt;span class="c1"&gt;// mount the tree&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;tree&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="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// result:&lt;/span&gt;
&lt;span class="c1"&gt;// &amp;lt;div class="some-class"&amp;gt;&amp;lt;p&amp;gt;hello&amp;lt;/p&amp;gt;&amp;lt;span&amp;gt;some value: blockdom&amp;lt;/span&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;As you can see, Blockdom makes some tradeoffs in order to achieve best performance. The &lt;code&gt;blockdom-child&lt;/code&gt; syntax is somewhat awkward, but it is necessary in order to create the block tree.&lt;/p&gt;

&lt;p&gt;You can &lt;a href="https://github.com/ged-odoo/blockdom/blob/main/doc/performance_notes.md" rel="noopener noreferrer"&gt;read more about blockdom performance here&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Generalized Blocks
&lt;/h2&gt;

&lt;p&gt;So how can we learn from Blockdom and make existing Virtual DOM implementations better? I've been exploring this concept with &lt;a href="https://github.com/aidenybai/million" rel="noopener noreferrer"&gt;Million.js&lt;/a&gt;.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&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%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/aidenybai" rel="noopener noreferrer"&gt;
        aidenybai
      &lt;/a&gt; / &lt;a href="https://github.com/aidenybai/million" rel="noopener noreferrer"&gt;
        million
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Optimize React performance and make your React 70% faster in minutes, not months. 
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;blockquote&gt;
&lt;p&gt;Want to &lt;strong&gt;automatically find and fix performance issues&lt;/strong&gt;? Check out &lt;a href="https://million.dev/" rel="nofollow noopener noreferrer"&gt;Million Lint&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;a href="https://million.dev" rel="nofollow noopener noreferrer"&gt;
  &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Faidenybai%2Fmillion%2Fmain%2F.github%2Fassets%2Fbanner.png" alt="Million.js Banner"&gt;
&lt;/a&gt;
&lt;div&gt;
  &lt;a href="https://img.shields.io/github/actions/workflow/status/aidenybai/million/ci.yml?branch=main" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/fb497c53455593573470c806ffa33d241aa94946a78ce3fb00267c1973db65e5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616964656e796261692f6d696c6c696f6e2f63692e796d6c3f6272616e63683d6d61696e267374796c653d666c617426636f6c6f72413d30303030303026636f6c6f72423d303030303030" alt="CI"&gt;&lt;/a&gt;
  &lt;a href="https://www.npmjs.com/package/million" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/decc55deaac1f7f3c2915b32caf8e73337ad5cf84b6832c70e4db7aaae16685b/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f6d696c6c696f6e3f7374796c653d666c617426636f6c6f72413d30303030303026636f6c6f72423d303030303030" alt="NPM Version"&gt;&lt;/a&gt;
    &lt;a href="https://www.npmjs.com/package/million" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/a2bcac74c4f7b3c0d09f1c304102df4ec77184c0bbfd4d9cbfce3e04b4307690/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f64742f6d696c6c696f6e2e7376673f7374796c653d666c617426636f6c6f72413d30303030303026636f6c6f72423d303030303030" alt="NPM Downloads"&gt;&lt;/a&gt;
  &lt;a href="https://discord.gg/X9yFbcV2rF" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/946afe14467bbb5bc1bd8cca37860c03aff901927a7a6e5f51a38f24089e5ad4/68747470733a2f2f696d672e736869656c64732e696f2f646973636f72642f3933383132393034393533393138363735383f7374796c653d666c617426636f6c6f72413d30303030303026636f6c6f72423d303030303030266c6162656c3d646973636f7264266c6f676f3d646973636f7264266c6f676f436f6c6f723d666666666666"&gt;&lt;/a&gt;
&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td&gt;
          &lt;a href="https://million.dev/docs/introduction" rel="nofollow noopener noreferrer"&gt;📚 Read the docs&lt;/a&gt;
        &lt;/td&gt;
        &lt;td&gt;
          &lt;a href="https://www.youtube.com/watch?v=VkezQMb1DHw" rel="nofollow noopener noreferrer"&gt;🎦 Watch video&lt;/a&gt;
        &lt;/td&gt;
        &lt;td&gt;
          &lt;a href="https://million.dev/chat" rel="nofollow noopener noreferrer"&gt;💬 Join our Discord&lt;/a&gt;
        &lt;/td&gt;
        &lt;td&gt;
          &lt;a href="https://twitter.com/milliondotjs" rel="nofollow noopener noreferrer"&gt;🌐 Follow on Twitter&lt;/a&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;What is Million.js?&lt;/h2&gt;
&lt;/div&gt;

&lt;p&gt;Million.js is an extremely fast and lightweight optimizing compiler that make &lt;a href="https://react.dev" rel="nofollow noopener noreferrer"&gt;components&lt;/a&gt; up to &lt;a href="https://krausest.github.io/js-framework-benchmark/current.html" rel="nofollow noopener noreferrer"&gt;&lt;em&gt;&lt;strong&gt;70% faster&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Oh man... Another &lt;a href="https://regexr.com/6mr5f" rel="nofollow noopener noreferrer"&gt;&lt;code&gt;/virtual dom|javascript/gi&lt;/code&gt;&lt;/a&gt; framework? I'm fine with &lt;a href="https://reactjs.org" rel="nofollow noopener noreferrer"&gt;React&lt;/a&gt; already, why do I need this?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Million.js works with React and makes reconciliation faster. By using a fine-tuned, optimized virtual DOM, Million.js reduces the overhead of diffing (&lt;a href="https://demo.million.dev" rel="nofollow noopener noreferrer"&gt;&lt;em&gt;try it out here&lt;/em&gt;&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt; Imagine &lt;a href="https://react.dev" rel="nofollow noopener noreferrer"&gt;React&lt;/a&gt; components running at the speed of raw JavaScript.&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;&lt;a href="https://million.dev/" rel="nofollow noopener noreferrer"&gt;&lt;strong&gt;👉 Setup Million.js in seconds! →&lt;/strong&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;/div&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Installation&lt;/h2&gt;
&lt;/div&gt;

&lt;p&gt;The Million.js CLI will automatically install the package and configure your project for you.&lt;/p&gt;

&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;npx million@latest&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Once your down, just run your project and information should show up in your command line!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Having issues installing? &lt;a href="https://million.dev/docs/install" rel="nofollow noopener noreferrer"&gt;&lt;strong&gt;→ View the installation guide&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="markdown-heading"&gt;…&lt;/div&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/aidenybai/million" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;Million.js intends to use the compiler to reduce computational work of diffing, and blocks are a great way to do this. Million.js forgoes the slightly awkward syntax, focusing on two main concepts: the ability to do string comparison and &lt;code&gt;cloneNode(true)&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;This way, you don't need to construct a block and recall it every time you render. You just construct as you want, and it will handle the rest for you.&lt;/p&gt;

&lt;p&gt;This way, it's super simple syntax without much tradeoff.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;render&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;million&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;block&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;million/block&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;block&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;div&amp;gt;Hello World&amp;lt;/div&amp;gt;&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;You can read up about &lt;a href="https://million.js.org/docs/api/advanced/block" rel="noopener noreferrer"&gt;blocks in Million here&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;Blockdom presents exciting new ways to optimize Virtual DOM, making it a viable contender for ways we can optimize rendering in the future.&lt;/p&gt;

&lt;p&gt;Other Virtual DOM libraries should take inspiration from Blockdom and conduct research into how block-like structures can help make Virtual DOM rendering a contender in hyper-performant rendering libraries.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&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%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/ged-odoo" rel="noopener noreferrer"&gt;
        ged-odoo
      &lt;/a&gt; / &lt;a href="https://github.com/ged-odoo/blockdom" rel="noopener noreferrer"&gt;
        blockdom
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A fast virtual dom library
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;p&gt;&lt;a href="https://opensource.org/licenses/MIT" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/d6d3d36f4a3697707a0cdbe9f0b7935534baa6a94e906e36015020963c55afb3/68747470733a2f2f6261646765732e66726170736f66742e636f6d2f6f732f6d69742f6d69742e7376673f763d313032" alt="Open Source Love"&gt;&lt;/a&gt;
&lt;a href="https://badge.fury.io/js/blockdom" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/888c0d9ba98051cb4d921f23458842524b58f124cf4bd9b995f6de1c46efe801/68747470733a2f2f62616467652e667572792e696f2f6a732f626c6f636b646f6d2e737667" alt="npm version"&gt;&lt;/a&gt;
&lt;a href="https://www.npmjs.com/package/blockdom" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/786aecde93664cfafd74004284b2c9c51d3c51bc84cd32f5d710b6516552ab11/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f646d2f626c6f636b646f6d2e737667" alt="Downloads"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;blockdom&lt;/h1&gt;
&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Probably the fastest virtual dom library in the world!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;IMPORTANT: &lt;code&gt;blockdom&lt;/code&gt; is just a proof of concept and a place to experiment some ideas. This is
not intended to be used in a real application, no real support will be given!  However, it is
designed to be the rendering engine of the &lt;a href="https://github.com/odoo/owl" rel="noopener noreferrer"&gt;Owl framework&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;&lt;code&gt;blockdom&lt;/code&gt; is a very fast virtual dom library. Its main selling
point is that it does not represent DOM element by element, but instead block by
block, where a block is an element with all its static content and some special
tags to indicate dynamic content. This allows blockdom to use &lt;code&gt;cloneNode(true)&lt;/code&gt;
on blocks and speed up the diff process, since the vdom tree is much smaller.&lt;/p&gt;
&lt;p&gt;It features blocks, supports fragments, manage synthetic event handlers and more
Note that it is not a framework. It does not even have the concept of components
…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/ged-odoo/blockdom" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Million.js 1.0.0 Release!</title>
      <dc:creator>Aiden Bai</dc:creator>
      <pubDate>Sun, 28 Nov 2021 19:23:23 +0000</pubDate>
      <link>https://dev.to/aidenybai/millionjs-100-release-3pna</link>
      <guid>https://dev.to/aidenybai/millionjs-100-release-3pna</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://github.com/aidenybai/million" rel="noopener noreferrer"&gt;&lt;em&gt;&lt;code&gt;&amp;lt;1kb&lt;/code&gt; compiler-augmented virtual DOM. It's fast!&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I initially started Million.js on a whim. I wanted to tinker around and figure out how to build a simple virtual DOM, and maybe share it with a couple friends. Six months later, Million.js 1.0.0 is completed!&lt;/p&gt;

&lt;p&gt;It's been a hot minute, but I've genuinely enjoyed every moment of the process. I'm insanely ecstatic to finally present a stable version of something I'm proud of.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.youtube.com/watch?v=dAHD-k0zSuo" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fimg.youtube.com%2Fvi%2FdAHD-k0zSuo%2F0.jpg" alt="YT Video"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Million.js?
&lt;/h3&gt;

&lt;p&gt;It's a Virtual DOM, or the architecture React is built off of. Its goal is to be a compile target for Transitional UI Libraries by providing ways for compilers to optimize diffing.&lt;/p&gt;

&lt;p&gt;Essentially, Million.js leverages the declaratively and flexibility of the Virtual DOM and while deferring to the compiler when optimizations can be made.&lt;/p&gt;

&lt;p&gt;It also is composable, but sensible by default, allowing you to build scalable, increasingly complex logic, but also enjoy best practices with simple API if need be.&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;// Composable&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;diff&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;node&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nf"&gt;children&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nf"&gt;props&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;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;diff&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;newVNode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;oldVNode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;
&lt;span class="nf"&gt;flush&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;workStack&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;schedule&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Equivalent sensible default API&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;el&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And more complex usage of the default API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;patch&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;million&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Initialize app&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;m&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;id&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;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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&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;app&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Patch content&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;app&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;m&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;id&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;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Goodbye World&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;h3&gt;
  
  
  Why?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;🦁 Built for libraries that compile&lt;/li&gt;
&lt;li&gt;📦 Lightweight bundle size (&amp;lt;1kb brotli+min)&lt;/li&gt;
&lt;li&gt;⚡ Fast runtime operations&lt;/li&gt;
&lt;li&gt;🛠️ Composable using drivers, sensible by default&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Next Steps
&lt;/h3&gt;

&lt;p&gt;I want to bootstrap a compiler using babel JSX AST plugins and explore the possibilities around automatically applying flags, deltas, and keys at build time to optimize away unnecessary diffing.&lt;/p&gt;

&lt;p&gt;Additionally, I want to see what new paradigms and APIs can be built for new UI libraries, and possibility greater adoption of Million.js or tangential ideology.&lt;/p&gt;

&lt;p&gt;All in all, I'm excited for the future of Transitional UI Libraries, and I hope Million.js is a step towards that future!&lt;/p&gt;

&lt;h3&gt;
  
  
  Learn more:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://million.js.org" rel="noopener noreferrer"&gt;Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/aidenybai/million" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.overleaf.com/read/sztmjdmfzykx" rel="noopener noreferrer"&gt;Research Paper&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.google.com/presentation/d/e/2PACX-1vQ5ChzziKq1rgjKP0PvMVjJwd4x8_H0EdNbeUQmMzG7k8k3AloQRm86D9aEuvwzz2GtPW6JCiRTx_9P/pub?start=false&amp;amp;loop=false&amp;amp;delayms=3000" rel="noopener noreferrer"&gt;Conference Slides&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://million.aidenybai.com" rel="noopener noreferrer"&gt;Benchmarker&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://youtu.be/ak4oJvWU0bY" rel="noopener noreferrer"&gt;Video&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>showdev</category>
    </item>
    <item>
      <title>The Million.js Manifesto</title>
      <dc:creator>Aiden Bai</dc:creator>
      <pubDate>Wed, 28 Jul 2021 06:52:22 +0000</pubDate>
      <link>https://dev.to/aidenybai/the-million-js-manifesto-1ipg</link>
      <guid>https://dev.to/aidenybai/the-million-js-manifesto-1ipg</guid>
      <description>&lt;h2&gt;
  
  
  Past
&lt;/h2&gt;

&lt;p&gt;Back in the days when JavaScript was first manifested, direct DOM manipulation was used to introduce interactivity for static web sites. Eventually, the JavaScript scene moved on to new technologies such as MooTools and jQuery, which helped &lt;strong&gt;simplify certain actions into simple, reusable functions&lt;/strong&gt;. However, there was still one pressing issue.&lt;/p&gt;

&lt;p&gt;Even though web development became easier, scaling large web applications that required an extensive amount of interactivity was difficult, as operations were generally imperative and difficult to organize. This led the rise to several frameworks and libraries, notably React. React aimed to allow for &lt;strong&gt;declarative development and componentization to compose user interfaces scalably&lt;/strong&gt;. To achieve this, the team behind React used a Virtual DOM architecture, where computation and logic was deferred to an algorithm to determine changes. This means that the developer just has to figure out how the markup will look.&lt;/p&gt;

&lt;p&gt;React helped to pioneer extensive usage of JavaScript to render web applications, leading to the rise of the Virtual DOM architecture in other libraries and usage of new technologies like JSX.&lt;/p&gt;

&lt;h2&gt;
  
  
  Present
&lt;/h2&gt;

&lt;p&gt;Nowadays, the prevalence of web applications is non-negligible. JavaScript and React &lt;a href="https://nextjs.org/showcase"&gt;are everywhere&lt;/a&gt;, and the Virtual DOM architecture is used in many of the popular libraries today (React.js, Vue.js, Preact.js, Elm, etc). "Pure JavaScript rendering" has subsided as development of preprocessors such as Webpack have taken hold as a standard, leading the way to preprocessors, allowing for &lt;strong&gt;cross-browser compatibility (e.g. Babel), prerendering, and JAMstack technologies&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;JavaScript frameworks and libraries have entire ecosystems around them, with tools like Next.js around React supercharging how web development is done. Library developers are slowly realizing the importance of performance sacrificed in the previous generation of developers for the purpose of developer experience. This is seen with &lt;strong&gt;trends towards static analysis&lt;/strong&gt; with Svelte, which currently leverages the prevalent usage of bundlers in most web applications.&lt;/p&gt;

&lt;p&gt;Performance is slowly becoming a priority, but &lt;strong&gt;technologies that depend on the Virtual DOM like React are fundamentally outdated&lt;/strong&gt;, even with incremental improvements with lazy loading and ISR in Next.js.&lt;/p&gt;

&lt;h2&gt;
  
  
  Future
&lt;/h2&gt;

&lt;p&gt;It is easy to to recite, reinvent, and monkey-patch what exists. With React and the Virtual DOM being such a backbone technology in the JavaScript library space, it is paramount that bleeding-edge libraries like Next.js leverage their position in the ecosystem to pioneer &lt;a href="https://tomdale.net/2017/09/compilers-are-the-new-frameworks/"&gt;compiler-based optimizations&lt;/a&gt;. While the most straightforward solution is to ditch everything and use the browser just as compile target with a series of imperative operations, the Virtual DOM arguably brings many advantages. It helps us write declarative interfaces &lt;strong&gt;without templating, meaning conditions are constrained to the limit of JavaScript&lt;/strong&gt;, as well as &lt;a href="https://reactjs.org/blog/2013/06/05/why-react.html"&gt;many other benefits&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The future of the Virtual DOM is not destruction of the Virtual DOM, rather it is to &lt;strong&gt;constrain usage of the Virtual DOM where it is powerful&lt;/strong&gt; while leveraging static analysis and compilation (&lt;a href="https://dev.to/aidenybai/million-js-the-future-of-virtual-dom-1e6d"&gt;This is done through Million.js&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/aidenybai/million-js-the-future-of-virtual-dom-1e6d"&gt;→ Interested in how Million is different?&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I recently had the opportunity to chat with &lt;a href="https://twitter.com/rauchg"&gt;@rauchg&lt;/a&gt; about Million.js as well as some of my thoughts on the current state of Virtual DOM. He explained to me that optimization of the Virtual DOM was only a facet of the next phase of web frameworks. This includes how we can improve development mode experience, tree-shaking and bundle size, etc.&lt;br&gt;
aggressive tree shaking - reduce bundle size. I highly recommend you to check out his &lt;a href="https://twitter.com/rauchg"&gt;Twitter&lt;/a&gt; and &lt;a href="https://rauchg.com/"&gt;blog&lt;/a&gt;, as he has so much valuable insight into the industry and how impact can and needs to be made.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Million.js - The Future of Virtual DOM</title>
      <dc:creator>Aiden Bai</dc:creator>
      <pubDate>Fri, 16 Jul 2021 01:29:35 +0000</pubDate>
      <link>https://dev.to/aidenybai/million-js-the-future-of-virtual-dom-1e6d</link>
      <guid>https://dev.to/aidenybai/million-js-the-future-of-virtual-dom-1e6d</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Plug: &lt;em&gt;I work on &lt;a href="https://github.com/aidenybai/million"&gt;&lt;strong&gt;Million.js&lt;/strong&gt;&lt;/a&gt;: &amp;lt;1kb virtual DOM - it's fast!&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;Virtual DOM needs to leverage the compiler, so that unnecessary diffing is not incurred. &lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Recently, I published &lt;a href="https://dev.to/aidenybai/why-is-the-virtual-dom-necesssary-59l2"&gt;some&lt;/a&gt; &lt;a href="https://dev.to/aidenybai/how-does-virtual-dom-work-b74"&gt;articles&lt;/a&gt; detailing the Virtual DOM paradigm, implementation, and the benefits and flaws using it. These articles received mixed reception, with some developers agreeing with the points in the article, while others disagreed. They argued that compilation based frameworks that do some level of static analysis (notably &lt;a href="https://sveltejs.dev"&gt;Svelte&lt;/a&gt;) compile to imperative DOM operations and therefore &lt;strong&gt;bypass the overhead of a Virtual DOM engine.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;You may be wondering: What's the point of using Virtual DOM, if you can just use a compiler-based framework like Svelte? While static analysis and &lt;a href="https://tomdale.net/2017/09/compilers-are-the-new-frameworks/"&gt;compilation is the future&lt;/a&gt;, Virtual DOM should not be completely ruled out as an obselete technology. Svelte only is possible if API conditions are constrained, so that the code is predictive and therefore &lt;strong&gt;analyzable&lt;/strong&gt;&lt;em&gt;.&lt;/em&gt; For libraries that need more flexibility, such as React or Vue, conditions cannot be constrained easily and therefore a variant of the Virtual DOM is necessary for those libraries.&lt;/p&gt;

&lt;p&gt;This is why &lt;a href="https://github.com/aidenybai/million"&gt;Million.js&lt;/a&gt; exists—to bring the Virtual DOM into the future by leveraging the compiler for static analysis and optimizations &lt;strong&gt;that makes DOM manipulation be performant and flexible.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Virtual DOM Optimizations
&lt;/h2&gt;

&lt;p&gt;Traditionally, Virtual DOM engines do a significant amount of computation during the diffing process. For example, when diffing children, the Virtual DOM engine not only linearly calculates which nodes need to be updated, but also determines the possible swaps/moves that can be done. Although this incurrs the least amount of DOM modifications, the computational cost can be great. Even with extremely efficient list diffing algorithms (like &lt;code&gt;list-diff2&lt;/code&gt;), the time complexity is &lt;code&gt;O(n)&lt;/code&gt; in the best case (not including the &lt;code&gt;O(n^3&lt;/code&gt; time complexity baseline for diffing). Repeat this for all the children in a vnode tree and you can &lt;strong&gt;just imagine how inefficient this can be&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;This is why one of the major concepts to create a future oriented Virtual DOM is to be aware and construct the architecture based on the compiler. This not only increases performance by allowing for straight &lt;code&gt;O(1)&lt;/code&gt; operations, but also gracefully falls back to normal diffing when necessary. Additionally, &lt;strong&gt;bundle sizes decrease significantly&lt;/strong&gt;, reducing the amount of code that needs to be executed at runtime.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/aidenybai/million"&gt;Million.js&lt;/a&gt; attempts to implement this with three major "lines of defense":&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Keys:&lt;/strong&gt; Specify the identity of a vnode&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Keys are useful when you know that a certain vnode's position, data, and children will not change between two states. Keys can be provided by the user manually, or generated by the compiler. This allows for the vnode to be skipped entirely, avoiding unnecessary diffing (&lt;code&gt;O(1)&lt;/code&gt;)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flags&lt;/strong&gt;: Specify the type of content of a vnode's children.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Flags allow for diffing to skip certain computationally expensive condition branches. For example, if the vnode's children only contains text nodes, then just setting the &lt;code&gt;textContent&lt;/code&gt; of the element would be significantly faster than constructing and replacing a text node. &lt;a href="https://github.com/aidenybai/million"&gt;Million.js&lt;/a&gt; currently only supports 3 flags: &lt;code&gt;NO_CHILDREN&lt;/code&gt; (&lt;code&gt;O(1)&lt;/code&gt;), &lt;code&gt;ONLY_TEXT_CHILDREN&lt;/code&gt; (&lt;code&gt;O(n)&lt;/code&gt;), and &lt;code&gt;ANY_CHILDREN&lt;/code&gt; (&lt;code&gt;O(n^3)&lt;/code&gt;).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Deltas&lt;/strong&gt;: Specify predictive and consistent modifications of a vnode's children.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Deltas can be utilized when simple, imperative micro-actions can be predicted through static analysis. Deltas by default are a series of imperative operations, but leverage the internal diffing algorithm to reduce DOM manipulations. &lt;a href="https://github.com/aidenybai/million"&gt;Million.js&lt;/a&gt; currently supports 3 fundemental Delta operations: &lt;code&gt;INSERT&lt;/code&gt; (&lt;code&gt;O(1)&lt;/code&gt;), &lt;code&gt;UPDATE&lt;/code&gt; (&lt;code&gt;O(1) to O(n^3)&lt;/code&gt;), &lt;code&gt;DELETE&lt;/code&gt; (&lt;code&gt;O(1)&lt;/code&gt;).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Compiler Optimizations
&lt;/h2&gt;

&lt;p&gt;First off, most—if not all of the implementation complexity will be with the compiler. This is because static analysis is really hard to pull in a way so that it operates &lt;a href="https://hackernoon.com/why-using-static-analysis-is-hard-n02m3vt0"&gt;as intended&lt;/a&gt;. Below is a list of possible optimizations, and is by no means "real static analysis."&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Leveraging &lt;a href="https://github.com/aidenybai/million"&gt;Million.js&lt;/a&gt; features:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The primary way to optimize for &lt;a href="https://github.com/aidenybai/million"&gt;Million.js&lt;/a&gt; is just leverage the compiler-focused features that it provides. This is the only way to reduce diffing assuming that the patch scope remains constant.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Prerendering + reducing dynamic content&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Another way of making performance better is to not even consider static content by reducing the patching scope—especially if your application is only interactive in certain areas. This is even more efficient than generating imperative DOM operations, as DOM manipulation won't even be needed! Additionally, the initial vnode should be prerendered the page, so that the page doesn't need to be fully initialized at runtime.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;Bad:
&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt; inject &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Click Me!&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

Good:
&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&amp;lt;button&amp;gt;&lt;/span&gt;Click Me!&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Static vnode + props hoisting:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A standard optimization to hoist vnodes and props that are static, allowing them to be cached and incurr no generation computational cost. This is best illustrated with a code sample:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Without static VNode hoist&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;render&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;patch&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;m&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;undefined&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;`My favorite number: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt;
&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Static VNode needs to be constructed twice&lt;/span&gt;

&lt;span class="c1"&gt;// With static VNode hoist&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;_s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello World!&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;render&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;patch&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;_s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Static VNode is used twice and cached&lt;/span&gt;

&lt;span class="c1"&gt;// Without static props hoist&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;render&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;patch&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;m&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;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`app&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt; &lt;span class="p"&gt;}))&lt;/span&gt;
&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Static props need to be constructed twice&lt;/span&gt;

&lt;span class="c1"&gt;// With static props hoist&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;_s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`app&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;render&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;patch&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;m&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;_s&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Static props are used twice and cached&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

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

&lt;p&gt;&lt;em&gt;Note: If you feel that this sort of paradigm has a future and are willing to meet those ends—I highly recommend you check out &lt;a href="https://github.com/aidenybai/million"&gt;Million.js&lt;/a&gt; and try working on an implementation of a compiler yourself.&lt;/em&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://github.com/aidenybai/million"&gt;Million.js&lt;/a&gt; is far from being done, and there is a lot of work that needs to be done. I hope that this article has brought about a new perspective to think of the Virtual DOM as it progresses into the future. Feel free to comment any suggestions or lingering questions you may have!&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Tips to get Visibility + Feedback to your GitHub project</title>
      <dc:creator>Aiden Bai</dc:creator>
      <pubDate>Tue, 06 Jul 2021 07:20:40 +0000</pubDate>
      <link>https://dev.to/aidenybai/get-s-on-your-github-project-17o1</link>
      <guid>https://dev.to/aidenybai/get-s-on-your-github-project-17o1</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Plug: I help develop &lt;a href="https://github.com/aidenybai/million"&gt;&lt;code&gt;million&lt;/code&gt;&lt;/a&gt;: &amp;lt;1kb virtual DOM - it's fast!&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;If applicable, post your project on &lt;a href="https://news.ycombinator.com/"&gt;Hacker News&lt;/a&gt; with &lt;code&gt;Show HN:&lt;/code&gt; in your title, &lt;a href="https://echojs.com"&gt;EchoJS&lt;/a&gt;, &lt;a href="https://www.reddit.com/r/opensource/"&gt;r/opensource&lt;/a&gt;, &lt;a href="https://www.reddit.com/r/javascript/"&gt;r/javascript&lt;/a&gt;, &lt;a href="https://www.reddit.com/r/sideproject/"&gt;r/sideproject&lt;/a&gt;, and &lt;a href="https://producthunt.com"&gt;ProductHunt&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you have a following, post to those platforms (i.e. Twitter).&lt;/p&gt;

&lt;p&gt;If you have access to communities, post to those communities in sanctioned areas (i.e. Discord, Slack, Telegram)&lt;/p&gt;

&lt;p&gt;If you have extra time, post articles related to your project on blogging websites (i.e. Dev.to with #showdev, Hackernoon, Hashnode)&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;You probably stumbled upon this article because you're interested in promoting your project you've been working on. That's great! In this guide you'll learn how to validate your work through gathering an audience, attracting new contributors and stars.&lt;/p&gt;

&lt;p&gt;Right off the bat, you should have a reasonably intriguing and useful project. Make sure that your projects are presentable with a clear README, description, and logo. Take for example some projects I've done:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/aidenybai/million"&gt;Million.js&lt;/a&gt; - 🏳️‍🌈 &amp;lt;1kb virtual DOM - it's fast!&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/aidenybai/lucia"&gt;Lucia.js&lt;/a&gt; - 🙋‍♀️ 3kb library for tiny web apps&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since my projects are generally JavaScript/TypeScript/Web related, many of the resources provided will be targeted towards those communities, so use as you see fit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Platforms
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Hacker News
&lt;/h3&gt;

&lt;p&gt;Hacker News is probably one of the best way to reach other developers, but hundreds of posts are put on it each day. To ensure you get some exposure, prefix your post title with &lt;code&gt;Show HN:&lt;/code&gt; to be listed under the show category. Additionally, include an intriguing and easily understandable title to increase your click through rate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://news.ycombinator.com/item?id=24887968"&gt;Show HN: Lucia – 3kB Vue Alternative&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://news.ycombinator.com/item?id=27399687"&gt;Show HN: 1kb virtual DOM - it's fast!&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Dev.to
&lt;/h3&gt;

&lt;p&gt;Dev.to is probably one of the most effective ways to get developers to intract with your work. One option is to directly introduce your project. If you do, ensure you add the &lt;code&gt;#showdev&lt;/code&gt; tag as well as 3 additional tags related to your project.&lt;/p&gt;

&lt;p&gt;The other way of increasing interactions is to write articles &lt;em&gt;related to your project&lt;/em&gt; that developers could be interested in. This hooks developers into reading your article, extracting value, while becoming aware of your project. Ensure that you include call to actions at the start and end of your article.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/aidenybai/how-does-virtual-dom-work-b74"&gt;How does Virtual DOM work? (Build your own)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/aidenybai/why-is-the-virtual-dom-necesssary-59l"&gt;Why Virtual DOM?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Reddit
&lt;/h3&gt;

&lt;p&gt;Open source communities like &lt;a href="https://www.reddit.com/r/opensource/"&gt;r/opensource&lt;/a&gt;, &lt;a href="https://www.reddit.com/r/javascript/"&gt;r/javascript&lt;/a&gt;, &lt;a href="https://www.reddit.com/r/sideproject/"&gt;r/sideproject&lt;/a&gt; are very effective ways to promote your projects if you have a substantial amount (1k+) of Reddit karma. These communities generally discourage advertising, so if you have a new account, try posting to smaller communities to start off instead.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.reddit.com/r/opensource/comments/nsisa5/million_a_lightweight_and_fast_virtualdom_for/"&gt;Million, A lightweight and fast virtual-dom for your web apps.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.reddit.com/r/opensource/comments/jhi523/lucia_the_3kb_jquery_replacement/"&gt;Lucia - The 3kb jQuery replacement!&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ProductHunt
&lt;/h3&gt;

&lt;p&gt;ProductHunt is a great way to pitch your product to "maker-focused communities." This is pretty straightforward, I highly recommend you suppliment using this to advertise to other platforms as well.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.producthunt.com/posts/million-js"&gt;Million.js: A fast, &amp;lt;1kb virtual DOM&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.producthunt.com/posts/lucia-3kb-vue-like-javascript-library"&gt;Lucia: 3kb Vue-like JavaScript library&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Other
&lt;/h3&gt;

&lt;p&gt;You can use Twitter, EchoJS, and Discord/Slack/Telegram to help suppliment the other platforms.&lt;/p&gt;

&lt;h2&gt;
  
  
  Metrics
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Github Insights (Under Traffic Tab)&lt;/li&gt;
&lt;li&gt;Stars/Contributions to GitHub repo&lt;/li&gt;
&lt;li&gt;Dev.to Dashboard stats&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Side Effects
&lt;/h2&gt;

&lt;h3&gt;
  
  
  GitHub Trending
&lt;/h3&gt;

&lt;p&gt;This is generally the ultimate result of the promotion on other platforms - to float your project to get on trending. This encourages developers on Github who might work on similar projects to see your project. This type of visibility is the most valuable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Publications
&lt;/h3&gt;

&lt;p&gt;Another way to float your project to gain a "second wind" is to get publications to feature your project. This sort of method is best paired with GitHub trending.&lt;/p&gt;




&lt;p&gt;Have any suggestions? Send them in the comment section.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>discuss</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Why Virtual DOM?</title>
      <dc:creator>Aiden Bai</dc:creator>
      <pubDate>Fri, 02 Jul 2021 22:23:07 +0000</pubDate>
      <link>https://dev.to/aidenybai/why-is-the-virtual-dom-necesssary-59l2</link>
      <guid>https://dev.to/aidenybai/why-is-the-virtual-dom-necesssary-59l2</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Plug: I help develop &lt;a href="https://github.com/aidenybai/million" rel="noopener noreferrer"&gt;&lt;code&gt;million&lt;/code&gt;&lt;/a&gt;: &amp;lt;1kb virtual DOM - it's fast!&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;The Virtual DOM was initially pioneered by the React authors on the basis of making delarative JavaScript patterns performant - but how? To understand this, we need to quickly review how traditional DOM manipulation works.&lt;/p&gt;

&lt;p&gt;Generally speaking, the easiest way of changing the DOM ("Modifying the HTML") is to mutate the &lt;code&gt;innerHTML&lt;/code&gt; property on an element. For example, if I want to add a &lt;code&gt;div&lt;/code&gt; element in the document body, I could 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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;div&amp;gt;Hello World!&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// &amp;lt;body&amp;gt; now has a &amp;lt;div&amp;gt;Hello World!&amp;lt;/div&amp;gt; child.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This seems to be computationally performant, but it really isn't. While the action of reassignment is computationally performant, the DOM repaint ("Updating what the user sees") is not. This is because &lt;code&gt;innerHTML&lt;/code&gt; needs to parse DOM nodes from a string, preprocess, and append it, resulting in less-than-optimal performance. The issues with performance are increasingly noticable when there are more children/attributes and when the interval of mutation is shorter.&lt;/p&gt;

&lt;p&gt;So, how is this issue fixed? Well, instead, we do pinpoint changes to the DOM. For example, this solution would be almost &lt;strong&gt;10x faster&lt;/strong&gt; than the &lt;code&gt;innerHTML&lt;/code&gt; solution.&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;div&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="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;div&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="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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&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;div&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While this is simple enough, once you start performing continous mutations, more complexity arises. &lt;strong&gt;This is why the virtual DOM was created - to allow you to write declarative content (like the string in the &lt;code&gt;innerHTML&lt;/code&gt; example) while harnessing performance by making only pinpoint changes to the DOM.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Virtual DOM
&lt;/h2&gt;

&lt;p&gt;The virtual DOM is a tree of virtual nodes that represents what the DOM looks like. virtual nodes are light, stateless, and are JavaScript objects that only contain necessary fields. virtual nodes can be assembled into trees, and "diffed" to make pinpoint changes to the DOM.&lt;/p&gt;

&lt;p&gt;While this is efficient, it has some caveats. Notably, diffing is not computationally free. Traversing the trees have &lt;code&gt;O(n^3)&lt;/code&gt; time complexity, meaning the more children, the longer the time it will take to perform the action. To solve this, Million was created.&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%2Fqvsysw9ta4950c9tuc5v.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%2Fqvsysw9ta4950c9tuc5v.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/aidenybai/how-does-virtual-dom-work-b74"&gt;Read this article&lt;/a&gt; if you don't understand what the Virtual DOM is.&lt;/p&gt;

&lt;h2&gt;
  
  
  Million
&lt;/h2&gt;

&lt;p&gt;Million provides five major improvements: granular patching, fewer iterative passes, fast text interpolation, keyed virtual nodes, compiler flags.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Granular patching:&lt;/strong&gt; Instead of just replacing the entire element when there is a difference in props or children, only the necessary props are changed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fewer iterative passes:&lt;/strong&gt; Million attempts to reduce the amount of passes during diffing, allowing for better time and space complexity.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fast text interpolation:&lt;/strong&gt; Instead of replacing text nodes with DOM methods, Million uses compiler flags to set the &lt;code&gt;textContent&lt;/code&gt; of elements to boost performance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keyed virtual elements:&lt;/strong&gt; This allows for the patching algorithm to skip nodes if the new virtual element key is the same as the old one, minimizing the amount of unnecessary work.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compiler Flags:&lt;/strong&gt; This allows for the patching algorithm to skip condition branches, meaning less work is done.&lt;/li&gt;
&lt;/ul&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%2Fwp2dox7hhqeev31ksm46.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%2Fwp2dox7hhqeev31ksm46.png"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Thanks for reading! Drop a star to &lt;a href="https://github.com/aidenybai/million" rel="noopener noreferrer"&gt;Million&lt;/a&gt; or follow/react to this article for more Virtual DOM content!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
      <category>typescript</category>
    </item>
    <item>
      <title>How does Virtual DOM work? (Build your own)</title>
      <dc:creator>Aiden Bai</dc:creator>
      <pubDate>Thu, 17 Jun 2021 23:09:44 +0000</pubDate>
      <link>https://dev.to/aidenybai/how-does-virtual-dom-work-b74</link>
      <guid>https://dev.to/aidenybai/how-does-virtual-dom-work-b74</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Plug: I help develop &lt;a href="https://github.com/millionjs/million"&gt;&lt;code&gt;million&lt;/code&gt;&lt;/a&gt;: &amp;lt;1kb virtual DOM - it's fast!&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;The virtual DOM is a tree of virtual nodes that represents what the DOM looks like. virtual nodes are light, stateless, and are JavaScript objects that only contain necessary fields. virtual nodes can be assembled into trees, and "diffed" to make pinpoint changes to the DOM.&lt;/p&gt;

&lt;p&gt;The reasoning behind this is because modification and access of DOM nodes is computationally expensive. A diff between virtual nodes, accessing the DOM only for modification, is the premise of virtual DOM. It avoids the DOM as much as possible, favoring plain JavaScript objects instead, making reading and writing much cheaper.&lt;/p&gt;

&lt;h2&gt;
  
  
  How does it work?
&lt;/h2&gt;

&lt;p&gt;The Million virtual DOM contains three main functions: &lt;code&gt;m&lt;/code&gt;, &lt;code&gt;createElement&lt;/code&gt;, &lt;code&gt;patch&lt;/code&gt;. To completely understand how virtual DOM works, let's try and create our own rudimentary virtual DOM based off of these functions (&lt;strong&gt;~7 minutes read time&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;Before we start, we need to define what a virtual node is. A virtual node can either be a JavaScript object (virtual element) or a string (text).&lt;/p&gt;




&lt;p&gt;The &lt;code&gt;m&lt;/code&gt; function is a helper function that creates virtual elements. A virtual element contains three properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;tag&lt;/code&gt;: which stores the tag name of the element as a string.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;props&lt;/code&gt;: which stores the properties/attributes of the element as an object.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;children&lt;/code&gt;: which stores virtual node children of the element as an array.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An example implementation of the &lt;code&gt;m&lt;/code&gt; helper function is below:&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;m&lt;/span&gt; &lt;span class="o"&gt;=&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="o"&gt;=&amp;gt;&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way, we can construct virtual nodes easily:&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;m&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;id&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;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="c1"&gt;// Is the same as:&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;div&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;id&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;span class="na"&gt;children&lt;/span&gt;&lt;span class="p"&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;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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;The &lt;code&gt;createElement&lt;/code&gt; function turns a virtual node into a real DOM element. This is important because we'll be using this in our &lt;code&gt;patch&lt;/code&gt; function and the user may also use it to initialize their application.&lt;/p&gt;

&lt;p&gt;We'll need to programmatically create a new detached DOM element, then iterate over the virtual element props while adding them to the DOM element, and finally iterating over the children, initialling them as well. An example implementation of the &lt;code&gt;createElement&lt;/code&gt; helper function is below:&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;createElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;vnode&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="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;vnode&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="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createTextNode&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="c1"&gt;// Catch if vnode is just text&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;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="nx"&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;span class="k"&gt;if&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;props&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="nx"&gt;entries&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;props&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;forEach&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="nx"&gt;value&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;el&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="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="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;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="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="nx"&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="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;createElement&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;span class="k"&gt;return&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;p&gt;This way, we can convert virtual nodes to DOM elements easily:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;m&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;id&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;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="c1"&gt;// Is the same as: &amp;lt;div id="app"&amp;gt;Hello World&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;The &lt;code&gt;patch&lt;/code&gt; function takes an existing DOM element, old virtual node, and new virtual node. This won't necessarily be the most performant implementation, but this is just for demonstration purposes.&lt;/p&gt;

&lt;p&gt;We'll need to diff the two virtual nodes, then replace out the element when needed. We do this by first determining whether one of the virtual nodes is a text, or a string, and replacing it if the old and new virtual nodes do not equate each other. Otherwise, we can safely assume both are virtual elements. After that, we diff the tag and props, and replace the element if the tag has changed. We then iterate over the children and recursively patch if a child is a virtual element. An example implementation of the &lt;code&gt;patch&lt;/code&gt; helper function is below:&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;patch&lt;/span&gt; &lt;span class="o"&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;oldVNode&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="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;replace&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;replaceWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;createElement&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="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;newVNode&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;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;remove&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;oldVNode&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;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;createElement&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="c1"&gt;// Handle text case&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;oldVNode&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="o"&gt;||&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;newVNode&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;oldVNode&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;newVNode&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;replace&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;// Diff tag&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;oldVNode&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;newVNode&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="c1"&gt;// Diff props&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;oldVNode&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;some&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;prop&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;oldVNode&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;prop&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&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;props&lt;/span&gt;&lt;span class="p"&gt;?[&lt;/span&gt;&lt;span class="nx"&gt;prop&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;replace&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="c1"&gt;// Diff children&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;childNodes&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&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="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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;patch&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;oldVNode&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="nx"&gt;i&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;children&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;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;This way, we can patch DOM elements based on virtual nodes easily:&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;oldVNode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;m&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;id&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;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="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="nx"&gt;m&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;id&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;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Goodbye World&lt;/span&gt;&lt;span class="dl"&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;el&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;oldVNode&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;patch&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;oldVNode&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="c1"&gt;// el will become: &amp;lt;div id="app"&amp;gt;Goodbye World&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;Notes:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The old virtual node must always model the DOM element until after it is patched.&lt;/li&gt;
&lt;li&gt;Generally speaking, applications aren't directly written with these methods, rather they should be abstracted out into components and JSX for simplicity.&lt;/li&gt;
&lt;li&gt;This is not the same as Million's implementation, rather it is a demonstration to better allow you to understand how the virtual DOM works.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  So... What's unique about Million then?
&lt;/h2&gt;

&lt;p&gt;Million provides five major improvements: granular patching, fewer iterative passes, fast text interpolation, keyed virtual nodes, compiler flags.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Granular patching:&lt;/strong&gt; Instead of just replacing the entire element when there is a difference in props or children, only the necessary props are changed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fewer iterative passes:&lt;/strong&gt; Million attempts to reduce the amount of passes during diffing, allowing for better time and space complexity.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fast text interpolation:&lt;/strong&gt; Instead of replacing text nodes with DOM methods, Million uses compiler flags to set the &lt;code&gt;textContent&lt;/code&gt; of elements to boost performance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keyed virtual elements:&lt;/strong&gt; This allows for the patching algorithm to skip nodes if the new virtual element key is the same as the old one, minimizing the amount of unnecessary work.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compiler Flags:&lt;/strong&gt; This allows for the patching algorithm to skip condition branches, meaning less work is done.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>typescript</category>
      <category>react</category>
    </item>
  </channel>
</rss>
