<?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: Siddharth Sharma</title>
    <description>The latest articles on DEV Community by Siddharth Sharma (@hearsid).</description>
    <link>https://dev.to/hearsid</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%2F966049%2Fc544add3-7035-427f-86f7-5cae20d3f530.jpeg</url>
      <title>DEV Community: Siddharth Sharma</title>
      <link>https://dev.to/hearsid</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hearsid"/>
    <language>en</language>
    <item>
      <title>Reactive Programming- Part I</title>
      <dc:creator>Siddharth Sharma</dc:creator>
      <pubDate>Tue, 05 Mar 2024 17:32:05 +0000</pubDate>
      <link>https://dev.to/hearsid/reactive-programming-part-i-5cji</link>
      <guid>https://dev.to/hearsid/reactive-programming-part-i-5cji</guid>
      <description>&lt;h4&gt;
  
  
  ReactiveX
&lt;/h4&gt;

&lt;p&gt;What is ReactiveX?&lt;br&gt;
ReactiveX (Rx) is a programming paradigm and library that focuses on asynchronous programming using observable sequences.&lt;/p&gt;

&lt;p&gt;Why to use ReactiveX?&lt;br&gt;
ReactiveX provides API to treat and consume asynchronous stream of data originating from various sources e.g: Sensor readings, News Updates etc. in an concise and easy way, thus making it easy to develop and maintain asynchronous data.&lt;/p&gt;

&lt;h4&gt;
  
  
  Hot vs cold observables
&lt;/h4&gt;

&lt;p&gt;Cold Observables&lt;br&gt;
Sequences that start producing notifications per subscription. It starts producing data only when a subscriber subscribes to it.&lt;/p&gt;

&lt;p&gt;Hot Observables&lt;br&gt;
Sequence that starts producing notifications regardless of subscriptions. Subscribers that join later might miss some of the initial data.&lt;/p&gt;

&lt;h4&gt;
  
  
  Rxjs
&lt;/h4&gt;

&lt;p&gt;RxJS is a implementation of Reactive Extensions (ReactiveX) for Javascript and TypeScript ReactiveX was developed by Erik Meijer at Microsoft. Open sourced in 2012 Used by GitHub, Netflix, SoundCloud, AirBnb and others Reactive Extensions is Cross Platform (available for Java, C#, C++, JavaScript, Python, and more)&lt;/p&gt;

&lt;h4&gt;
  
  
  Patterns used
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The Observer Pattern&lt;/li&gt;
&lt;li&gt;The Iterator Pattern&lt;/li&gt;
&lt;li&gt;Functional programming concepts&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Observer Pattern
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Observer&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Observer&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="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="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; received message: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Subject&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Subject&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;observers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;addObserver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;observers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;removeObserver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;observers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;observers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obs&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;obs&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;observers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Usage&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;subject&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;Subject&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;observer1&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;Observer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Observer 1&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;observer2&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;Observer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Observer 2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addObserver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addObserver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello, observers!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeObserver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;observer2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Observers after removal.&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;h4&gt;
  
  
  Iterator Pattern
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The Iterator pattern is a behavioral design pattern that provides a way to access the elements of a collection (such as an array or list) without exposing the underlying representation. It allows you to traverse through the elements sequentially, abstracting away the details of how the traversal is implemented.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Iterator&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Iterator&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;collection&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;hasNext&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&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;collection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;next&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasNext&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Collection&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Collection&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;addItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;getIterator&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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Iterator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Usage&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;collection&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;Collection&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Item 3&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;iterator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getIterator&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;iterator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hasNext&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="nx"&gt;iterator&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Key Functional Programming Concepts
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Pure Functions: Pure functions are functions that always produce the same output for the same input and have no side effects. They don't modify data outside their scope or rely on external state. Pure functions promote predictability, testability, and composability.&lt;/li&gt;
&lt;li&gt;Immutability: Functional programming encourages immutability, which means that once a data structure or value is created, it cannot be modified. Instead, new values are created when transformations or modifications are required. This avoids unintended side effects and makes reasoning about code easier.&lt;/li&gt;
&lt;li&gt;Higher-Order Functions: In functional programming, functions are treated as first-class citizens. This means that functions can be assigned to variables, passed as arguments to other functions, and returned as results from functions. Higher-order functions are functions that either take other functions as arguments or return functions.&lt;/li&gt;
&lt;li&gt;Function Composition: Functional programming promotes composing functions to create more complex behavior. Function composition involves chaining or combining multiple functions together to create a new function. It allows for modular and reusable code.&lt;/li&gt;
&lt;li&gt;Recursion: Recursion is a technique where a function calls itself to solve a problem. Functional programming often relies on recursion instead of iterative loops. Recursive functions break down complex problems into simpler subproblems, which can lead to elegant and concise code.&lt;/li&gt;
&lt;li&gt;Immutable Data Structures: Functional programming favors immutable data structures, such as lists, sets, and maps, that don't change after creation. Instead of modifying these data structures, functional programming encourages creating new instances with modifications. Immutable data structures provide safety and make it easier to reason about program behavior.&lt;/li&gt;
&lt;li&gt;Referential Transparency: Referential transparency means that a function can be replaced with its resulting value without changing the program's behavior. It enables reasoning about code by allowing expressions to be evaluated independently of their context.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Operators
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;map&lt;/code&gt;: Transforms the items emitted by an Observable by applying a function to each item and returning the transformed result.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;filter&lt;/code&gt;: Filters items emitted by an Observable based on a predicate function, allowing only those items that satisfy the condition to pass through.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;mergeMap&lt;/code&gt; (also known as &lt;code&gt;flatMap&lt;/code&gt;): Projects each source item to an Observable and merges the emissions from those Observables into a single stream. It allows for concurrent inner subscriptions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;switchMap&lt;/code&gt;: Projects each source item to an Observable, cancels the previous inner Observable (if any), and emits the values from the most recent inner Observable. Useful for scenarios like canceling ongoing requests when a new request is made.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;concatMap&lt;/code&gt;: Projects each source item to an Observable and concatenates the emissions from those Observables, ensuring that the order of emissions is preserved.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;debounceTime&lt;/code&gt;: Emits a value from the source Observable only after a specified amount of silence, ignoring any new values emitted during that period. Useful for scenarios like search input throttling.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;distinctUntilChanged&lt;/code&gt;: Emits a value from the source Observable only if it is different from the previous value. It ensures that only distinct consecutive values are emitted.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;takeUntil&lt;/code&gt;: Emits values from the source Observable until another Observable emits a value. After that, it completes and stops emitting further values.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;retry&lt;/code&gt;: Resubscribes to the source Observable if it encounters an error, allowing for a specified number of retries.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;catchError&lt;/code&gt; (or &lt;code&gt;catch&lt;/code&gt;): Catches errors emitted by the source Observable and substitutes them with another Observable or a default value, allowing graceful error handling.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>rxjs</category>
      <category>reactivex</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>Angular VS React: Performance comparison with Google Web Vitals</title>
      <dc:creator>Siddharth Sharma</dc:creator>
      <pubDate>Sat, 05 Nov 2022 14:47:33 +0000</pubDate>
      <link>https://dev.to/hearsid/angular-vs-react-performance-comparison-with-google-web-vitals-2c28</link>
      <guid>https://dev.to/hearsid/angular-vs-react-performance-comparison-with-google-web-vitals-2c28</guid>
      <description>&lt;p&gt;&lt;strong&gt;Target Audience:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Software Developers/ Technical Managers who want to compare performance metrics of Angular and React to get better perspective about which one of these is more suitable for an upcoming project.&lt;/p&gt;

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

&lt;p&gt;Angular is a JavaScript framework built by Google, while React is a Javascript library built by Facebook. Angular is mostly used to build complex CRUD applications quickly, while React makes it possible to build apps that need to show a lot of data and need frequent and fast data update with its virtual DOM concept.&lt;/p&gt;

&lt;p&gt;This post is going to compare the performance difference between React and Angular in terms of:&lt;br&gt;&lt;br&gt;
1) App bundle size (JS files only) &lt;br&gt;
2) Heap size&lt;br&gt;
3) DOM nodes&lt;br&gt;
4) DOM Content Loaded (DCL)&lt;br&gt;
5) First Contentful Paint (FCP)&lt;br&gt;
6) Largest Contentful Paint (LCP)&lt;br&gt;
7) Time To Interactive (TTI)&lt;br&gt;
8) Scripting time&lt;br&gt;
9) Rendering time&lt;/p&gt;

&lt;p&gt;We will be comparing the data from &lt;strong&gt;Performance, Memory, Lighthouse, Performance insights (its still a preview feature) and Network tab&lt;/strong&gt; of Chrome Devtools for a simple application (Contact manager) created in both &lt;strong&gt;React (v18.2.0)&lt;/strong&gt; and &lt;strong&gt;Angular (v14.2.6)&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Contact Manager Application
&lt;/h2&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%2Fgceon7qs6zzong6r3tv6.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%2Fgceon7qs6zzong6r3tv6.png" alt="Preview Contact Manager application"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are going to create Contact manager application in both React and Angular. Angular application was created using &lt;strong&gt;Angular CLI&lt;/strong&gt; and React application using &lt;strong&gt;Create React App (CRA)&lt;/strong&gt;. The application will have some contacts by default and will have option to increase number of contacts, to allow you to compare these with different number nodes. There is option to provide a &lt;strong&gt;query parameter in the URL, no_of_contacts&lt;/strong&gt; so that we can dynamically provide the number of contacts to be generated. In this article, we will be looking at performance results for 1,000 contacts.&lt;/p&gt;

&lt;p&gt;If you would like to check the application’s performance for a different set of contact number, the &lt;strong&gt;applications can be accessed by the URL provided or cloned from Github repo link provided&lt;/strong&gt; at bottom of article.&lt;br&gt;&lt;br&gt;
NOTE: I have tried to list most accurate readings but there are factors like latency and caching etc which could have affected them.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Table of readings (For 1,000 Contacts)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dev.tourl"&gt;https://gist.github.com/hearsid/6d125d91283cd30c3ff958ef6e1e4e54#file-table-of-readings-1k-md&lt;/a&gt;&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%2Fgb2q7nvf6gp7zfjpu3mm.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%2Fgb2q7nvf6gp7zfjpu3mm.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup Details
&lt;/h2&gt;

&lt;p&gt;Hosting: Github pages&lt;br&gt;&lt;br&gt;
Angular stack: Angular v14.2.6 with default packages.&lt;br&gt;&lt;br&gt;
React stack: React (v18.2), react-router-dom, Typescript.&lt;/p&gt;

&lt;p&gt;Lets dive in and see how the above reading were taken and how they contribute in enhancing the performance of our application.&lt;/p&gt;

&lt;h2&gt;
  
  
  1) Application Bundle Size
&lt;/h2&gt;

&lt;p&gt;Application size decides the download time of the files by the browser and plays an important role, specially when the application size is very big or our target audience may be using slow internet connection. The pictures below are of the tab of chrome dev tools and the application size shown in the above table has been calculated by adding the JS file size. The file size can also be checked from the lighthouse report.&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%2F1xu7tljm63yjhl0dgwm2.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%2F1xu7tljm63yjhl0dgwm2.png" alt="React Contact manager network tab"&gt;&lt;/a&gt;&lt;br&gt;
1.1 Angular Contact manager network tab&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%2Ff4leh8rfw3n34vhl56zr.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%2Ff4leh8rfw3n34vhl56zr.png" alt="Angular Contact manager network tab"&gt;&lt;/a&gt;&lt;br&gt;
1.2 React Contact manager network tab&lt;/p&gt;

&lt;h2&gt;
  
  
  2) Heap size
&lt;/h2&gt;

&lt;p&gt;Memory tab is going to show the memory distribution by the page’s JavaScript objects and related DOM nodes. Readings for both Angular and React look fine as for our application.&lt;/p&gt;

&lt;h2&gt;
  
  
  3) DOM nodes
&lt;/h2&gt;

&lt;p&gt;This is crucial since a template parser’s internal compilation of the templates may result in the insertion of a few extra DOM nodes. Lesser the node elements, lighter the DOM tree, the better it is. But in our case the number of DOM nodes are same for Angular and React.&lt;/p&gt;

&lt;h2&gt;
  
  
  4) DCL- DOM Content Loaded
&lt;/h2&gt;

&lt;p&gt;When the HTML document has been fully parsed and all deferred scripts have downloaded and run, the DOMContentLoaded event is fired. It doesn’t wait for other elements like as async scripts, subframes and pictures to finish loading. In the below screenshot and for comparison &lt;strong&gt;best of 3 readings&lt;/strong&gt; been taken. We can take readings for these Web vitals from Performance and Lighthouse tab as well. The application looks like this or with less styling after DOM Content Loaded event.&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%2Fam1j5yk0z8ddvj5lladc.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%2Fam1j5yk0z8ddvj5lladc.png" alt="Application after DCL"&gt;&lt;/a&gt;&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%2Fxhybzvrs401f5a2hmglb.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%2Fxhybzvrs401f5a2hmglb.png" alt="Angular app DCL, FCP, TTI, LCP"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4.2 Angular app DCL, FCP, TTI, LCP&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%2Fu59votwnoz9pu2uf7ttn.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%2Fu59votwnoz9pu2uf7ttn.png" alt="React app DCL, FCP, TTI, LCP"&gt;&lt;/a&gt;&lt;br&gt;
4.3 React app DCL, FCP, TTI, LCP&lt;/p&gt;

&lt;h2&gt;
  
  
  5) FCP- First Contentful Paint
&lt;/h2&gt;

&lt;p&gt;First Contentful Paint (FCP) is when the browser renders the first bit of content from the DOM, providing the first feedback to the user that the page is actually loading. The appliation should looks like this after FCP.&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%2Fymfp5pszfm5jn4ol0wyz.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%2Fymfp5pszfm5jn4ol0wyz.png" alt="First contentful paint"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5.1 Application after FCP&lt;/p&gt;

&lt;h2&gt;
  
  
  6) LCP- Largest Contentful Paint
&lt;/h2&gt;

&lt;p&gt;LCP measures the time from when the user initiates loading the page until the largest image or text block is rendered within the viewport.&lt;/p&gt;

&lt;h2&gt;
  
  
  7) TTI- Time To Interactive
&lt;/h2&gt;

&lt;p&gt;The TTI metric measures the time from when the page starts loading to when its main sub-resources have loaded and it is capable of reliably responding to user input quickly. &lt;strong&gt;Our application should be completely loaded after this.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  8) Scripting time
&lt;/h2&gt;

&lt;p&gt;How much of the total time was spent in scripting phase by the framework. There is significant difference in this for Angular and React,&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%2Fhwi2s6nslqu68r0x7sqm.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%2Fhwi2s6nslqu68r0x7sqm.png" alt="Angular app Performance app"&gt;&lt;/a&gt;&lt;br&gt;
8.1 Angular app Performance app&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%2F3lj17z2z49rwyno2jgjr.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%2F3lj17z2z49rwyno2jgjr.png" alt="React app Performance tab"&gt;&lt;/a&gt;&lt;br&gt;
8.2 React app Performance tab&lt;/p&gt;

&lt;h2&gt;
  
  
  9) Rendering Time
&lt;/h2&gt;

&lt;p&gt;How much of the total time was spent in the rendering phase by the frameworks.&lt;/p&gt;

&lt;h2&gt;
  
  
  10) Onload event
&lt;/h2&gt;

&lt;p&gt;The load event is fired when the whole page has loaded, including all dependent resources such as stylesheets and images. This is in contrast to DOM Content Loaded event, which is fired as soon as the page DOM has been loaded, without waiting for resources to finish loading.&lt;/p&gt;

&lt;h2&gt;
  
  
  Repository links:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://github.com/hearsid/ng-contact-manager" rel="noopener noreferrer"&gt;Angular Contact manager Github repository&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://github.com/hearsid/react-contact-manager" rel="noopener noreferrer"&gt;React Contact manager Github repository&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Application links:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://hearsid.com/ng-contact-manager/#/contacts?no_of_contacts=100" rel="noopener noreferrer"&gt;Angular Contact manager application link&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://hearsid.com/react-contact-manager/?no_of_contacts=100" rel="noopener noreferrer"&gt;React Contact manager application link&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

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