<?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: Deepak Sisodiya</title>
    <description>The latest articles on DEV Community by Deepak Sisodiya (@deepaksisodiya).</description>
    <link>https://dev.to/deepaksisodiya</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%2F167801%2F6837e800-6869-4a14-9d2b-9d91494fc686.png</url>
      <title>DEV Community: Deepak Sisodiya</title>
      <link>https://dev.to/deepaksisodiya</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/deepaksisodiya"/>
    <language>en</language>
    <item>
      <title>5 best practices for clean coding in JavaScript</title>
      <dc:creator>Deepak Sisodiya</dc:creator>
      <pubDate>Thu, 10 Sep 2020 12:40:29 +0000</pubDate>
      <link>https://dev.to/deepaksisodiya/5-best-practices-for-clean-coding-in-javascript-26am</link>
      <guid>https://dev.to/deepaksisodiya/5-best-practices-for-clean-coding-in-javascript-26am</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;“Even bad code can function. But if the code isn’t clean, it can bring a development organisation to its knees.” — Robert C. Martin (Uncle Bob)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Clean coding means that you write code for your later self and your co-workers and not for the machine. Your code must be easily understandable for humans.&lt;/p&gt;

&lt;p&gt;Here are some of the clean coding practices which I follow while writing Javascript code. These are not framework-specific practices and can be used with any framework.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Write simple code&lt;/strong&gt;&lt;br&gt;
Code should be simple enough to understand. For example, if we have to write a method that takes an array of number and return the new array with each number in array double its value. This can be implemented as.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4DEYSg3U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AxQyzv2NiEGuWSMh8AytC2w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4DEYSg3U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AxQyzv2NiEGuWSMh8AytC2w.png" alt="Alt text of image"&gt;&lt;/a&gt;&lt;br&gt;
Instead of the above code, we should do it like this.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0XeVm8Np--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AcXpg6hLmoxq4BRVtpkJH8Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0XeVm8Np--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AcXpg6hLmoxq4BRVtpkJH8Q.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Write linear code&lt;/strong&gt;&lt;br&gt;
Nested code is hard to understand. Always write the linear code as much as possible. It makes our code simple, clean, easy to read and easy to maintain thus makes developer life easier.&lt;/p&gt;

&lt;p&gt;For Example, let’s write a function which sends the email to the issue owner.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tdm4LkQh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AgnRgaofYbb5kv-iFKx68WQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tdm4LkQh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AgnRgaofYbb5kv-iFKx68WQ.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
Now let’s look at the same code implemented with async/await&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dHgJbLty--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AG7vTcYXjHd4KBRpw_F568w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dHgJbLty--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AG7vTcYXjHd4KBRpw_F568w.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
Let’s look at another example&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--c-TRYhAD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AoqEojwKjF-FINxv1QOeeDQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--c-TRYhAD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AoqEojwKjF-FINxv1QOeeDQ.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
Now let’s look at the same code implemented with the &lt;strong&gt;fail-fast approach&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TFrtsNoK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2Ag4zorQL15q8Jq6Vjf-gJBQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TFrtsNoK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2Ag4zorQL15q8Jq6Vjf-gJBQ.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Better naming of variables and methods&lt;/strong&gt;&lt;br&gt;
It improves code readability and code become easier to maintain. Names should be meaningful and have context. By reading the name of function or variable one should understand its purpose. Example&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MtKQFmcB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2A-_iLwRYiZcsNxGHBSxvhow.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MtKQFmcB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2A-_iLwRYiZcsNxGHBSxvhow.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
Always make affirmative names. So instead of &lt;em&gt;isNotActive&lt;/em&gt; use &lt;em&gt;!isActive&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Functions should do one thing&lt;/strong&gt;&lt;br&gt;
Function should not be larger than 20–25 lines. Smaller the function is better. Function should either modify or query something but not both. Consider the following code.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--t3DbRjJo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AlDl_Qen9WWnZaMiG23qbIg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--t3DbRjJo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AlDl_Qen9WWnZaMiG23qbIg.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
The same thing can be done in a cleaner way&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vfFQbVmq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AO3J6wE0ruVNRUJxViW6ocA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vfFQbVmq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AO3J6wE0ruVNRUJxViW6ocA.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Use ESLint, Prettier and latest JavaScript&lt;/strong&gt;&lt;br&gt;
Always use ESLint and Prettier to make common coding style across developers, find syntax error and code formatting. Use JavaScript latest features to write code, like de-structuring, spread operator, async-await, template literals, optional chaining and more. Some Examples are&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OM5c_k5l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AMKfiyv-GbZn5SF8UhQQOkg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OM5c_k5l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1400/1%2AMKfiyv-GbZn5SF8UhQQOkg.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;I hope this post has been helpful and thanks for reading. The feedbacks are always welcome.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>vue</category>
      <category>react</category>
    </item>
    <item>
      <title>Working with Dynamic Components in Vue.js</title>
      <dc:creator>Deepak Sisodiya</dc:creator>
      <pubDate>Sat, 19 Oct 2019 13:33:42 +0000</pubDate>
      <link>https://dev.to/deepaksisodiya/working-with-dynamic-components-in-vue-js-56ag</link>
      <guid>https://dev.to/deepaksisodiya/working-with-dynamic-components-in-vue-js-56ag</guid>
      <description>&lt;p&gt;To understand what is a dynamic component, let's consider an example. Suppose we are developing a commenting platform where user can come and post a comment on the article. Posting of comment for the logged-in and logged-out user is different.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--V9H6w2C6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/2112/1%2ANYu7PMJkXewe27Mm3LU3nw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--V9H6w2C6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/2112/1%2ANYu7PMJkXewe27Mm3LU3nw.png" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;
Logged-in user



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Qf1Hjs78--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/2096/1%2AIr-XToqO7zawHp-MtCea-Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Qf1Hjs78--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/2096/1%2AIr-XToqO7zawHp-MtCea-Q.png" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;
Logged-out user



&lt;p&gt;In the case of the logged-in user, we want to load CommentBoxLoggedIn component and for the logged-out user, we want to load CommentBoxLoggedOut component. Here we are mounting the component dynamically depending on if the user is logged-in or logged-out, that's where we want to use the dynamic component concept.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Component 
  :is="dynamicComponent" 
  v-bind="dynamicComponentProps" 
/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;is attribute is a reference to the dynamic component and the v-bind attribute is used to pass dynamic component props. Let's see the example.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--R18zirdZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/3356/1%2AzHNAPj0Tko1M5PhbyCKl3Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--R18zirdZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/3356/1%2AzHNAPj0Tko1M5PhbyCKl3Q.png" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;
Using a dynamic component



&lt;p&gt;In the example above we are calculating the dynamic component and dynamic component props as a computed prop. Notice the parentId is always 0 in case of the top-level comment.&lt;/p&gt;

&lt;p&gt;This looks like a simple if/else solution. But using this approach we can make our code more scalable and readable moving the logic out of the template. We can also add animation with a dynamic component using Vue.js Transition &lt;a href="https://vuejs.org/v2/guide/transitions.html#Transitioning-Between-Components"&gt;https://vuejs.org/v2/guide/transitions.html#Transitioning-Between-Components&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This approach has one more advantage. Suppose we have reply action in each comment of the article. On click of reply action, we want to load the same dynamic component CommentBoxLoggedIn and CommentBoxLoggedOut depending on if the user logged-in or logged-out but with modified/different props.&lt;/p&gt;

&lt;p&gt;For this, we can pass the computed props commentBoxComponentName and commentBoxComponentProps to a child component, let say to CommentItem component which renders single comment. Now CommentItem component receiving the commentBoxComponentProperties and commentBoxComponentName as a props. Let's see the example&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GTMGWX1e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/3560/1%2AZYZz10hOoiQaXPvriVGEPw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GTMGWX1e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/3560/1%2AZYZz10hOoiQaXPvriVGEPw.png" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;
Extending the dynamic component props and using in the template



&lt;p&gt;In the example above we are extending commentBoxComponentProperties with parentId because in case of reply parentId is different for each comment. and at the same time, we are using dynamic components in the template. This way we are making our code more structured and manageable.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>vue</category>
    </item>
    <item>
      <title>Top VS Code Extensions For Vue.js Development</title>
      <dc:creator>Deepak Sisodiya</dc:creator>
      <pubDate>Fri, 11 Oct 2019 07:52:03 +0000</pubDate>
      <link>https://dev.to/deepaksisodiya/top-vs-code-extensions-for-vue-js-development-3ifk</link>
      <guid>https://dev.to/deepaksisodiya/top-vs-code-extensions-for-vue-js-development-3ifk</guid>
      <description>&lt;p&gt;I have beeing using VS Code from last around 2 years. Before that, I was using webstorm for JavaScript development. But I found the VS Code more useful. Now it is my primary editor for any JavaScript development. The most important feature of VS Code is that it has a lot of plugins for your specific requirement. This makes it easy to use for everyone whether he/she is an experienced developer or new developer. Today I am sharing some useful extension for Vue.js development.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=octref.vetur"&gt;Vetur&lt;/a&gt;&lt;br&gt;
This is the most useful plugins for Vue.js development. This plugin is specific to vue.js development. It has Syntax-highlighting, Snippet support, Formatting, lots of Framework Support and more. checkout &lt;a href="https://vuejs.github.io/vetur/"&gt;https://vuejs.github.io/vetur/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://quokkajs.com/docs/"&gt;Quokka.js&lt;/a&gt;&lt;br&gt;
This one is my favourite. Generally, when we want to do some stuff in JavaScript we will go to either jsbin or jsfiddle or codepan. But this plugin gives the same thing in VS Code itself. Like&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3HU3Rj9e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/2348/1%2AkWbMpYUy0R1KcdTvCU_DzQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3HU3Rj9e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/2348/1%2AkWbMpYUy0R1KcdTvCU_DzQ.png" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-close-tag"&gt;Auto Close Tag&lt;/a&gt;&lt;br&gt;
This plugins automatically add HTML/XML close tag. From VS Code 1.16, it has built-in close tag support for HTML, Handlebars and Razor files. This extension is enabled for other languages like XML, PHP, Vue, JavaScript, TypeScript, JSX, TSX and so on. It is configurable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=steoates.autoimport&amp;amp;ssr=false#review-details"&gt;Auto Import&lt;/a&gt;&lt;br&gt;
Automatically finds, parses and provides code actions and code completion for all available imports.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer"&gt;Bracket Pair Colorizer&lt;/a&gt;&lt;br&gt;
This extension allows matching brackets to be identified with colours. The user can define which characters to match, and which colours to use. Like&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qjau3i_m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/3684/1%2ABN02cbEumNG0VWoeQMwLzw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qjau3i_m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/3684/1%2ABN02cbEumNG0VWoeQMwLzw.png" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint"&gt;ESLint&lt;/a&gt;&lt;br&gt;
Integrates ESLint JavaScript into VS Code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode"&gt;Prettier&lt;/a&gt;&lt;br&gt;
It is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens"&gt;GitLens&lt;/a&gt;&lt;br&gt;
This is a very useful plugin. It adds Git capabilities built into Visual Studio Code — Visualize code authorship at a glance via Git blame annotations and code len and many more things.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=aaron-bond.better-comments"&gt;Better Comments&lt;/a&gt;&lt;br&gt;
The Better Comments extension will help you create more human-friendly comments in your code. It highlights your comments with colour. Like&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--t7awPBY1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/2284/1%2ABAPRm0wpNy_ZQD3q6tP5TA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--t7awPBY1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/2284/1%2ABAPRm0wpNy_ZQD3q6tP5TA.png" alt="Alt text of image"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=will-stone.plastic"&gt;Plastic&lt;/a&gt;&lt;br&gt;
Plastic is my favourite theme for VS Code. Try it, you will love its simplicity.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>javascript</category>
      <category>vue</category>
      <category>vscode</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
