<?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 Gyanendra Singh Panwar on Medium]]></title>
        <description><![CDATA[Stories by Gyanendra Singh Panwar on Medium]]></description>
        <link>https://medium.com/@gyanendra371?source=rss-17c5b501188a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*CwRFruwwJ_XXfXM5udWgHA.jpeg</url>
            <title>Stories by Gyanendra Singh Panwar on Medium</title>
            <link>https://medium.com/@gyanendra371?source=rss-17c5b501188a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 18:33:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gyanendra371/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[forMultipleEach]]></title>
            <link>https://medium.com/@gyanendra371/formultipleeach-c42bfccfb29?source=rss-17c5b501188a------2</link>
            <guid isPermaLink="false">https://medium.com/p/c42bfccfb29</guid>
            <category><![CDATA[array-methods]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[polyfill]]></category>
            <category><![CDATA[array-prototype]]></category>
            <dc:creator><![CDATA[Gyanendra Singh Panwar]]></dc:creator>
            <pubDate>Fri, 14 Apr 2023 18:51:38 GMT</pubDate>
            <atom:updated>2023-04-14T18:54:18.971Z</atom:updated>
            <content:encoded><![CDATA[<p>We must be wondering how to iterate multiple array simultaneously. It would be pretty easy to add a implementation for it.</p><figure><img alt="Run multiple array simultaneously" src="https://cdn-images-1.medium.com/max/1024/0*SToW1u7hiVt0cLll" /><figcaption>Photo by <a href="https://unsplash.com/it/@amutiomi?utm_source=medium&amp;utm_medium=referral">Miguel A Amutio</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Below is the implementation for ‘forMultipleEach’</p><ul><li>It return undefined when array do not have value for that index.</li><li>Added forMultipleEach method to array.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7b81bf447699f6cb4b151f44f51511d/href">https://medium.com/media/f7b81bf447699f6cb4b151f44f51511d/href</a></iframe><p>Related links :</p><p><a href="https://github.com/lodash/lodash/pull/5629">Added forMultipleEach to iterate over multiple array simultaneously by gyanendrasinghpanwar · Pull Request #5629 · lodash/lodash</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c42bfccfb29" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reacting to html events | Observer design pattern]]></title>
            <link>https://medium.com/@gyanendra371/reacting-to-html-events-observer-design-pattern-45d9d3ab49f3?source=rss-17c5b501188a------2</link>
            <guid isPermaLink="false">https://medium.com/p/45d9d3ab49f3</guid>
            <category><![CDATA[dom-manipulation]]></category>
            <category><![CDATA[dom-events]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[observer-design-pattern]]></category>
            <dc:creator><![CDATA[Gyanendra Singh Panwar]]></dc:creator>
            <pubDate>Sun, 25 Sep 2022 09:06:49 GMT</pubDate>
            <atom:updated>2022-09-25T09:06:49.933Z</atom:updated>
            <content:encoded><![CDATA[<p>I know for a fact that frontend developer need to react to various Dom events such as onClick, onChange etc.. With change of this event we need to alter various data. Sometimes those task become cumbersome and messy. Our code is not extensible and we need to put various condition to overcome various business logic. Let see how we can make such code better with observer design pattern.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QvdX_26yElJ63P6x" /><figcaption>Photo by <a href="https://unsplash.com/@dlerman6?utm_source=medium&amp;utm_medium=referral">Daniel Lerman</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Prerequisite</strong> : Basic understanding of <a href="https://en.wikipedia.org/wiki/Observer_pattern#:~:text=The%20observer%20pattern%20is%20a,calling%20one%20of%20their%20methods.">observer design pattern</a>.</p><p>Let’s take one problem statement and see what are the problem we have encountered while fixing it.</p><p><strong><em>Statement</em></strong>: — We have two input box number of items and cost and on basis of them we need to display total amount and some other business requirement validation.</p><p>I have written below code how we would solve this without including any design pattern.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b233a35f0cca0eca471fe5945453c977/href">https://medium.com/media/b233a35f0cca0eca471fe5945453c977/href</a></iframe><h4><strong>Let see what are the issue with our current approach:-</strong></h4><ul><li>Our notify function need be modified whenever we want to change business logic. Let see we have same code for admin and user and in case of admin we do not need the functionality of displaying validation message. So now we need to pass extra parameter to notify function. Our notify function is tightly coupled with business logic.</li><li>Our function <em>numberOfItemChanged and itemCostChanged</em> are not pure function.</li><li>As business requirement grow our notify function will get polluted. Our code won’t be clean and it would be violation SOLID.</li></ul><h4>Implementing observer pattern for reacting to events:-</h4><ul><li>In below code we have made notify method independent of observer.</li><li>We can dynamically attach observer(business logic) without changing notify method.</li><li>In case of admin we can dynamically remove <em>ValidationObserver </em>without putting extra condition in notify method.</li><li>Our code is extensible and scalable. We can introduce any more business logic and attach to subject. We do not need to modify any existing logic.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0251eecd36c02ca72cb976c920dd5a0c/href">https://medium.com/media/0251eecd36c02ca72cb976c920dd5a0c/href</a></iframe><p><em>Thanks for taking your time to read this article. Hope it can help you in your project. Please provide your input !</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45d9d3ab49f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Frontend Validation - Chain of Responsibility]]></title>
            <link>https://medium.com/@gyanendra371/frontend-validation-chain-of-responsibility-8aca976f07ea?source=rss-17c5b501188a------2</link>
            <guid isPermaLink="false">https://medium.com/p/8aca976f07ea</guid>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[chain-of-responsibility]]></category>
            <category><![CDATA[design-patter]]></category>
            <category><![CDATA[solid-principles]]></category>
            <category><![CDATA[behavioral-design-pattern]]></category>
            <dc:creator><![CDATA[Gyanendra Singh Panwar]]></dc:creator>
            <pubDate>Sat, 24 Sep 2022 09:02:41 GMT</pubDate>
            <atom:updated>2022-09-26T06:27:15.838Z</atom:updated>
            <content:encoded><![CDATA[<p>I have seen people putting various validation in frontend where code is not scalable and extensible. Such code are nowhere near to SOLID principles. These code are messy and result in polluting html and js/ts file as they have various condition for every case. One approach will be to use is Chain of responsibility design pattern for this use case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*myZ5do-GHm4uG-qu" /><figcaption>Photo by <a href="https://unsplash.com/@mael_balland?utm_source=medium&amp;utm_medium=referral">Mael BALLAND</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Prerequisite — </strong><a href="https://en.wikipedia.org/wiki/Chain-of-responsibility_pattern"><strong>Chain of Responsibility</strong></a></p><p>The <strong>chain-of-responsibility pattern</strong> is a <a href="https://en.wikipedia.org/wiki/Behavioral_pattern">behavioral</a> <a href="https://en.wikipedia.org/wiki/Design_pattern_(computer_science)">design pattern</a> consisting of a source of command of object and a series of <strong>processing objects</strong>. Each processing object contains logic that defines the types of command objects that it can handle; the rest are passed to the next processing object in the chain. A mechanism also exists for adding new processing objects to the end of this chain.</p><p><strong>Problems encountered during validation</strong></p><ul><li>Do not follow the DRY principle — Let say if we want to validate password filed. We have to first validate whether field is empty or not. This validation will be at all place whether it is email or password. So we need to have same code for it at all place.</li><li>Violation of Single responsibility principle — Let say we have email validation code so its responsibility is to only check whether email entered is correct or not. It should not check whether email address is provided or not. We can argue about its responsibility but it would be clear with below code. Now this code can not be used for optional email(when it is not mandatory to have email field) .</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a04329d4621b33e7b50860445852e561/href">https://medium.com/media/a04329d4621b33e7b50860445852e561/href</a></iframe><p><strong>Validation implementation with Chain of responsibility</strong></p><p>Let see how below code is DRY and following SOLID.</p><ul><li>We do not need repeat the required field code everywhere. Let’s say in future we need to do password validation so we do not need to rewrite the required field validation code. We can just implement password validation. Our code is following Open and Closed principle.</li><li>We can use same email validation class irrespective if email is required field or not. It is now following Single responsibility principle.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f88a70b46dd5453cdc8bfb362e4e07dd/href">https://medium.com/media/f88a70b46dd5453cdc8bfb362e4e07dd/href</a></iframe><p><strong>Exploration:-</strong></p><blockquote>Let say in future we need to add one more validation to email field while doing sign up in application. We need to verify whether email is already registered or not. We can add one more class <em>RegisterdEmailHandler </em>and this can be added to chain of emailValidation.</blockquote><p>Thanks for taking your time to read this article. Hope it can help you in your project. Please provide your input !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8aca976f07ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>