<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pushpak Sharma on Medium]]></title>
        <description><![CDATA[Stories by Pushpak Sharma on Medium]]></description>
        <link>https://medium.com/@pushpak.sharma?source=rss-709fe7a7dafe------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QRqNZ_8yZYuCAU6vYaPe4Q.jpeg</url>
            <title>Stories by Pushpak Sharma on Medium</title>
            <link>https://medium.com/@pushpak.sharma?source=rss-709fe7a7dafe------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 03:51:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pushpak.sharma/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[divide and conquer | Nuts & Bolts Problem]]></title>
            <link>https://medium.com/@pushpak.sharma/divide-and-conquer-nuts-bolts-problem-92082115a056?source=rss-709fe7a7dafe------2</link>
            <guid isPermaLink="false">https://medium.com/p/92082115a056</guid>
            <category><![CDATA[java-algorithm]]></category>
            <category><![CDATA[divide-and-conquer]]></category>
            <category><![CDATA[placement-and-interview]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Pushpak Sharma]]></dc:creator>
            <pubDate>Wed, 12 Dec 2018 16:52:11 GMT</pubDate>
            <atom:updated>2018-12-12T17:12:56.865Z</atom:updated>
            <content:encoded><![CDATA[<p>Application on <strong>Algorithmic Paradigm:</strong> Divide and Conquer</p><h4>Problem Statement:-</h4><p>Set of n nuts of different sizes and n bolts of different sizes. There is a one-one mapping between nuts and bolts. Match nuts and bolts efficiently</p><p><strong>Approach 1: Brute Force</strong></p><p>time complexity 0(n²)</p><p><strong>Approach 2: Quick Sort Way</strong></p><p>average time complexity 0(n log n)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JbLU5sdWD2RGjAtaHEtW9Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kMQH7ueUvAp9bI98gbjSWA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BifeAuVEDsbDz87nr5KsfQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W9faJxYF8Xqw5_B7ymQTZw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lcTmOQVeFXo5OQgPQQqziw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xjRVtZUW3UUeUICLnKdMQg.png" /></figure><pre>public class NutsAndBoltsMatch</pre><pre>{</pre><pre>//Driver method</pre><pre>public static void main(String[] args)</pre><pre>{</pre><pre>// Nuts and bolts are represented as array of characters</pre><pre>char nuts[] = {&#39;@&#39;, &#39;#&#39;, &#39;$&#39;, &#39;%&#39;, &#39;^&#39;, &#39;&amp;&#39;};</pre><pre>char bolts[] = {&#39;$&#39;, &#39;%&#39;, &#39;&amp;&#39;, &#39;^&#39;, &#39;@&#39;, &#39;#&#39;};</pre><pre>// Method based on quick sort which matches nuts and bolts</pre><pre>matchPairs(nuts, bolts, 0, 5);</pre><pre>System.out.println(&quot;Matched nuts and bolts are : &quot;);</pre><pre>printArray(nuts);</pre><pre>printArray(bolts);</pre><pre>}</pre><pre>// Method to print the array</pre><pre>private static void printArray(char[] arr) {</pre><pre>for (char ch : arr){</pre><pre>System.out.print(ch + &quot; &quot;);</pre><pre>}</pre><pre>System.out.print(&quot;\n&quot;);</pre><pre>}</pre><pre>// Method which works just like quick sort</pre><pre>private static void matchPairs(char[] nuts, char[] bolts, int low,</pre><pre>int high)</pre><pre>{</pre><pre>if (low &lt; high)</pre><pre>{</pre><pre>// Choose last character of bolts array for nuts partition.</pre><pre>int pivot = partition(nuts, low, high, bolts[high]);</pre><pre>// Now using the partition of nuts choose that for bolts</pre><pre>// partition.</pre><pre>partition(bolts, low, high, nuts[pivot]);</pre><pre>// Recur for [low...pivot-1] &amp; [pivot+1...high] for nuts and</pre><pre>// bolts array.</pre><pre>matchPairs(nuts, bolts, low, pivot-1);</pre><pre>matchPairs(nuts, bolts, pivot+1, high);</pre><pre>}</pre><pre>}</pre><pre>// Similar to standard partition method. Here we pass the pivot element</pre><pre>// too instead of choosing it inside the method.</pre><pre>private static int partition(char[] arr, int low, int high, char pivot)</pre><pre>{</pre><pre>int i = low;</pre><pre>char temp1, temp2;</pre><pre>for (int j = low; j &lt; high; j++)</pre><pre>{</pre><pre>if (arr[j] &lt; pivot){</pre><pre>temp1 = arr[i];</pre><pre>arr[i] = arr[j];</pre><pre>arr[j] = temp1;</pre><pre>i++;</pre><pre>} else if(arr[j] == pivot){</pre><pre>temp1 = arr[j];</pre><pre>arr[j] = arr[high];</pre><pre>arr[high] = temp1;</pre><pre>j--;</pre><pre>}</pre><pre>}</pre><pre>temp2 = arr[i];</pre><pre>arr[i] = arr[high];</pre><pre>arr[high] = temp2;</pre><pre>// Return the partition index of an array based on the pivot</pre><pre>// element of other array.</pre><pre>return i;</pre><pre>}</pre><pre>}</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FoeRMXZ8EKvY%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DoeRMXZ8EKvY&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FoeRMXZ8EKvY%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b051d42340d2ad403f94b546b7c03b5e/href">https://medium.com/media/b051d42340d2ad403f94b546b7c03b5e/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92082115a056" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Multithreading]]></title>
            <link>https://medium.com/@pushpak.sharma/multithreading-f34d794f2d7b?source=rss-709fe7a7dafe------2</link>
            <guid isPermaLink="false">https://medium.com/p/f34d794f2d7b</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[multithreading]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Pushpak Sharma]]></dc:creator>
            <pubDate>Wed, 14 Nov 2018 17:03:25 GMT</pubDate>
            <atom:updated>2018-11-19T15:17:06.187Z</atom:updated>
            <content:encoded><![CDATA[<p>Understanding the niche concept to be able to write code :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K_hjKOtvs_2fXEq9StLNyA.png" /></figure><h3>Part 1</h3><blockquote><strong>Basic Terminology</strong></blockquote><p>The <strong>thread</strong> is a unit of Process.</p><p>It is a sub-process.</p><p>Now you will wonder <br>:- that u have used thread in Java without writing a program in Thread.</p><p>How?</p><p>Have u seen something like this ``` <em>Exception in thread “</em><strong><em>main</em></strong>” ```</p><p>That mean Main is the Thread So by default all java program is of <strong>THREAD.</strong></p><p>There are Two ways in Java from which we can use the functionality of Thread.</p><ol><li><strong>extends Thread</strong></li><li><strong>implements Runnable</strong> because java doesn’t have multiple inheritances.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e4ba07b685b6e58db572bcdadc018a1/href">https://medium.com/media/5e4ba07b685b6e58db572bcdadc018a1/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k9KLMMqcPI3y4LDmgpYMtg.png" /></figure><h3>Part 2</h3><p>So there is always main thread and it is master of the program.</p><p><strong>Note</strong> we can suspend the flow of thread throw Sleep :)</p><p>Now we want to make the thread run parallel to do this</p><p>we using start which will call run() method by default.</p><p>So we can override the run method.</p><p>So you may have heard the Term <em>Process </em><strong><em>Scheduler</em></strong></p><p>Both the Process have the same priority. So <em>Process </em><strong><em>Scheduler selects them Randomly.</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a2c704e54ba4603fc9591a79692ce5a/href">https://medium.com/media/9a2c704e54ba4603fc9591a79692ce5a/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XaGFwgQ3pjoLJ5kyeZ0qoQ.png" /></figure><h3>Part 3</h3><p>Using Runnable interface</p><p>It is a Functional interface and it has only one method that is run.</p><p>So Runnable Doesn’t have the Start method.</p><p>So we create thread obj and call start method but Note it will call the start method of Thread itself not of runnable so in order to execute it we bind it with thread.</p><p>If you expand the constructor of Thread it is asking for obj of Runnable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1e897af15f04d746044de741cc45c4a5/href">https://medium.com/media/1e897af15f04d746044de741cc45c4a5/href</a></iframe><h3>Part 4</h3><h4>Lambda Expression</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba1e911525687504f154c705bb25fd16/href">https://medium.com/media/ba1e911525687504f154c705bb25fd16/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F7dhugteYtkQ%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D7dhugteYtkQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F7dhugteYtkQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e1b33673f286daf7918813e87f3afa4/href">https://medium.com/media/8e1b33673f286daf7918813e87f3afa4/href</a></iframe><p>Hope you will love it….!</p><h3>Conclusion</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FjUJ8tb6weAN8sVnUEy%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FjUJ8tb6weAN8sVnUEy%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FjUJ8tb6weAN8sVnUEy%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a45781991a0cc10de852348d90304b6/href">https://medium.com/media/5a45781991a0cc10de852348d90304b6/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f34d794f2d7b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Code Of Graph {BFS}and Design Thinking]]></title>
            <link>https://medium.com/@pushpak.sharma/code-of-graph-bfs-and-design-thinking-b7dc73094334?source=rss-709fe7a7dafe------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7dc73094334</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[data-struct]]></category>
            <category><![CDATA[university]]></category>
            <category><![CDATA[graph]]></category>
            <dc:creator><![CDATA[Pushpak Sharma]]></dc:creator>
            <pubDate>Mon, 12 Nov 2018 17:32:56 GMT</pubDate>
            <atom:updated>2018-11-12T17:39:52.790Z</atom:updated>
            <content:encoded><![CDATA[<p>How to Write Code of a Graph in Java</p><p>How to think and approach toward it.</p><h3>First</h3><p>we have to create vertex and choose the way we want to represent Graph</p><p>through list or Matrix.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OMIExSEwHkU0y94S1eu1Iw.png" /></figure><h3>Second</h3><p>Create Edge Between Graph</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*crfzI0vHjzwJAioTXLqVow.png" /></figure><h3>Third</h3><p>Main Logic To Traverse the Graph</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uccSbOOv19NavT_iCl51mA.png" /></figure><h3>Traversal Example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nNgMZ0cnCpyHpVLRAdlroA.png" /></figure><h3>Code</h3><p><a href="https://github.com/pushoo-sharma/Competitive-web-series/tree/master/Data-structure/src/com/pushpak/Graph">pushoo-sharma/Competitive-web-series</a></p><h3><strong>Conclusion</strong></h3><p>let&#39;s do it :)</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fl1IY8U7eDBCCZVXfG%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fbollywood-india-indian-l1IY8U7eDBCCZVXfG&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fl1IY8U7eDBCCZVXfG%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/776a642a4eb0a5822bf57e928fb89f1b/href">https://medium.com/media/776a642a4eb0a5822bf57e928fb89f1b/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7dc73094334" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Graph {Competitive Web Series}]]></title>
            <link>https://medium.com/@pushpak.sharma/introduction-to-graph-competitive-web-series-e3ddf25fb045?source=rss-709fe7a7dafe------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3ddf25fb045</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[competitive]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Pushpak Sharma]]></dc:creator>
            <pubDate>Fri, 09 Nov 2018 19:59:29 GMT</pubDate>
            <atom:updated>2018-11-09T19:59:29.199Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_ZRNFvhFakOBPdNUp1orfQ.png" /><figcaption>Graph {competitive web series}</figcaption></figure><p>Here we will look at the Graph and its universal implementation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mfwTVjKCGY3OvYMtVPPYvA.png" /></figure><p>There are two types of data structure <strong><em>linear</em></strong> and<strong><em> non-linear</em></strong>.</p><p>Linear {Stack, queue, linked list}</p><p>Non-linear {tree,trie,Graph}</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IBdfnmR8Ku5uN6uM7Y_Thg.png" /></figure><p>The graph is the father of two children:-</p><ol><li>Node</li></ol><p>2. Edges</p><h4>Golden note</h4><p>In the Directed Graph the node having vertices (a,b) != (b,a)</p><p>There are two ways of representing the Graph</p><ol><li>Adjacency Matrix</li></ol><p>2. Adjacency List</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q3_f5UYFA_GYT2gEED5IHQ.png" /></figure><blockquote>Question</blockquote><p>When you use what and when?</p><p><strong>Answer: Matrix When the DENSE graph and List when Sparse Graph</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h-vGa5B5dsJ3x_NzXA3U6w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vQscymnNkcVBNhHTm_0h7g.png" /></figure><h4>Two Best application of Graph</h4><p>BFS {Breadth First Search}</p><p>DFS {Depth First Search}</p><p>BFS — can be used to find friends of friends and give u suggestion</p><p>DFS — going to the deepest level and then coming back and then repeating the same task</p><p><strong>Difference Between Tree and Graph?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*agR_2vrnwirwL6IQcr_-MA.png" /></figure><p><strong>When to use BFS And DFS?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dy0-HXJv30L_GqEiIk1yUA.png" /></figure><p><strong>BFS Pseudo Code and Explanation</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JfiLtLn6MqGUK9-kBzHu2Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aGAeRQVNeeafuFd9c1rOTg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y7zUAE7Lxkqa8yTmpYWW-Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A-CKCzbik_sERvhnfU0BDw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3pawzv7EDvpMAs8q-rrGQQ.png" /></figure><h4>BFS Code</h4><p><a href="https://github.com/pushoo-sharma/Competitive-web-series/blob/master/Data-structure/src/com/pushpak/Graph/BFS.java">pushoo-sharma/Competitive-web-series</a></p><h4>BFS Code Explanation</h4><p>Youtube link will be attached over here</p><h3>Conclusion</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FlS74OiH1JYYak%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2FlS74OiH1JYYak&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FlS74OiH1JYYak%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="232" frameborder="0" scrolling="no"><a href="https://medium.com/media/9802b4a6059694f7260d04d25224ec27/href">https://medium.com/media/9802b4a6059694f7260d04d25224ec27/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3ddf25fb045" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interview Series on JavaScript {Object Creation Pattern}]]></title>
            <link>https://medium.com/@pushpak.sharma/interview-series-on-javascript-object-creation-pattern-143243e8a979?source=rss-709fe7a7dafe------2</link>
            <guid isPermaLink="false">https://medium.com/p/143243e8a979</guid>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Pushpak Sharma]]></dc:creator>
            <pubDate>Wed, 10 Oct 2018 04:19:44 GMT</pubDate>
            <atom:updated>2018-10-10T04:19:44.829Z</atom:updated>
            <content:encoded><![CDATA[<p>This will help you to prepare for getting your job and cleaning your Concept too!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wyOChV6-Xu-Mob9E" /><figcaption>“man talking in front of woman” by <a href="https://unsplash.com/@rawpixel?utm_source=medium&amp;utm_medium=referral">rawpixel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>JavaScript have<em> no formal support</em> of Class.</blockquote><blockquote>So we need to create object and from that object we can create other object from that object :)</blockquote><p><strong>So we will look @ different object creation Pattern</strong></p><blockquote><strong>Constructor</strong> Pattern</blockquote><blockquote><strong>Factory</strong> Pattern</blockquote><blockquote><strong>Prototype</strong> Pattern</blockquote><blockquote><strong>Dynamic Prototype</strong> Pattern</blockquote><p><em>We will look at them one by one : D</em></p><h3>Factory Pattern</h3><pre>var newJoining = function(personName,personExperience,personSalary){</pre><pre>var temp = {};<br>    <br>    temp.personName = personName ;<br>    temp.personExperience = personExperience ;<br>    temp.personSalary = personSalary ;<br>    <br>    temp.printInfo = function(){<br>     console.log(&quot;Person Name : &quot;+ this.personName+&quot; and Experience &quot;+ this.personExperience +&quot; and Salary &quot;+ this. personSalary);<br>    }<br>    <br>    return temp ;<br>}</pre><pre>person1 = newJoining(&quot;Pushpak&quot;,0,&quot;xxx&quot;);<br>person2= newJoining(&quot;Arkit&quot;,1,&quot;xxx&quot;);</pre><pre>person1.printInfo();<br>person2.printInfo();</pre><h3>Constructor Pattern</h3><pre>var studentRecord = function(name , age , standard){<br>    this.name = name ;<br>    this.age = age ;<br>    this.standard = standard ;<br>    <br>    this.printInfo = function(){<br>        console.log(&quot;Student Name is : &quot;+ this.name+&quot; age &quot;+this.age+&quot; and  class &quot;+this.standard);<br>    }    <br>}</pre><pre>var personOne = new studentRecord(&quot;Pushpak&quot;,18,12);<br>var personTwo = new studentRecord(&quot;Raj&quot;,12,12);</pre><pre>personOne.printInfo();<br>personTwo.printInfo();</pre><h3>Prototype Pattern</h3><pre>var studentRecord = function(){<br>}</pre><pre>studentRecord.prototype.name = &quot;xyz&quot; ;<br>studentRecord.prototype.age = 18 ;<br>studentRecord.prototype.standard = 12 ;</pre><pre>studentRecord.prototype.printInfo = function(){<br>    console.log(&quot;Name is &quot;+ this.name+&quot; age is &quot;+ this.age+&quot; standard is &quot;+ this.standard);<br>}</pre><pre>var personOne = new studentRecord();<br>personOne.name = &quot;Pushpak&quot;;<br>personOne.age = 18 ;<br>personOne.standard = 12 ;</pre><pre>personOne.printInfo();</pre><p>we are <strong><em>overriding</em></strong><em> </em>it.</p><pre>var studentRecord = function(){<br>}</pre><pre>studentRecord.prototype.name = &quot;xyz&quot; ;<br>studentRecord.prototype.age = 18 ;<br>studentRecord.prototype.standard = 12 ;</pre><pre>studentRecord.prototype.printInfo = function(){<br>    console.log(&quot;Name is &quot;+ this.name+&quot; age is &quot;+ this.age+&quot; standard is &quot;+ this.standard);<br>}</pre><pre>var personOne = new studentRecord();<br><strong>//personOne.name = &quot;Pushpak&quot;;</strong><br>personOne.age = 18 ;<br>personOne.standard = 12 ;</pre><pre>personOne.printInfo();</pre><p>After Commenting it :- we got <strong><em>output</em></strong></p><blockquote>Name is <strong><em>xyz</em></strong> age is 18 standard is 12</blockquote><pre>console.log(&#39;name&#39; in personOne);                       // true<br>console.log(personOne.hasOwnProperty(&#39;name&#39;));          // false</pre><h3>Dynamic Prototype Pattern</h3><pre>var studentDynamicRecord = function(name , age , standard){<br>    this.name = name ;<br>    this.age = age ;<br>    this.standard = standard ;<br>    <br>    if( typeof this.printInfo !== &#39;function&#39;){<br>        console.log(&quot; this function is created only ONCE&quot;);<br>        studentDynamicRecord.prototype.printInfo = function(){<br>            console.log(&quot;Student Name is : &quot;+ this.name+&quot; age &quot;+this.age+&quot; and  class &quot;+this.standard);<br>        }    <br>    }<br>    <br>};</pre><pre>var personOne = new studentDynamicRecord(&quot;Pushpak&quot;,18,12);</pre><pre>personOne.printInfo();</pre><pre>var personTwo = new studentDynamicRecord(&quot;Push&quot;,18,12);</pre><pre>personTwo.printInfo();</pre><h4>Output</h4><pre><strong>this function is created only ONCE</strong><br>Student Name is : Pushpak age 18 and  class 12<br>Student Name is : Push age 18 and  class 12</pre><p>After Removing <strong><em>type check</em></strong></p><pre>var studentDynamicRecord = function(name , age , standard){<br>    this.name = name ;<br>    this.age = age ;<br>    this.standard = standard ;<br>    <br>    studentDynamicRecord.prototype.printInfo = function(){<br>        console.log(&quot;This Function is called&quot;);<br>        console.log(&quot;Student Name is : &quot;+ this.name+&quot; age &quot;+this.age+&quot; and  class &quot;+this.standard);<br>    }    <br>    <br>    <br>};</pre><pre>var personOne = new studentDynamicRecord(&quot;Pushpak&quot;,18,12);</pre><pre>personOne.printInfo();</pre><pre>var personTwo = new studentDynamicRecord(&quot;Push&quot;,18,12);</pre><pre>personTwo.printInfo();</pre><pre>console.dir(personOne);<br>console.dir(personTwo);</pre><h4>Output</h4><pre><strong>This Function is called</strong><br>Student Name is : Pushpak age 18 and  class 12<br><strong>This Function is called</strong><br>Student Name is : Push age 18 and  class 12</pre><h3>Conclusion</h3><p>Keep learning and put your constructive comment :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=143243e8a979" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interview Series on JavaScript {Promises}]]></title>
            <link>https://medium.com/@pushpak.sharma/interview-series-on-javascript-promises-c14379234674?source=rss-709fe7a7dafe------2</link>
            <guid isPermaLink="false">https://medium.com/p/c14379234674</guid>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[storyofmylife]]></category>
            <dc:creator><![CDATA[Pushpak Sharma]]></dc:creator>
            <pubDate>Mon, 24 Sep 2018 18:42:07 GMT</pubDate>
            <atom:updated>2018-09-24T18:42:50.128Z</atom:updated>
            <content:encoded><![CDATA[<p>This will help you to prepare for getting your job and cleaning your Concept too!</p><h3>Promises</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GEXMdK5HDaJ4tYe3" /><figcaption>“person’s hands” by <a href="https://unsplash.com/@rawpixel?utm_source=medium&amp;utm_medium=referral">rawpixel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Two Important thing <strong><em>Resolve and Reject</em></strong></blockquote><p><strong>Resolve (Done)</strong></p><p><strong>Reject (Not Done) <em>in Simple terminology</em>!</strong></p><blockquote>Thing you should know :-</blockquote><ol><li><strong>then</strong> (it is called once the promise is <em>Resolved</em>)</li><li><strong>catch</strong> (it is called once the promise is <em>Rejected</em> )</li></ol><pre>let promiseToLearnEveryDay = new <strong>Promise</strong>(function(resolve , reject){<br>    <br>    // promise to learn every day<br>    let<strong> myPromise</strong> = true ;<br>    <br>    if(<strong>myPromise</strong>){<br>       <em> </em><strong><em>resolve</em></strong>(&#39;Doing&#39;);<br>    }<br>    else{<br>        <strong><em>reject</em></strong>(&#39;Not Doing&#39;);<br>    }<br>    <br>});</pre><pre>promiseToLearnEveryDay.<strong>then</strong>(function(<strong>fromResolve</strong>){<br>    console.log(&quot;Learning mode is : &quot;+fromResolve);<br>}).<strong>catch</strong>(function(<strong>fromReject</strong>){<br>    console.log(&quot;Learning mode is : &quot;+fromReject);<br>})</pre><p>So you can get understanding with above example!</p><h4>Now Some Exercise</h4><h4>Story</h4><p>You Started learning java-script; Now you go to the hackathon; Now you Won hackathon</p><p>Code this using Promises :)</p><pre>let learnJavaScript = function(){</pre><pre>return  new Promise(function(resolve,reject){</pre><pre>resolve(&quot;Learning javascript&quot;)</pre><pre>});</pre><pre>};</pre><pre>let participateInHackathon = function(message){</pre><pre>return  new Promise(function(resolve,reject){</pre><pre>resolve(message+&quot;- Participating in Hackathon&quot;);</pre><pre>});</pre><pre>};</pre><pre>let winingHackathon = function(message){</pre><pre>return  new Promise(function(resolve,reject){</pre><pre>resolve(message+&quot;- Wining @ Hackathon !&quot;);</pre><pre>});</pre><pre>};</pre><pre>learnJavaScript().then(function(result){</pre><pre>return(participateInHackathon(result));</pre><pre>}).then(function(result){</pre><pre>return(winingHackathon(result));</pre><pre>}).then(function(result){</pre><pre>console.log(result);</pre><pre>})</pre><p><strong>Something More</strong></p><p>Using the Above Example</p><ol><li>all</li><li>race</li></ol><pre>// if all <strong>resolve</strong> <strong><em>then</em></strong> will execute<br>Promise.all([learnJavaScript(),participateInHackathon(),winingHackathon()]).then(function(){</pre><pre>console.log(&#39;all done&#39;)</pre><pre>});</pre><pre>// if any one<strong> resolve</strong> <strong><em>then</em></strong> will execute</pre><pre>Promise.race([learnJavaScript(),participateInHackathon(),winingHackathon()]).then(function(){</pre><pre>console.log(&#39;all done&#39;)</pre><pre>});</pre><p><strong>Conclusion</strong></p><p>Happy Learning Spread the Love !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c14379234674" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Redux {React}]]></title>
            <link>https://medium.com/@pushpak.sharma/redux-react-b29d8409fd02?source=rss-709fe7a7dafe------2</link>
            <guid isPermaLink="false">https://medium.com/p/b29d8409fd02</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[knowledge-sharing]]></category>
            <category><![CDATA[100daysofcode]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[redux]]></category>
            <dc:creator><![CDATA[Pushpak Sharma]]></dc:creator>
            <pubDate>Sun, 16 Sep 2018 05:53:49 GMT</pubDate>
            <atom:updated>2018-09-17T12:15:38.587Z</atom:updated>
            <content:encoded><![CDATA[<p>We will first understand about how redux work</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ri7IZZz-LAMmQUNe" /><figcaption>“turned on MacBook Air displaying coding application” by <a href="https://unsplash.com/@sapegin?utm_source=medium&amp;utm_medium=referral">Artem Sapegin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Redux Simplified with the step:-</p><pre>Redux Simplified with the step:- <br><strong>1. Store  </strong> <br> a).reducer   <br> b).state <br><strong>2.Reducer  </strong>  <br> a).state    <br> b).action <br><strong>3.Subscribe <br>4.Dispatch</strong></pre><p><strong><em>Note</em></strong>: Step 2 that is Reducer is before Step 1 otherwise it throws an error!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/28d4180e2ed0bac05b39faaef8f3fee5/href">https://medium.com/media/28d4180e2ed0bac05b39faaef8f3fee5/href</a></iframe><p>Output @ console :-</p><pre>Pushpak is Now  I am travelling the globe<br>Pushpak is Now  I am swimming</pre><blockquote>I HAVE PUTTED ALL STEP IN ONE FILE TO GIVE BETTER UNDERSTANDING OF FLOW!</blockquote><p>At project<strong><em> reducer and dispatch</em></strong> are in the separate file.</p><h3>WHY, HOW AND WHEN {Redux}</h3><p>what is redux?</p><blockquote>It a library and help in <strong>state management.</strong></blockquote><p><a href="https://redux.js.org/basics/usagewithreact">Usage with React - Redux</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*opfEKYU1X-DPTWJIGGc5LQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Drn0dT7AQDUFTlNMXN9ROA.jpeg" /></figure><p><em>PAGE</em><strong><em> 1</em></strong><em> AND PAGE</em><strong><em> 2</em></strong><em> DEPICTS THE STORE</em></p><p><strong>Page 1:-</strong></p><p><strong>point 1:</strong>- when there are lots of containers and your action in so deep to avoid multiple passing u use global state.</p><p><strong>point 2:</strong>- When u are using variable across multiple pages and reflecting the changes</p><p><strong>Page 2:-</strong></p><p><strong>point 3:</strong>-<em> when to use redux and when not to?</em></p><p><strong><em>The answer </em></strong>is when itis hard to read and understand and track your code.</p><p>Redux help in storing, updating and dispatching and subscribing easily.</p><h3>Understanding Terminology</h3><p><strong>Reducer?</strong></p><p><em>reducer hold functionality to modify the state</em></p><p><strong>Dispatch?</strong></p><p><em>transfer the value that u made changes onto the </em><strong><em>Reducer</em></strong><em>.</em></p><p><strong>Subscribe?</strong></p><p><em>It passes the updated value to all its</em><strong><em> subscribers.</em></strong></p><h3>More Code Snippet to understand it Better</h3><h4>Snippet 1</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05897d1b717d1baca1f03c75d3af8672/href">https://medium.com/media/05897d1b717d1baca1f03c75d3af8672/href</a></iframe><p><strong>Output</strong>:-</p><pre>Pushpak age is now  {age: 31}<br>Pushpak age is now  {age: 41}</pre><h4>Snippet 2</h4><p>Before using React-Redux</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5915811f4a24fc326fddb69a519004f4/href">https://medium.com/media/5915811f4a24fc326fddb69a519004f4/href</a></iframe><p>After React-Redux</p><blockquote>Note : <strong>&lt;Provider&gt; </strong>Whatever we pass to it is available globally!</blockquote><blockquote>It has to be at the highest level <strong>@app.js</strong></blockquote><blockquote>You need to wrap<strong> store </strong>in &lt;Provider&gt;</blockquote><p><em>WARNING :- u should know what is higher order component</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ab55c0eb80e66f2afcaa8de1c71be1c/href">https://medium.com/media/5ab55c0eb80e66f2afcaa8de1c71be1c/href</a></iframe><h4>Snippet 3:</h4><p><strong>Combine Multiple Reducers</strong></p><p><a href="https://github.com/pushoo-sharma/React-with-Redux/tree/master/Redux/reduxappsecond">pushoo-sharma/React-with-Redux</a></p><h4>Snippet 4:</h4><p><strong>Redux Middleware</strong></p><blockquote>Reducer is designed to run synchronous code</blockquote><p>What is does if you try to run something as async it will not work ; thus for this middle ware come into action :/</p><blockquote>Redux have a property known as <strong>applyMiddleware </strong>and its a <strong>function.</strong></blockquote><blockquote><strong>applyMiddleware </strong>capture the action.</blockquote><p>what we do when we <em>catch the action</em> ; we can take it and do <em>something next </em>and following this<em> we return the action back</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/658d6c503ddfc532c1059cae11dec1c4/href">https://medium.com/media/658d6c503ddfc532c1059cae11dec1c4/href</a></iframe><p><strong>Output @ console</strong></p><pre>catch in the middleWare {&quot;type&quot;:&quot;AGE_UP&quot;,&quot;value&quot;:1}</pre><h4>Snippet 5:</h4><p><strong>Redux <em>THUNK</em></strong></p><p><em>In </em><strong><em>javascript</em></strong><em> world if you execute a statement instead of executing the statement right there it will wrap it with a func. and u have to call that func. and that func. will return the statement.</em></p><p>So this is How u execute in <strong>THUNK.</strong></p><p><a href="https://github.com/pushoo-sharma/React-with-Redux/tree/master/Redux/reduxappthird">pushoo-sharma/React-with-Redux</a></p><h4>Snippet 6:</h4><p><strong>Redux<em> Saga</em></strong></p><p><a href="https://github.com/pushoo-sharma/React-with-Redux/tree/master/Redux/reduxappfourth">pushoo-sharma/React-with-Redux</a></p><h3>Conclusion</h3><p>Happy learning and spread the love!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b29d8409fd02" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Calling back-end Services React]]></title>
            <link>https://medium.com/@pushpak.sharma/calling-back-end-services-react-c76e3160026?source=rss-709fe7a7dafe------2</link>
            <guid isPermaLink="false">https://medium.com/p/c76e3160026</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[web]]></category>
            <dc:creator><![CDATA[Pushpak Sharma]]></dc:creator>
            <pubDate>Thu, 06 Sep 2018 13:22:50 GMT</pubDate>
            <atom:updated>2018-09-06T13:22:50.714Z</atom:updated>
            <content:encoded><![CDATA[<p>(Part -1 )</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pF7-dJn5PNN_qpjW" /><figcaption>“programming language codes” by <a href="https://unsplash.com/@markusspiske?utm_source=medium&amp;utm_medium=referral">Markus Spiske</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>JSON PlaceHolder</h4><p><a href="https://jsonplaceholder.typicode.com/posts">https://jsonplaceholder.typicode.com</a></p><p>it give us API ; which give us few end point.Using these endpoint we can send few http request to CRUD operation.</p><h4>HTTP client</h4><pre>Front End =======&gt; Back End (HTTP Request)to get or save data.</pre><p>? How can we do that</p><p>React care about rendering the View and managing the DOM.</p><p>It make sure what we have in Browser DOM is sync with state of your application !</p><p>React Doesn’t have a opinion about how to send http request to Server.(Angular HTTPmodule).</p><p>Use your preferred libr.</p><pre>Fetch API<br>JqUERY ajax<br>Axios  </pre><p><a href="https://www.npmjs.com/package/axios">axios</a></p><h4>Getting Data</h4><p>Right place to call a server and get some data is in componentDidMount lifecycle Hook.</p><pre>componentDidMount(){<br>const promise = axios.get(&quot;https://jsonplaceholder.typicode.com/posts&quot;);<br>}</pre><p>What is promise above ?</p><p>It is a object that holds the result of asynchronous operation.</p><p>async operation is something that will finish in future.</p><p>First its in pending state -&gt;resolved (Success) OR rejected (failure)</p><p><em>Server send header,request,status.</em></p><p>we can get the value using<strong> await</strong> keyword.Note : we should attach the function with <strong>async</strong> .</p><pre><strong>async</strong> componentDidMount(){<br>const response  = <strong>await </strong>axios.get(&quot;https://jsonplaceholder.typicode.com/posts&quot;);</pre><pre>console.log(response);</pre><pre>}</pre><h4>Creating Data</h4><p>async and . post() will be a key player.</p><pre>handleAdd = <strong>async</strong>() =&gt; {<br>// console.log(&quot;Add&quot;);</pre><pre>const obj = { title : &#39;a&#39; , body : &#39;b&#39;};</pre><pre>const {data : post} = await axios.<strong>post</strong>(ApiEndPoint , obj);</pre><pre>// console.log(post);</pre><pre>const posts = [post,...this.state.posts];</pre><pre>this.setState({posts});</pre><pre>};</pre><h4>LifeCycle of Request</h4><p>Every http request has the property called method that intent the property of request .</p><p>Common method</p><pre>get (for getting data)<br>post (for creating data)<br>put (for updating data)<br>delete (for deleting data)<br>options </pre><h4>Updating the data</h4><p>axios.patch vs axios.put</p><p>we use<em> patch </em>to update one or more property and<em> put </em>to update all property.</p><pre>axios.<strong>put</strong>(ApiEndPoint + &#39;/&#39; + post.id ,<strong>post</strong>);</pre><pre>axios.<strong>patch</strong>(ApiEndPoint + &#39;/&#39; + post.id ,{<strong> title : post.title</strong>});</pre><pre>You can see we are only sending the properties that needs to be updated !</pre><h4>Deleting the data</h4><pre><strong>axios.delete</strong>(ApiEndPoint + &#39;/&#39; + post.id)</pre><p>It is done with the help of <strong>axios.delete.</strong></p><h4>Optimistic vs Pessimistic Updates</h4><p>Pessimistic Updates</p><pre>handleDelete = async post =&gt; {</pre><pre>await axios.delete(ApiEndPoint + &#39;/&#39; + post.id);<br>//Calling the server first</pre><pre>const posts = this.state.posts.filter( p =&gt; p.id !== post.id);</pre><pre>this.setState({posts});<br>//then updating the post</pre><pre>console.log(&quot;Delete&quot;, post);</pre><pre>};</pre><pre>With this implementation if there occur an error while calling a server ; the reset of the function will not occur.<br>we are not sure call to the server will fail or success.</pre><p>Optimistic</p><p>we assume most of the time call to the server will success.</p><p>So we will update the UI before server call and if it fails we will revert it back.</p><p>Steps :</p><ol><li>keep a storage of original content</li><li>make the changes on the UI</li><li>wait for the server to respond === “Success” ? “Bingo” : load the original content</li></ol><p>Note : wrap the code in try catch method</p><pre>const originalPost = this.state.posts;</pre><pre>const posts = this.state.posts.filter( p =&gt; p.id !== post.id);</pre><pre>this.setState({posts});</pre><pre>try{</pre><pre>await axios.delete(ApiEndPoint + &#39;/&#39; + post.id);</pre><pre>}</pre><pre>catch(err){</pre><pre>alert(&#39;something failed while deleting a post !&#39;);</pre><pre>this.setState({posts : originalPost});</pre><pre>}</pre><h4>Expected And Unexpected Error</h4><p>Expected Error</p><p>If we try to delete post with invalid id : it will return with an error 404 : Not found (which is a standard http error)</p><p>400 : when we try to submit a form with invalid data.</p><p>400 : range as CLIENT ERROR ; So we should display a specific message.</p><p>Unexpected Error</p><p>Network is down so we won’t be able to call to the server. or network is up but server is down or network is up server is up but database is down.or we have a bug in our application code</p><p>so we should display a generic or user friendly message.</p><pre>catch(err){</pre><pre>if(err.response &amp;&amp; err.response.status === 404){</pre><pre>alert(&quot;This post has been deleted alredy&quot;);</pre><pre>}</pre><pre>else{</pre><pre>console.log(&quot;logging the error&quot;,err);</pre><pre>alert(&quot;an unexpected error occured.&quot;);</pre><pre>}</pre><pre>}</pre><p>Cconclusion</p><p>Keep Reading !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c76e3160026" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Routing in React]]></title>
            <link>https://medium.com/@pushpak.sharma/routing-in-react-b07b5ce76336?source=rss-709fe7a7dafe------2</link>
            <guid isPermaLink="false">https://medium.com/p/b07b5ce76336</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[routing]]></category>
            <dc:creator><![CDATA[Pushpak Sharma]]></dc:creator>
            <pubDate>Tue, 04 Sep 2018 18:46:35 GMT</pubDate>
            <atom:updated>2018-09-04T18:51:00.844Z</atom:updated>
            <content:encoded><![CDATA[<p>we learn about a library that helps in routing in React.</p><p>First you need to install npm install --save react-router-dom.</p><p><a href="https://www.npmjs.com/package/react-router-dom">react-router-dom</a></p><p>Now lets us know about &lt;BrowserRouter&gt;</p><p>It grabs history object in router and passes it down the Component Tree.</p><p>Now , understanding &lt;Route path = “/products” Component = {Products}/&gt;</p><blockquote>This Route looks at current URL if it matches with path = “/products” it will render this Component = {Products}</blockquote><h4>Switch</h4><p>when to use :-</p><pre>&lt;div className = “content”&gt;<br>      &lt;Route path = &quot;/products&quot; Component = {Products} /&gt;</pre><pre>      &lt;Route path = &quot;/posts&quot; Component = {Posts}/&gt;</pre><pre>      &lt;Route path = &quot;/admin&quot; Component = {Dashboard}/&gt;</pre><pre>      &lt;Route path = &quot;/&quot; Component = {Home}/&gt;</pre><pre>&lt;/div&gt;</pre><pre>Here two paths matches when path is /products <br> path = &quot;/products&quot;<br> path = &quot;/&quot;</pre><p>We can use “exact” and other solution is &lt;Switch&gt;</p><p><em>Note : Switch renders the first child which matches</em></p><p>Therefore,you should order the Route from most Specific ones to most Generic ones.</p><h4>link</h4><p>link prevent overhead and http request.</p><p>How this link prevent addition HTTP request ?</p><p>link have regular anchor onClick:fn() which is handler which prevent the default behaviour of anchor this will not send addition request instead update the URL.</p><p>&lt;Link to=”/posts/2018/06&quot;&gt;Posts&lt;/Link&gt;</p><h4>Route Props</h4><p>history , location and match are the default props.</p><p>it will be automatically injected once the path matches.</p><h4>Passing Props</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9a49c9208a1caab85ac1ac678400ae3/href">https://medium.com/media/c9a49c9208a1caab85ac1ac678400ae3/href</a></iframe><h4>Route Parameters</h4><p>prefix that parameter with colon:</p><p>We can read the route parameter through match object</p><p>&lt;Route path = “/products/:id” Component = {ProductDetails}/&gt;</p><h4>Optional Parameter</h4><pre>&lt;Route path = &quot;/posts/:year/:month&quot; Component = {Posts}/&gt;</pre><pre>&lt;Route path = &quot;/admin&quot; Component = {Dashboard}/&gt;</pre><pre>&lt;Route path = &quot;/&quot; Component = {Home}/&gt;</pre><p>If you exclude month from URL when you click month ; you will see Home is rendered.</p><p>So How can we improve this ?</p><p>Answer is using Regular Expression</p><pre>&lt;Route path = “/posts/:year?/:month?” Component = {Posts}/&gt;</pre><h4>Query String Parameter</h4><p>They can be find in the location Object under search.</p><p><a href="https://www.npmjs.com/package/query-string">query-string</a></p><p>You need to install it !</p><pre>import queryString from &#39;query-string&#39;;</pre><pre>const {sortBy} = queryString.parse(location.search);</pre><h4>Redirect</h4><pre>&lt;Route path = &quot;/not-found&quot; Component = {NotFound}/&gt;</pre><pre>&lt;Route path = &quot;/&quot; exact Component = {Home}/&gt;</pre><pre>&lt;Redirect to =&quot;/not-found&quot;/&gt;</pre><p>If we type invalid URL it will redirect to set path.</p><p>It also has some other application ; Sometime you want to redirect resources from one URL to other URL.</p><pre>&lt;Redirect from = “/messages” to = “/post”/&gt;</pre><h4>Programmatic Navigation</h4><p>when you look at history object you will find push and replace function.</p><p>push -&gt; will add new address in the browser history.so u can click the back button to where you were.</p><p>replace -&gt; will replace the current address so we won’t have history</p><p>Replace are mostly used in Login Pages.</p><p>Nested Routing (self )</p><h3>Conclusion</h3><p>Its an Important Concept on react.</p><p>I will write more on it once i again enough knowledge on it !.</p><p>Till Then happy learning !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b07b5ce76336" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Life Cycle Hook in React]]></title>
            <link>https://medium.com/@pushpak.sharma/life-cycle-hook-in-react-a5d6ff5df053?source=rss-709fe7a7dafe------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5d6ff5df053</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Pushpak Sharma]]></dc:creator>
            <pubDate>Tue, 04 Sep 2018 05:13:14 GMT</pubDate>
            <atom:updated>2018-09-04T05:13:14.530Z</atom:updated>
            <content:encoded><![CDATA[<p>We will dive into what are life cycle hook in react !</p><h4>Mount</h4><ul><li>constructor</li><li>render</li><li>componentDidMount</li></ul><h4>Update</h4><ul><li>render</li><li>componentDidUpdate</li></ul><h4>UnMount</h4><ul><li>componentWillUnmount</li></ul><h4>Mount-Explained with Exampled with Code {See Comment for Better Understanding}</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/97b9a6039ecdf7b045675c1bd0c35fe3/href">https://medium.com/media/97b9a6039ecdf7b045675c1bd0c35fe3/href</a></iframe><p>Output</p><pre>Constructor — App<br> {}                  App.js:17<br>App-render           App.js:26<br>child-render         test.js:5<br>App-Mounted          App.js:23</pre><h4>Update</h4><p>When there is Update ; It will scheduled a render call.</p><p>Our App is render ; It means its children are render.</p><p>Entire Tree is Rendered !== Entire DOM is Updated.</p><p>Now we have two DOM :- Virtual DOM And Real DOM .<strong>React</strong> will see what are the changes we have made and then it will UPDATE the REAL DOM</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c597346d8e4c87c9152b2386869d6dad/href">https://medium.com/media/c597346d8e4c87c9152b2386869d6dad/href</a></iframe><pre>                          Output @ Console</pre><pre>-------------------------------------------------------------------<br>Constructor — App<br> App-render<br> child-render<br>App-Mounted<br>------------------------------------------------------------------</pre><pre> 0 //on increment<br>App-render<br>child-render<br>prevState {value: 0}value: 0__proto__: Object<br>PrevProps {}__proto__: Object</pre><pre>------------------------------------------------------------------- <br>1//on increment<br> App-render<br> child-render<br> prevState {value: 1}value: 1__proto__: Object<br> PrevProps {}</pre><h4>UnMount</h4><p>Before Removing the Component Again the tree will be rendered and unmount is called.</p><pre>componentWillUnmount(){</pre><pre>//it is called just before the component is removed from the DOM</pre><pre>console.log(&#39;unmount&#39;);</pre><pre>}</pre><p>This give us an opportunity to do any-kind of cleanup :)</p><h4><strong>Conclusion</strong></h4><p>It is an important Concept try to understand it will and comment down if you have query.I am not an expert but a learner and our all goal is to learn and asking question and answer them is good way to brush the skill and knowledge.</p><p>Signing off — Happy Coding !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5d6ff5df053" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>