<?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: Awais Akram Mughal</title>
    <description>The latest articles on DEV Community by Awais Akram Mughal (@iamawaisakram).</description>
    <link>https://dev.to/iamawaisakram</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%2F160762%2F5ed838f8-6756-4fdf-bf40-df6c1fd5ec1c.jpg</url>
      <title>DEV Community: Awais Akram Mughal</title>
      <link>https://dev.to/iamawaisakram</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/iamawaisakram"/>
    <language>en</language>
    <item>
      <title>Currying Function and It's Advantages</title>
      <dc:creator>Awais Akram Mughal</dc:creator>
      <pubDate>Wed, 17 Jun 2020 14:03:31 +0000</pubDate>
      <link>https://dev.to/iamawaisakram/currying-function-and-it-s-advantages-5fgf</link>
      <guid>https://dev.to/iamawaisakram/currying-function-and-it-s-advantages-5fgf</guid>
      <description>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Turning a function that takes multiple arguments, to a function which returns functions (Unary and Anonymous).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Currying is right-associative (Read from Right-Left).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The concept acts systematic: Property needs to interact with other basic properties in order to fully develop its advantages. &lt;strong&gt;There is a mutual dependency between the properties involved.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Makes working with HOC(Higher Order Component) much more effective, provided the passed in functions are in curried form themselves.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's Look at an Example:&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;// * Abstraction over Arity(the amount of functions you can curry into one function)&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;comp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;g&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;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;g&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;inc&lt;/span&gt; &lt;span class="o"&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="c1"&gt;// * Unary Function&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mul&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;y&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;=&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="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// * Binary Function&lt;/span&gt;

&lt;span class="c1"&gt;// * Normal Composition of two unary Functions:&lt;/span&gt;
&lt;span class="nx"&gt;comp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inc&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;inc&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// * 4&lt;/span&gt;

&lt;span class="c1"&gt;// * Composition of Binary and Unary Funtions:&lt;/span&gt;
&lt;span class="nx"&gt;comp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mul&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;inc&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// * 9&lt;/span&gt;

&lt;span class="c1"&gt;// * Invalid Composition of an inner binary Function:&lt;/span&gt;
&lt;span class="nx"&gt;comp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inc&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;mul&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// * Type Error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Let's look at the Invalid Composition Example:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Here, &lt;em&gt;f's&lt;/em&gt; arity doesn't matter, because "comp" is polymorphic in nature/return.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If &lt;em&gt;f&lt;/em&gt; is substituted with &lt;em&gt;inc&lt;/em&gt;, &lt;em&gt;comp's&lt;/em&gt; return type becomes:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;g&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;If &lt;em&gt;f&lt;/em&gt; is substituted with &lt;em&gt;mul&lt;/em&gt;, &lt;em&gt;comp's&lt;/em&gt; return type becomes:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;g&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Which is perfectly valid. However, &lt;em&gt;mul&lt;/em&gt; here is &lt;em&gt;g&lt;/em&gt; and it requires 2 arguments but only one is given, hence, type error.&lt;/p&gt;

&lt;h3&gt;
  
  
  Important Things to note here:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Arguments Order matters, it only concerns non-commutative functions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Primary parameters should be placed at the end to facilitate function composition.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Parameters that are least likely to change should be place leftmost to facilitate partially applied functions.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  DON'T:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Rely on function's length property.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use magic auto currying, that is, functions as return values are curried automatically.    &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Revealing Module Design Pattern</title>
      <dc:creator>Awais Akram Mughal</dc:creator>
      <pubDate>Wed, 17 Jun 2020 13:38:09 +0000</pubDate>
      <link>https://dev.to/iamawaisakram/revealing-module-design-pattern-5a27</link>
      <guid>https://dev.to/iamawaisakram/revealing-module-design-pattern-5a27</guid>
      <description>&lt;p&gt;&lt;em&gt;Defining all functions and variables in private scope and return an anonymous object with pointers to the private functionality we wished to reveal as public.&lt;/em&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;var&lt;/span&gt; &lt;span class="nx"&gt;myRevealingModule&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&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;privateVar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Awais Mughal&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;privateFunction&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;name: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;privateVar&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="nx"&gt;publicGetName&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;privateFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;getName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;publicGetName&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})()&lt;/span&gt;

&lt;span class="nx"&gt;myRevealingModule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getName&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// * name: Awais Mughal&lt;/span&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  How you can improve the readability in case of multiple functions?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Move the return object to the top, so when you look at the code days after writing, it'll be easy to know the public methods.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Focus on Naming conventions&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Advantages:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Syntax of our Script will be more consistent.&lt;/li&gt;
&lt;li&gt;readability&lt;/li&gt;
&lt;li&gt;Accessibility Concerns are handled &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Disadvantages:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If a private function refers to the public function, that public function can't be overridden wile using it on other places(calling the public function from another file) if a patch is necessary. &lt;strong&gt;WHY?&lt;/strong&gt; Because you can't manipulate the implementation of private function from outside.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Public Object members which refer to &lt;strong&gt;private variables&lt;/strong&gt; are also subject to the no-patch rule note above.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>codenewbie</category>
      <category>codequality</category>
    </item>
    <item>
      <title>Using Recoil With React</title>
      <dc:creator>Awais Akram Mughal</dc:creator>
      <pubDate>Mon, 01 Jun 2020 11:04:18 +0000</pubDate>
      <link>https://dev.to/iamawaisakram/using-recoil-with-react-4api</link>
      <guid>https://dev.to/iamawaisakram/using-recoil-with-react-4api</guid>
      <description>&lt;h2&gt;
  
  
  A new State Management Library for React
&lt;/h2&gt;

&lt;p&gt;If you would like to learn more about its need and the thought process behind it. Kindly go to: &lt;em&gt;&lt;a href="https://recoiljs.org/"&gt;Recoil Home Page&lt;/a&gt;&lt;/em&gt; and watch the video at the bottom of the page. &lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Firstly:&lt;/strong&gt;&lt;br&gt;
The basic use of Recoil is through the introduction of &lt;strong&gt;Atom&lt;/strong&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;atom&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;recoil&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;DataEntriesAtom&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;atom&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dataEntries&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// * unique Key (with respect to other atoms/selectors)&lt;/span&gt;
  &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="c1"&gt;// * default value (aka initial value)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code is self explanatory with comments.&lt;/p&gt;

&lt;p&gt;Here's how you use it in the component.&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="nx"&gt;React&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;react&lt;/span&gt;&lt;span class="dl"&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;useRecoilState&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;recoil&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;moment&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;moment&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="c1"&gt;// * Atoms&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;DataEntriesAtom&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;../../Recoil/Data/Atoms&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="c1"&gt;// * Style&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./index.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;props&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;logbookEntries&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setLogbookEntries&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useRecoilState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;DataEntriesAtom&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="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;logbook&lt;/span&gt;&lt;span class="dl"&gt;'&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="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;title-div&lt;/span&gt;&lt;span class="dl"&gt;'&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;p&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Logbook&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;logbook-result&lt;/span&gt;&lt;span class="dl"&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;logbookEntries&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="nx"&gt;entry&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&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="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;entry&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;date&lt;/span&gt;&lt;span class="dl"&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;moment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createdAt&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;MMMM Do YYYY&lt;/span&gt;&lt;span class="dl"&gt;'&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;/p&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;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;value&lt;/span&gt;&lt;span class="dl"&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;entry&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="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="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="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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;But What is the use of the Atom you ask?&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
If you're using the &lt;em&gt;DataEntriesAtom&lt;/em&gt; in any other component and you call the &lt;em&gt;setLogbookEntries&lt;/em&gt; from this component, Recoil monitors the change in that particular atom and only re-renders the component that is using this &lt;strong&gt;Atom&lt;/strong&gt;. Simple yet efficient.&lt;/p&gt;

&lt;p&gt;It reduces the boilerplate code that you have to write and let's say you have a DOM tree with two main branches that have no link to one another, but you want a node of the separate branch to change its value as soon as you change the value of the current branch.&lt;/p&gt;

&lt;p&gt;While using redux, you would have to write a lot of code to get this working. But in this case, just defining an atom with get it working. :)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Also, Notice that we are using useRecoilState imported from Recoil.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Secondly:&lt;br&gt;
Recoil Introduced &lt;strong&gt;Selector&lt;/strong&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;selector&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;recoil&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="c1"&gt;// * Atom&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;DataEntriesAtom&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;./Atoms&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// * API calls&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;GetDataEntriesAPI&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;../../Api/Data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;GetDataEntriesQuery&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dataEntriesQuery&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;async&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="o"&gt;=&amp;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;previousEntries&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;DataEntriesAtom&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;entries&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;GetDataEntriesAPI&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;previousEntries&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;concat&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="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Selectors represent derived state. You can think of derived state as the output of passing state to a pure function that modifies the given state in some way.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's Setup Recoil:
&lt;/h2&gt;

&lt;h2&gt;
  
  
  In you Parent JS File(In my case it's the index.js)
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;For Asynchronous calls: you can use Suspense, on calling the selector, Recoil will manage the loading of the Component for you.&lt;/em&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&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;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&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;react-dom&lt;/span&gt;&lt;span class="dl"&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;RecoilRoot&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;recoil&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="c1"&gt;// * Routes&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Routes&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;./Routes&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="c1"&gt;// * Styling&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./index.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="nx"&gt;ReactDOM&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;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;StrictMode&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;RecoilRoot&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;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Suspense&lt;/span&gt; &lt;span class="nx"&gt;fallback&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;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;Loading&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&amp;gt;}&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;Routes&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="sr"&gt;/React.Suspense&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;/RecoilRoot&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;/React.StrictMode&amp;gt;&lt;/span&gt;&lt;span class="err"&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;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&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;



</description>
      <category>javascript</category>
      <category>react</category>
      <category>recoil</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Getting Started with System Design!</title>
      <dc:creator>Awais Akram Mughal</dc:creator>
      <pubDate>Mon, 18 May 2020 09:56:46 +0000</pubDate>
      <link>https://dev.to/iamawaisakram/getting-started-with-system-design-48kk</link>
      <guid>https://dev.to/iamawaisakram/getting-started-with-system-design-48kk</guid>
      <description>&lt;h2&gt;
  
  
  Let's get you started with a real world example:
&lt;/h2&gt;

&lt;h1&gt;
  
  
  &lt;em&gt;Opening a Restaurant(A Pizza Parlour)&lt;/em&gt;
&lt;/h1&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Opening of the restaurant:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;You open up the restaurant with a single chef. There comes a point that A single chef can not handle all the orders.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;How would you then manage all the incoming orders then?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you think like a manager, You'll ask the chef to work harder 😁. And you'll pay them more: Put more money, get more output.&lt;/p&gt;

&lt;p&gt;Here: &lt;br&gt;
&lt;strong&gt;&lt;em&gt;We are Optimizing Processes and Increase Throughput Using the same resource.&lt;/em&gt;&lt;/strong&gt;  It's called &lt;strong&gt;Vertical Scaling&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The other thing you can do is: If the order is a pizza, you can have some ingredients/pieces prepared beforehand so when the order comes, less time is taken.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Preparing beforehand during non-peak hours&lt;/em&gt;&lt;/strong&gt;. It's termed as &lt;strong&gt;Pre-processing &amp;amp; Cron Job&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Let's make the business Resilient:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Let's say that chef calls in sick one day and you won't have any business that day, So the chef becomes a single point of failure.&lt;/p&gt;

&lt;p&gt;What you can do for this kind of emergency:&lt;/p&gt;

&lt;p&gt;Hire a backup chef, so, in case if the primary chef doesn't comes, you can employ the backup chef that day.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Keep backups and avoid single point of failure&lt;/em&gt;&lt;/strong&gt;.  &lt;strong&gt;Backups&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Aside from backups, what you can do is hire more primary and backup chefs.&lt;br&gt;
That's buy more resources. It's called &lt;strong&gt;Horizontal Scaling&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Let's Expand our Business:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Let's say you got 3 chefs in the Pizza shop and they have their specialties:&lt;br&gt;
chef 1 and chef 2 got specialty in Pizzas, while chef 3's specialty is in garlic bread.&lt;/p&gt;

&lt;p&gt;So, to efficiently get the orders done, when an order comes you can direct/route those orders according to the specialty of a chef.&lt;br&gt;
If the order is of a pizza, you can send it to either chef 1 or 2 according to their availability etc. If you want any change in the recipe of a garlic bread, chef 3 is your man.&lt;/p&gt;

&lt;p&gt;Let's make a team around the chefs that we have, &lt;br&gt;
Team1: totals chefs: 3, leading: Chef 3 (Getting all the Garlic Bread order)&lt;br&gt;
Team2: total chefs: 3, leading: Chef 2 &lt;br&gt;
Team3: total chefs: 4, leading: Chef 1&lt;br&gt;
(Team 2 and 3 get all the Pizza orders)&lt;/p&gt;

&lt;p&gt;Now all the pizza orders are being divided/routed towards the Team 2 and 3, while all the garlic bread orders are going to Team 1.&lt;/p&gt;

&lt;p&gt;What you're doing is that you are scaling these three teams at different rates and dividing the responsibilities among them.&lt;/p&gt;

&lt;p&gt;What we have here now is a &lt;strong&gt;Micro-Services Architecture&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;At this point your restaurant/Shop is doing pretty well, able to handle different orders and this business is scale-able to a large extent.&lt;/p&gt;

&lt;p&gt;But, What if, there is an electricity outage in this shop? You won't have business that day.&lt;br&gt;
What if you loose licence that day? You won't have business that day.&lt;/p&gt;

&lt;p&gt;You don't want your eggs in a single basket, you want a separate shop, in a different place may not have the same number of chefs, but, at-least you have a backup.&lt;/p&gt;

&lt;p&gt;Now, we create a new shop &lt;strong&gt;SHOP 2&lt;/strong&gt;. This is very we take complexity to a new level. An advantage of shop 2 is that orders close to its range, can be served by it.&lt;/p&gt;

&lt;p&gt;Now if you receive an order, you need to be able to route it that either you want this order to be sent to &lt;strong&gt;SHOP 1&lt;/strong&gt; or &lt;strong&gt;SHOP 2&lt;/strong&gt;. This is called a &lt;strong&gt;Distributed System&lt;/strong&gt;.(partitioning) &lt;br&gt;
It's more response tolerant and gives a quicker response time.&lt;/p&gt;

&lt;p&gt;Now let's say you have a customer who sent its order to the Central Authority(the routing mechanism), but you need some specific requirements to route that order to either &lt;strong&gt;SHOP 1&lt;/strong&gt; or &lt;strong&gt;SHOP 2&lt;/strong&gt;. The parameter can be the delivery time.&lt;/p&gt;

&lt;p&gt;Let's say, if you send the order to the &lt;strong&gt;SHOP 1&lt;/strong&gt;, it takes 1.5 hours for it to deliver to the customer, as it's a popular shop. But the &lt;strong&gt;SHOP 2&lt;/strong&gt; only takes 1 hour to deliver the order.&lt;/p&gt;

&lt;p&gt;So, the central authority should route the order to the &lt;strong&gt;SHOP 2&lt;/strong&gt;, and as long as the Central Mechanism is getting real time updates, It can make &lt;strong&gt;smart business decisions&lt;/strong&gt;, which means, &lt;strong&gt;more money&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;This central Mechanism is called &lt;strong&gt;Load Balancer&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;At this point, The System is:&lt;br&gt;
Scalable and Fault Tolerant.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to make it Future Proof?&lt;/strong&gt;(Extensibility).&lt;/p&gt;

&lt;p&gt;You have a delivery agent and a pizza shop, and they have nothing in common, The delivery agent's concern is to only deliver the order as quickly as possible to the customer, while the shop's concern is to prepare the order as quickly as possible, it does not cares who is going to pick the order up.&lt;/p&gt;

&lt;p&gt;We can see the separation in responsibilities. It's called &lt;strong&gt;Decoupling the System&lt;/strong&gt;. (Separating out the concerns).&lt;/p&gt;

&lt;p&gt;Let's say, &lt;strong&gt;SHOP 1's&lt;/strong&gt; oven becomes faulty or the &lt;strong&gt;Delivery agent's&lt;/strong&gt; bike becomes faulty. You need all the events(logs) happening in present or that have already happened. It's called &lt;strong&gt;Logging and Metrics&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Most Important Point&lt;/strong&gt;, as a back-end engineer, you need to make your system as extensible as possible, you do not need to rewrite your code again and again to serve a different purpose.&lt;/p&gt;

&lt;p&gt;For example, &lt;strong&gt;Delivery Agent&lt;/strong&gt; doesn't need to know that it's delivery a Pizza, it could be a burger tomorrow. &lt;strong&gt;Extensible&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Finally, Now we are able to scale our business.&lt;/p&gt;

&lt;p&gt;Let's recap and see what are the High level problems that we faced and how we resolved them:&lt;/p&gt;

&lt;p&gt;Following is know as &lt;strong&gt;HIGH LEVEL DESIGN&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Order Overload --&amp;gt; Recruitment
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Complexity --&amp;gt; Separation of Concern
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Mishaps --&amp;gt; Fault Tolerance
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;LOW LEVEL DESIGN&lt;/strong&gt; has a lot to do with how you code, making classes, objects, functions, signature.&lt;/p&gt;

</description>
      <category>design</category>
      <category>architecture</category>
      <category>microservices</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>System Design Basics: Horizontal vs Vertical Scaling</title>
      <dc:creator>Awais Akram Mughal</dc:creator>
      <pubDate>Thu, 23 Apr 2020 07:27:39 +0000</pubDate>
      <link>https://dev.to/iamawaisakram/system-design-basics-horizontal-vs-vertical-scaling-39b6</link>
      <guid>https://dev.to/iamawaisakram/system-design-basics-horizontal-vs-vertical-scaling-39b6</guid>
      <description>&lt;h2&gt;
  
  
  Let's understand this concept through a story:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mughal&lt;/strong&gt; &lt;em&gt;accidentally&lt;/em&gt; made a script and it is running on a local computer, he writes some documentation and makes it public for people to look at.&lt;/p&gt;

&lt;p&gt;Now some folks find this functionality very useful and they contact him and tells him that they'll pay for this scripts usage.&lt;/p&gt;

&lt;p&gt;So, Mughal Makes an &lt;strong&gt;API&lt;/strong&gt; and exposes the script functionality to them, but it's still running on a computer that he has and he can't keep it running forever, there might be a power outage or it shuts down accidentally, that's quite a problem.&lt;/p&gt;

&lt;p&gt;He decides to host/deploy his script on a cloud, which is essentially another computer somewhere, but all the maintenance is provided and you just need to login and do your thing, your immediate concerns are taken care of.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now&lt;/strong&gt;, the usage of your scripts functionality is made popular and many other people also want to implement its usage, but more the implementation, more the traffic and more the computational power required to handle those requests sent to the API.&lt;/p&gt;

&lt;p&gt;So, He got 2 options:&lt;br&gt;
&lt;strong&gt;1:&lt;/strong&gt; Buy Bigger machine or make computational power of existing machine strong.&lt;br&gt;
&lt;strong&gt;2:&lt;/strong&gt; Buy more machines with the somewhat same computational power, so the requests can be distributed among them.&lt;/p&gt;

&lt;p&gt;Here, &lt;strong&gt;Option 1&lt;/strong&gt; is called &lt;strong&gt;Vertical Scaling&lt;/strong&gt;, which means that you're upgrading your existing machine with regards to your need, while &lt;strong&gt;Option 2&lt;/strong&gt; is called &lt;strong&gt;Horizontal Scaling&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Now, let's compare the &lt;strong&gt;Horizontal&lt;/strong&gt; and &lt;strong&gt;Vertical&lt;/strong&gt; Scaling:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1:&lt;/strong&gt; In case of &lt;strong&gt;Horizontal Scaling&lt;/strong&gt;, you need an &lt;strong&gt;&lt;em&gt;Load Balancer&lt;/em&gt;&lt;/strong&gt; to manage the request pouring in and have them consistent with every machine. While it is not required in the &lt;strong&gt;Vertical Scaling&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2:&lt;/strong&gt; &lt;strong&gt;Horizontal Scaling&lt;/strong&gt; is &lt;strong&gt;&lt;em&gt;Data Resilient&lt;/em&gt;&lt;/strong&gt;, which means that if one machine is powered off(let's say), other machines can handle its requests. While that is not the case in the &lt;strong&gt;Vertical Scaling&lt;/strong&gt;, there is only a single point of failure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3:&lt;/strong&gt; We have many machines involved in &lt;strong&gt;Horizontal Scaling&lt;/strong&gt;, so the communication between them is done through the &lt;strong&gt;&lt;em&gt;Network calls&lt;/em&gt;&lt;/strong&gt;, which makes it a little slow, while on the other side we have a single machine and it uses &lt;strong&gt;&lt;em&gt;Inter Process Communication&lt;/em&gt;&lt;/strong&gt;, which is quite fast.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4:&lt;/strong&gt; Let's say in &lt;strong&gt;Horizontal Scaling&lt;/strong&gt;, machines are communicating with each other and tasks might be dependent, like &lt;strong&gt;machine 1&lt;/strong&gt; sends data to &lt;strong&gt;machine 2&lt;/strong&gt;, then &lt;strong&gt;machine 2&lt;/strong&gt; sends it to &lt;strong&gt;machine 4&lt;/strong&gt;, here, you can see that data is complicated to maintain, so if this kind of transaction is happening, what happens is that we have to lock all the databases, which is impractical and because of which we have this issue of &lt;strong&gt;&lt;em&gt;loose transactional guarantee&lt;/em&gt;&lt;/strong&gt;, and this is called &lt;strong&gt;&lt;em&gt;Data Inconsistency&lt;/em&gt;&lt;/strong&gt;, which is quite a big issue. While it's not the case in &lt;strong&gt;Vertical Scaling&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5:&lt;/strong&gt; Very important point, there's gonna come a point when you just can't upgrade your existing computer, it's the &lt;strong&gt;Hardware Limit&lt;/strong&gt;, In this scenario, &lt;strong&gt;Horizontal Scaling&lt;/strong&gt; Scales well as the number of Users increases.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Question is: What is being used in the real world?
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;Answer&lt;/strong&gt; is &lt;strong&gt;&lt;em&gt;Both&lt;/em&gt;&lt;/strong&gt;, What happens is that we start with &lt;strong&gt;Horizontal Scaling&lt;/strong&gt; and &lt;strong&gt;Vertical Scale&lt;/strong&gt; Every Machine as possible, and we take Strong points from both types, &lt;/p&gt;

&lt;p&gt;We take:&lt;br&gt;
Resilience and User Scaling from &lt;strong&gt;Horizontal Scaling&lt;/strong&gt;&lt;br&gt;
Inter Process Communication and Data Consistency from &lt;strong&gt;Vertical Scaling&lt;/strong&gt; &lt;/p&gt;

</description>
      <category>design</category>
      <category>architecture</category>
      <category>codenewbie</category>
      <category>microservices</category>
    </item>
    <item>
      <title>Web First or Mobile First UI Improvement?</title>
      <dc:creator>Awais Akram Mughal</dc:creator>
      <pubDate>Mon, 20 Apr 2020 05:29:34 +0000</pubDate>
      <link>https://dev.to/iamawaisakram/web-first-or-mobile-first-ui-improvement-5mf</link>
      <guid>https://dev.to/iamawaisakram/web-first-or-mobile-first-ui-improvement-5mf</guid>
      <description>&lt;p&gt;&lt;em&gt;When you're asked to improve the UI of an already hosted/build Web Application, We always have this thought of should I go with Mobile First Design Improvement or Web First? What Breakpoints Should I use for better responsiveness?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;We'll be looking into it, in this post!&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;What I do is that, I always ask for analytics panel's credentials or permission to view the analytics console of the Web Application.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;First:&lt;/strong&gt; Let's look into how to look for best possible Breakpoints for the Website?
&lt;/h2&gt;

&lt;p&gt;One way is to go in Analytics Console, go to: &lt;strong&gt;Audience&lt;/strong&gt; -&amp;gt; &lt;strong&gt;Technology&lt;/strong&gt; -&amp;gt; &lt;strong&gt;Browser &amp;amp; OS&lt;/strong&gt;  -&amp;gt; Click on &lt;strong&gt;Screen resolution&lt;/strong&gt; Tab.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OIR4dHqw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/iamawaisakram/Posts-Images/blob/master/Web-First-or-Mobile-First-UI-Improvement/Screenshot%25202020-04-19%2520at%252011.37.15%2520AM.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OIR4dHqw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/iamawaisakram/Posts-Images/blob/master/Web-First-or-Mobile-First-UI-Improvement/Screenshot%25202020-04-19%2520at%252011.37.15%2520AM.png%3Fraw%3Dtrue" alt="alt text" title="breakpoints screen" width="880" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here you'll get the screen resolutions of the devices, ordered accordingly to the number of users accessing this Website.&lt;br&gt;
You can prioritise the breakpoint accordingly if you want here.&lt;/p&gt;

&lt;p&gt;Second way is to go to this &lt;a href="https://www.w3schools.com/browsers/browsers_display.asp"&gt;link&lt;/a&gt;&lt;br&gt;
where you'll see the screen resolution statistics and you can plan accordingly as well.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cUy6tBqm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/iamawaisakram/Posts-Images/blob/master/Web-First-or-Mobile-First-UI-Improvement/Screenshot%25202020-04-20%2520at%252010.27.40%2520AM.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cUy6tBqm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/iamawaisakram/Posts-Images/blob/master/Web-First-or-Mobile-First-UI-Improvement/Screenshot%25202020-04-20%2520at%252010.27.40%2520AM.png%3Fraw%3Dtrue" alt="alt text" title="screen resolutions" width="880" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Secondly:&lt;/strong&gt; How to make a decision between Web First Design improvement and Mobile First Design improvement?
&lt;/h2&gt;

&lt;p&gt;In Analytics Console, go to: &lt;strong&gt;Audience&lt;/strong&gt; -&amp;gt; &lt;strong&gt;Mobile&lt;/strong&gt; -&amp;gt; &lt;strong&gt;Overview&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BsZyW0Ff--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/iamawaisakram/Posts-Images/blob/master/Web-First-or-Mobile-First-UI-Improvement/Screenshot%25202020-04-19%2520at%252011.37.46%2520AM.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BsZyW0Ff--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/iamawaisakram/Posts-Images/blob/master/Web-First-or-Mobile-First-UI-Improvement/Screenshot%25202020-04-19%2520at%252011.37.46%2520AM.png%3Fraw%3Dtrue" alt="alt text" title="First Image" width="880" height="419"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here you'll be able to see three rows &lt;strong&gt;Desktop&lt;/strong&gt;, &lt;strong&gt;Mobile&lt;/strong&gt;, &lt;strong&gt;Tablet&lt;/strong&gt;, you can make a decision on the basis of number of users as per device.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>css</category>
      <category>uiimprovement</category>
    </item>
    <item>
      <title>Generators and Async/Await Comparison</title>
      <dc:creator>Awais Akram Mughal</dc:creator>
      <pubDate>Thu, 16 Apr 2020 09:02:05 +0000</pubDate>
      <link>https://dev.to/iamawaisakram/generators-and-async-await-comparison-24e7</link>
      <guid>https://dev.to/iamawaisakram/generators-and-async-await-comparison-24e7</guid>
      <description>&lt;h2&gt;
  
  
  What is a Generator?
&lt;/h2&gt;

&lt;p&gt;There is an introduction in ES6 to a new way of working with functions and iterators as generator functions. A generator is a function that gives the power of execution in the hands of the user, what it does is that it can stop at a specific point and returns the power of execution from that point onwards to the user. In short, a generator appears to be a function but it behaves like an iterator. Let's discuss it with an example and comparison with Async/Await.&lt;/p&gt;

&lt;h1&gt;
  
  
  Example
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Generator:
&lt;/h2&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="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;generator&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="c1"&gt;// yield Keyword is where the execution stops and an object is returned&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nx"&gt;getUserFromDB&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; Correctly Received&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;iterator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;generator&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// It will run the generator function up to the first yeild keyword&lt;/span&gt;
&lt;span class="c1"&gt;// But the execution will be halted right after calling the 'getUserFromDB' function but right before assigning it to the const user(Very important to note here)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;iteration&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;iterator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;  

&lt;span class="c1"&gt;// Generator returns an Object after calling the next() function&lt;/span&gt;
&lt;span class="c1"&gt;// iteration will return the unresolved promise {value: Promise{}, done: false}&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;iteration&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Why is the done's value false? &lt;/span&gt;
&lt;span class="c1"&gt;// You need to understand that, the last yield keyword is like the return statement in the normal function&lt;/span&gt;
&lt;span class="c1"&gt;// while previous yield keywords are like mini returns but they do not terminate the generator&lt;/span&gt;
&lt;span class="c1"&gt;// Only the final yield keyword returns the done:true because it tells that the generator function is now completed, its state is moved to "completed" state.&lt;/span&gt;

&lt;span class="c1"&gt;// It is called when the promise resolves&lt;/span&gt;
&lt;span class="nx"&gt;iteration&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;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;resolvedValue&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resolvedValue&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// let's say it's "Got some Users"&lt;/span&gt;

  &lt;span class="c1"&gt;// Now, we can continue the execution by&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;nextIteration&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;iterator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resolvedValue&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Notice, we are using the very first const we initialised with&lt;/span&gt;
  &lt;span class="c1"&gt;// Another amazing thing to notice&lt;/span&gt;
  &lt;span class="c1"&gt;// We can pass the value to the generator function as well&lt;/span&gt;
  &lt;span class="c1"&gt;// Which can become the part of the next returned object :-)&lt;/span&gt;


  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nextIteration&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
  &lt;span class="c1"&gt;// We get the final value: {value: "Got some Users Correctly Received", done: true}&lt;/span&gt;
  &lt;span class="c1"&gt;// See, Now Done is true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Async/Await:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&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;testing&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;users&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;getUsersFromDB&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; Correctly Received&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;// That's it with async/await :p &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;The async function declaration defines an asynchronous function — a function that is an AsyncFunction object. Asynchronous functions operate in a separate order than the rest of the code via the event loop, returning an implicit Promise as its result. But the syntax and structure of code using async functions looks like standard synchronous functions.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the difference between &lt;em&gt;"Await"&lt;/em&gt; and &lt;em&gt;"Yield"&lt;/em&gt; Keywords you ask?
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Yield&lt;/em&gt; can be considered to be the binding block of &lt;em&gt;await&lt;/em&gt;. Yield takes the value it's given and passes it to its caller.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The caller can do whatever it wishes with that value&lt;/li&gt;
&lt;li&gt;Later the caller may give a value back to the generator(via generator.next()), which becomes the result of the yield expression.&lt;/li&gt;
&lt;li&gt;Or an error that will appear to be thrown by the yield expression.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;async-await&lt;/em&gt; can be considered to use &lt;em&gt;yield&lt;/em&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;At the caller(i.e. the async-await driver) will wrap the value in a promise using a similar algorithm to new Promise(r =&amp;gt; r(value)) (note, not Promise.resolve, but that's not a big deal).&lt;/li&gt;
&lt;li&gt;It then waits for the promise to resolve. If it fulfils, it passes the fulfilled value back.&lt;/li&gt;
&lt;li&gt;If it rejects, it throws the rejection reason as an error.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  In this Answer's Summary:
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Utility of async-await is to use yield and unwrap the yielded value as a promise and pass it's resolved value back, repeating until the function returns its final value.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Now there's an another question: &lt;em&gt;Is it possible to reset Generator?&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Once a generator enters the "completed" state, it never leaves it and its associated execution context is never resumed. Any execution state associated with generator can be discarded at this point.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  That's it for today folks.
&lt;/h3&gt;

</description>
      <category>javascript</category>
      <category>asynchronous</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
