<?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 Abhaychauhan on Medium]]></title>
        <description><![CDATA[Stories by Abhaychauhan on Medium]]></description>
        <link>https://medium.com/@abhaychauhan232?source=rss-2486f09d2af9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jjWn1jsS1x5YU4fHFlDQrA.jpeg</url>
            <title>Stories by Abhaychauhan on Medium</title>
            <link>https://medium.com/@abhaychauhan232?source=rss-2486f09d2af9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 20:14:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abhaychauhan232/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[Why and how ? - Pinia]]></title>
            <link>https://medium.com/@abhaychauhan232/why-and-how-pinia-4811536184ce?source=rss-2486f09d2af9------2</link>
            <guid isPermaLink="false">https://medium.com/p/4811536184ce</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[vue]]></category>
            <category><![CDATA[vuejs-2]]></category>
            <category><![CDATA[pinia]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Abhaychauhan]]></dc:creator>
            <pubDate>Fri, 26 Aug 2022 03:56:07 GMT</pubDate>
            <atom:updated>2022-08-26T03:56:07.741Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why and how ? - Pinia</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/0*1gmseph7XoymzY9g.jpg" /><figcaption>Pinia the future for Vue apps</figcaption></figure><p><strong>Namaste</strong></p><p>I am using Pinia for the past 6 months and in this blog I would be sharing what are the main advantages that I felt makes Pinia a better option over Vuex.</p><p>Later in this blog I would also code through a simple counter application using Pinia as the store library.</p><p><strong>So first to answer the question why should we move on to pinia ?</strong></p><ol><li>The main reason will be because it is the future for global state management in Vue as Vuex is now in management mode and will not receive any new features.</li><li>Pinia provides a Composition-style-API which are much easier and intuitive to use.</li><li>Pinia is modular by design you can have multiple stores which can be imported in only the components where they are needed. This enables a better code splitting and also improves the readability of the code.</li><li><strong>No more mutations….<br></strong>Mutations are not there in pinia, your store will only consist of actions and getter functions that&#39;s it. You can directly handle async code in actions.</li><li>It has a much better devtool support than vuex with timeline, in-component inspection, and time-travel debugging.</li><li>Pinia also has built in Typescript support which helps you to leverage all the type safety and preventing potential runtime errors<br>I have not yet used it but have heard that it very awesome and easy to use.</li></ol><h4>Now coming on to the second part of this blog on how to get started with Pinia ?</h4><p>Although Pinia is supported for both Vue2 and Vue3 I will be using Vue3 with composition API just because it is easier for me and I am lazy.</p><p><em>What we will be building ?</em></p><p>We will be making one of the hardest feature out there which is making a global counter which gets incremented and decremented on respective button clicks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5P1YOMeZ-NT7kM0l" /><figcaption>Lets do it….</figcaption></figure><p>First lets add pinia to out project using</p><pre>yarn add pinia<br># or with npm<br>npm install pinia</pre><p>Now in your main.js file import createPinia function and use it in your app using the .use() functions</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*xSWpMflN4KHgwt8d_mL5rQ.png" /><figcaption>use createPinia()</figcaption></figure><p>After this step we will create a stores folder in our src folder which will have a single file counter.js</p><p>Counter.js will be the store for all the counter related actions , similarly we can have multiple stores in a single application and use them accordingly.</p><p>We will use defineStore function from pinia to create a store just as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*-Fs7yBSgHKbX4ler-QdFLw.png" /><figcaption>using defineStore to create store</figcaption></figure><p>defineStore takes 2 arguments one is the id of the store (name for the store) and second is a object which contains state actions and getters.</p><p>We can see here we do not need mutations now.</p><p>We will export this store by the name of useCounterStore always prepend use to the name of your store it is recommended.</p><p>Now the final part is how we will use it in our application.</p><p>For that we import useCounterStore in the component where we will use the counter .</p><p>I am using it in App.vue only.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3KT2hfsUA9dtL3x_e2lVIQ.png" /><figcaption>using counterStore in our app</figcaption></figure><p>You can see the comments in the code to understand what each line is doing.</p><p>This is how easy it is to use pinia for global state management in vue apps it is highly efficient due to its modular design.</p><p>Follow me get more updates on Vue Ecosystem and web development in general.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4811536184ce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How make you own custom directives in Vue.js ?]]></title>
            <link>https://medium.com/@abhaychauhan232/how-make-you-own-custom-directives-in-vue-js-a58a14adf160?source=rss-2486f09d2af9------2</link>
            <guid isPermaLink="false">https://medium.com/p/a58a14adf160</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[directives]]></category>
            <dc:creator><![CDATA[Abhaychauhan]]></dc:creator>
            <pubDate>Sun, 15 May 2022 05:12:59 GMT</pubDate>
            <atom:updated>2022-05-15T05:27:56.386Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to make you own custom directives in Vue.js ?</h3><p>Directives are one of the most easy to use functionality provided in the core modules of Vue.js. All Vue directives are prefixed with “v-”, some of the most used directives are “v-for”, “v-if”, “v-else”, “v-show” etc.</p><p><strong>But what actually are directives ans when should we use them ?</strong></p><p>Directives are instructions that mainly intend to reuse the logic for low level DOM manipulation. Directives should only be used for low level Dom access and change a bit of behavior of the Dom element.</p><p>Now lets suppose in our project we want to give different colors to different HTML elements. The most naive way to do this would be</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*t6zSculfbAMYxm33IYfXjw.png" /><figcaption>Styling use the inline css</figcaption></figure><p>But if there are like hundreds of p tags in our project then it would be a cumbersome and boring thing to do .</p><p>Now comes Vue in picture , vue allows us to make custom directives to change access the specific DOM element and change its behavior.</p><p>Lets see how can we make our custom directive that can set the color of any DOM element.</p><p>First of all we need the access of this directive in all of our components in the projects hence we will register it globally in main.js file using the app.directive() function .</p><p>This function takes in two parameters</p><ol><li>the name of the directive (vue will automatically prepend v- to the directive)</li><li>Hook function to manipulate the DOM element</li></ol><p>Make sure you register the directive before mounting the app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/1*a6HbEFdheakiQMsPLyDF9g.png" /><figcaption>How to register directive globally</figcaption></figure><p><strong>What arguments are passed to the Hook function ?</strong></p><p>The arguments received by the hook function are</p><ol><li>el : It the the element at which the directive is applied(we can access all properties of this element using el)</li><li>binding : It is an object having properties like value,oldValue,modifier,instance,dir etc;</li><li>vnode : the underlying VNode representing the bound element.</li><li>prevNode: the VNode representing the bound element from the previous render.</li></ol><p><strong>The binding object present in hook function have the multiple properties some of the main ones are :</strong></p><ol><li><strong>value</strong> : the value passed to the directive</li><li><strong>arg</strong> : The argument passed to the directive, if any. For example in v-color:foo, the arg would be foo.</li><li><strong>oldValue </strong>: The previous value present in the directive</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*vC82WKck4vUDQW_CcAUjCA.png" /><figcaption>Argument in hook function</figcaption></figure><p>Now enough with the boring theory about the directive lets jump right in and make our own directive that helps us to change the color of the DOM element easily.</p><p>Firstly we will write our hook function which will show same behavior on both being <em>updated </em>and <em>mounted .</em></p><p>I will give the directive name as “color”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*1DLHx3JRo5I0AM8PUqqtXg.png" /><figcaption>Our color directive</figcaption></figure><p>We have access to the DOM element using the <em>el</em> parameter passed in our function hence using this we can use that to change the style of that particular element.</p><p>Now to assign the value passed to the directive (which will be name of the color) to the color property of the the element we can use the binding object in our function and access <em>binding.value</em></p><p>We will not be needing the vnode and prevNode parameter hence i have removed those to eliminate the warnings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*Ns8Q2g-zlKOFzPuHuIEN7g.png" /></figure><p>AND TADAA !!!!</p><p>Our new and sweet custom directive is ready for use in our project.</p><p><strong>How to use it ?</strong></p><p>You can simply go to any of the element that you need to change color of and add a directive to it and pass the name of the color you need to change to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*qEjU1QpsFyCr774RN_nOsQ.png" /><figcaption>passing value to our custom directive</figcaption></figure><p><strong>Result</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*UAYCOv82fqqQ7q3a9w4qJA.png" /><figcaption>Result of our custom directive</figcaption></figure><p>Directives are really powerful feature in vue in my opinion they help you manage small DOM manipulation very smoothly and improved the code readability and re-usability.</p><p><strong>Please Do Like, Follow and Share , Thank you</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a58a14adf160" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>