<?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>Forem: Ibrahim ben Salah</title>
    <description>The latest articles on Forem by Ibrahim ben Salah (@xania).</description>
    <link>https://forem.com/xania</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%2F979052%2F60a8e7c5-ea25-4ebf-9d20-33543d8397a6.png</url>
      <title>Forem: Ibrahim ben Salah</title>
      <link>https://forem.com/xania</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/xania"/>
    <language>en</language>
    <item>
      <title>JavaScript SSR made easy</title>
      <dc:creator>Ibrahim ben Salah</dc:creator>
      <pubDate>Tue, 21 Feb 2023 18:24:40 +0000</pubDate>
      <link>https://forem.com/xania/ssr-based-on-pure-functions-3e9b</link>
      <guid>https://forem.com/xania/ssr-based-on-pure-functions-3e9b</guid>
      <description>&lt;p&gt;Server Side Rendering (SSR) in any JavaScript framework, with preservation of the reactivity behavior of the application, depends on the ability to hibernate the runtime state (at server), so that it can be later (at client) hydrated back to its previous state. &lt;/p&gt;

&lt;h3&gt;
  
  
  Video
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=HXmWYlhQCeU" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=HXmWYlhQCeU&lt;/a&gt;&lt;br&gt;
(PS, this is my first video in a decade, I hope my coding skills make up for the video quality ;)&lt;/p&gt;
&lt;h3&gt;
  
  
  Source code
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/xania/view/tree/main/packages/kitchen-sink" rel="noopener noreferrer"&gt;kitchen-sink&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The following code snippet is a basic SSR simulation of how hibernation and hydration could work.&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;// ~/pages/hello-world.ts&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;server&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&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;function&lt;/span&gt; &lt;span class="nf"&gt;client&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello World&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;

   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;client&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;I was hoping I could use an existing solution for a UI library that I wrote called &lt;code&gt;@xania/view&lt;/code&gt; but all solution that I could find are specific to other UI frameworks. &lt;br&gt;
So I decided to build a UI agnostic solution. It is extremely hard and it evolves writing code transpiler/compiler but I did it anyway and I am hyped to share with you the results.&lt;/p&gt;
&lt;h2&gt;
  
  
  Introducing &lt;code&gt;vite-plugin-resumable&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;This plugin is a UI framework agnostic solution for hibernating and hydrating javascript closures. You can say we found a way to serialize functions. It is the foundation for SSR feature of &lt;code&gt;@xania/view&lt;/code&gt; but it can be used with any other UI library.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Continue reading to learn how to setup your project or visit github &lt;a href="https://github.com/xania/view/tree/main/packages/kitchen-sink" rel="noopener noreferrer"&gt;here&lt;/a&gt; for full working source code of the example.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  Setup
&lt;/h3&gt;

&lt;p&gt;Currently we have only support for vite projects.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;create new vite project&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;npm init vite my-vite-app&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;install resumable package&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;npm i vite-plugin-resumable&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;next step is to add the plugin to your vite configuration&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&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="nx"&gt;resumable&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;vite-plugin-resumable&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

  &lt;span class="p"&gt;...&lt;/span&gt;
  &lt;span class="nx"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nf"&gt;resumable&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;By default, this plugin looks in &lt;code&gt;pages&lt;/code&gt; folder for all files with .tsx extension and creates a server entry for each file found.&lt;/p&gt;

&lt;p&gt;So go ahead and create a page called hello-world.tsx script in &lt;em&gt;pages&lt;/em&gt; folder&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;// ~/pages/hello-world.ts&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;view&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello server&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;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;State&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="nx"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
     &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
       &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;counter&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;client&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello client&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;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&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="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="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;x&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="p"&gt;}&lt;/span&gt;

   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;client&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 resumable package will automatically &lt;strong&gt;infer&lt;/strong&gt; the client code from the result of the server entry function.&lt;br&gt;
In this case the client code is generated from the function declaration of &lt;code&gt;client&lt;/code&gt;. This function will be executed on client and will use the hydrated instance of the counter object, including the registered &lt;em&gt;next-observer&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Let's start the application and see this in action&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;npm start&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Open a browser and navigate to &lt;em&gt;&lt;a href="http://localhost:5173/hello-world" rel="noopener noreferrer"&gt;http://localhost:5173/hello-world&lt;/a&gt;&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;// terminal output
Hello server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;// browser output
Hello client
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Clicking on the document will increment the counter and trigger the observer which will print current value to the console of your browser.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// browser output
counter, 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;This plugin streamlines the development process by simplifying the code structure required to make a web application that can be executed on both the server and client side.&lt;/p&gt;

&lt;p&gt;This is currently an alpha (aka proof of concept) version to verify usefulness of this approach. So far, this plugin captures the generic features of SSR so that any UI library could benefit from it.&lt;/p&gt;

&lt;p&gt;We optimize the amount of client script that is sent to the client, but in the future we will be looking for more opportunities to optimize the state data (e.g. if we only access a property of an object then we may want to sent only the value of that property instead of the whole object.&lt;/p&gt;

&lt;p&gt;next is to try this out with React and I will also build an adapter for &lt;a href="https://github.com/xania/view" rel="noopener noreferrer"&gt;@xania/view&lt;/a&gt;&lt;/p&gt;

</description>
      <category>gemini</category>
      <category>ai</category>
      <category>development</category>
      <category>discuss</category>
    </item>
    <item>
      <title>SSR in javascript is hard</title>
      <dc:creator>Ibrahim ben Salah</dc:creator>
      <pubDate>Mon, 02 Jan 2023 22:57:36 +0000</pubDate>
      <link>https://forem.com/xania/ssr-in-javascript-is-hard-1i72</link>
      <guid>https://forem.com/xania/ssr-in-javascript-is-hard-1i72</guid>
      <description>&lt;p&gt;I started working on &lt;a href="https://github.com/xania/view" rel="noopener noreferrer"&gt;Xania&lt;/a&gt; Web's Fastest JSX based Library since back in 2014.&lt;/p&gt;

&lt;p&gt;Before that I was 90% backend 10y .NET developer and my focus has shifted since then more towards JavaScript. And because of my background I am hyped about the new trend shift towards backend, but...frontend has evolved and we don't want to loose the capabilities of our beloved libraries in favor of SSR. but it's hard.&lt;/p&gt;

&lt;p&gt;SSR is mainly hard because of serialization of &lt;code&gt;runtime&lt;/code&gt; state. Part of it is the need for javasript bundler at runtime. Basically we need to examine the data we are sending to the client, determine what types are used, track back where those types are defined in code (which I am not sure is even possible), create a hydration script which imports these types. And, it get even hard if we also want to serialize closures. After that framework specific handling can take over...which is relatively easy to do.&lt;/p&gt;

&lt;p&gt;There are a couple of framework solutions with support for hydration (rehydration/resumability/lazy/partial,etc....) like &lt;code&gt;SvelteKit&lt;/code&gt;, &lt;code&gt;Next.JS&lt;/code&gt;, &lt;code&gt;Qwik&lt;/code&gt;, &lt;code&gt;Astro&lt;/code&gt;, &lt;code&gt;Marko&lt;/code&gt;, etc... but it is sad to see that none allows an incremental / progressive adaption. They all are coupled to either a view library, routing or toolchain, I just want to use &lt;code&gt;Vite&lt;/code&gt; and &lt;code&gt;Xania&lt;/code&gt; and add &lt;em&gt;Hydration&lt;/em&gt; to the mix.&lt;/p&gt;

&lt;p&gt;Here is the challenge I am taking on:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Is it possible to statiscally generate rehydration script at compile time? I am thinking of a solution that is using rollup transform plugin, &lt;/li&gt;
&lt;li&gt;Or otherwise, create a serializer, runtime bundler and hydration script.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I have little to no experience in this area, so any suggestion are very welcome.&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>ai</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Immutability is overrated</title>
      <dc:creator>Ibrahim ben Salah</dc:creator>
      <pubDate>Tue, 20 Dec 2022 23:59:49 +0000</pubDate>
      <link>https://forem.com/xania/immutability-is-overrated-3k9o</link>
      <guid>https://forem.com/xania/immutability-is-overrated-3k9o</guid>
      <description>&lt;h4&gt;
  
  
  Immutability fine, but not always, right?!
&lt;/h4&gt;

&lt;p&gt;As the author of &lt;a href="https://github.com/xania/view" rel="noopener noreferrer"&gt;Xania&lt;/a&gt; a javascript UI library I ask myself this question countless times. &lt;/p&gt;

&lt;p&gt;Immutability as an unbreakable rule does not make sense to me and I have been thinking about this for years, Could you help me make sense of it? I've heard all the popular arguments but I am still not convinced, let me explain..&lt;/p&gt;

&lt;p&gt;Sure I do agree on the importance of immutability, and to be very precise I dont argue that, but disallowing immutability always and in all cases feels like a handicap in programming languages or in some case libraries in language like JavaScript where mutability is possible but make it inconvient to work with mutable data.&lt;/p&gt;

&lt;h4&gt;
  
  
  Pure functions have side-effects
&lt;/h4&gt;

&lt;p&gt;I found &lt;a href="https://www.johndcook.com/blog/2010/05/18/pure-functions-have-side-effects/" rel="noopener noreferrer"&gt;this article&lt;/a&gt; that inspired me investigate this more&lt;/p&gt;

&lt;p&gt;take for example the functions &lt;code&gt;f&lt;/code&gt; and &lt;code&gt;wasm&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;f&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&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;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wasm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;esi&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ecx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;eax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ecx&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;eax&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;esi&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;eax&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is generally accepted that &lt;code&gt;f&lt;/code&gt; is pure, and it is.  But &lt;code&gt;wasm&lt;/code&gt; mutates the variable &lt;code&gt;eax&lt;/code&gt; so it is generally accepted to say that &lt;code&gt;wasm&lt;/code&gt; is inpure, but is it really?&lt;br&gt;
Suprisingly &lt;code&gt;wasm&lt;/code&gt; is kind of how &lt;code&gt;f&lt;/code&gt; would look like if it was compiled to WASM. We can also image how &lt;code&gt;wasm&lt;/code&gt; can be decompiled back to &lt;code&gt;f&lt;/code&gt;, so without going deep into theory we can say &lt;code&gt;f&lt;/code&gt; and &lt;code&gt;wasm&lt;/code&gt; are the &lt;em&gt;same&lt;/em&gt;, correct me if I am wrong but I think this is called isomorphic in category theory, because following rule applies...&lt;/p&gt;

&lt;p&gt;| &lt;code&gt;f&lt;/code&gt; o &lt;code&gt;wasm&lt;/code&gt; == &lt;code&gt;wasm&lt;/code&gt; o &lt;code&gt;f&lt;/code&gt; == id&lt;/p&gt;

&lt;p&gt;Despite the fact that &lt;code&gt;wasm&lt;/code&gt; has mutations we should consider it as pure just as &lt;code&gt;f&lt;/code&gt; because they are the &lt;em&gt;same&lt;/em&gt;.&lt;br&gt;
In general, a mutation does not always conclude if the given function is pure or not.&lt;/p&gt;

&lt;h4&gt;
  
  
  Rules for Mutability
&lt;/h4&gt;

&lt;p&gt;Like in the article above by John D. Cook, pure functions only make sense at certain the level of abstraction. sounds like we can agree on it but this raises the question, what are pricesly those levels where we allow mutations in a pure function? Is the level boundary defined by the language runtime?&lt;br&gt;
Is it thinkable to extend the mutation to the user code (even in haskell) if rules of mutability are satisfied? &lt;/p&gt;

&lt;p&gt;This is where my brain starts to hurt. What are your thoughs and do you know if there are resources on this subject?&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>If I would rewrite React from scratch it would look like this</title>
      <dc:creator>Ibrahim ben Salah</dc:creator>
      <pubDate>Thu, 15 Dec 2022 18:47:07 +0000</pubDate>
      <link>https://forem.com/xania/if-i-would-rewrite-react-from-scratch-it-would-look-like-this-553d</link>
      <guid>https://forem.com/xania/if-i-would-rewrite-react-from-scratch-it-would-look-like-this-553d</guid>
      <description>&lt;h4&gt;
  
  
  Keep JSX and functions
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;span&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello, React&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;span&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Keep useState, but add full HTML syntax support, use click not onClick, class not className
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&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;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;updateCount&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="mi"&gt;0&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;button&lt;/span&gt; &lt;span class="na"&gt;click&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;updateCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      Count: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&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;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  useState with objects
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;me&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="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ibrahim&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ben Salah&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="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;
         fullName: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;me&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;firstName&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;me&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;lastName&lt;/span&gt;&lt;span class="dl"&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  true first class support for async/await and promises, not the fake &lt;code&gt;use&lt;/code&gt; hook
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&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;ditto&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://pokeapi.co/api/v2/pokemon/ditto&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&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="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;ditto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Add support for async iterator
&lt;/h4&gt;

&lt;p&gt;Not sure if one would expect this to end up with one final div and auto dispose all the previous, or all div's should be retained&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;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nx"&gt;MyComponent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;for&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;delay&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;delays&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;wait&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;yield&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;`Delayed response for $&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;delay&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; milliseconds`&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Add support for observables (e.g. rxjs)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;MyCounter&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;time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;timer&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="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&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="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&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="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;Current time: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;time&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;Do you agree on using the &lt;em&gt;platform&lt;/em&gt; instead of inventing dubious hooks with many gotcha's? Or do you think it's an impossible idea? If the latter then you would be surprised to hear that the fastest UI library in the krausest js framework benchmark is already built with these concepts, it's called  &lt;em&gt;xania&lt;/em&gt; (named after a small district in Morocco).&lt;/p&gt;

&lt;p&gt;benchmark results:&lt;br&gt;
&lt;a href="https://krausest.github.io/js-framework-benchmark/2022/table_chrome_104_windows.html"&gt;https://krausest.github.io/js-framework-benchmark/2022/table_chrome_104_windows.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;benchmark code:&lt;br&gt;
&lt;a href="https://github.com/xania/krausest-js-benchmark/blob/main/src/app.tsx"&gt;https://github.com/xania/krausest-js-benchmark/blob/main/src/app.tsx&lt;/a&gt;&lt;/p&gt;

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