<?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 Eze Henry on Medium]]></title>
        <description><![CDATA[Stories by Eze Henry on Medium]]></description>
        <link>https://medium.com/@Godofjs?source=rss-9ec1be7e3038------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*FNUxWi3TW3iwKgYDMg4Ftw.jpeg</url>
            <title>Stories by Eze Henry on Medium</title>
            <link>https://medium.com/@Godofjs?source=rss-9ec1be7e3038------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 11:21:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Godofjs/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[Implementing Webpack’s Module federation in a Vue 2 application.]]></title>
            <link>https://medium.com/geekculture/implementing-webpacks-module-federation-in-a-vue-2-application-38997c696094?source=rss-9ec1be7e3038------2</link>
            <guid isPermaLink="false">https://medium.com/p/38997c696094</guid>
            <category><![CDATA[webpack-5]]></category>
            <category><![CDATA[vue-2]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[module-federation]]></category>
            <dc:creator><![CDATA[Eze Henry]]></dc:creator>
            <pubDate>Tue, 07 Dec 2021 13:12:38 GMT</pubDate>
            <atom:updated>2021-12-17T07:33:53.713Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JPa0YECwJpuERsyH2k-B8g.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@mangofantasy?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Tim Johnson</a> on <a href="https://unsplash.com/s/photos/coupled-components?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>Micro Frontends:</h3><p>The micro frontend is a frontend architecture where modules of the same product/application are built independently of each other.</p><p>This architecture has proven to be really scalable so I decided to employ this architecture in my most recent project. Weeks into the development, I had a vue2 application and a Gridsome application. Since these two applications utilized the same design system, I copy/pasted components that were mutual to both applications which is not maintainable, and copy/pasting the components goes against the <a href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY principle.</a> I decided to find a more scalable solution which made me select Webpack’s module federation.</p><p>For this demo, we would be setting up Webpack’s module federation from start to finish. So, fasten your seatbelts 😃.</p><h4>Requirements</h4><ol><li>Two already set up vue2 projects: We won’t be covering this on this blog post. If you are having issues setting up your vue project, visit the <a href="https://cli.vuejs.org/guide/creating-a-project.html#vue-create">vue documentation</a>.</li></ol><h4>Installations</h4><p>To properly configure Webpack, we would need to add some dev dependencies to our project. P.S: These steps should be done for both projects. To add dev dependencies, we would run the command:</p><pre>yarn add webpack webpack-cli webpack-dev-server vue-loader url-loader sass-loader mini-css-extract-plugin html-webpack-plugin dart-sass css-loader -D</pre><p>When that has been done, we would need to add a start script to our package.json. The goal of this script is to utilize Webpack-CLI when starting the server as opposed to the vue-cli. The scripts section of our package.json should now contain a start script:</p><pre>&quot;scripts&quot;: {</pre><pre>&quot;serve&quot;: &quot;vue-cli-service serve&quot;,</pre><pre>&quot;build&quot;: &quot;vue-cli-service build&quot;,</pre><pre>&quot;start&quot;: &quot;webpack-cli serve&quot;,</pre><pre>&quot;lint&quot;: &quot;vue-cli-service lint&quot;</pre><pre>},</pre><p>If you run the yarn start command, you would notice there is an error…. Don’t fret…. yet 😏.</p><h4>Now let’s Begin…</h4><p>In this blog post, we would have two projects. Micro-main is the project that needs the shared components and web-common is the project that contains the shared components.</p><p>In both projects, we would create a webpack.config.js file in the root directory:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*OF-SkXPVkF_BuZ4Z7FcrGA.png" /><figcaption>The location of the webpack.config.js file in the project.</figcaption></figure><p>Now that we have created our webpack.config.js file, we would populate it with:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64652ed1244a0d0c3c4e0662041b353f/href">https://medium.com/media/64652ed1244a0d0c3c4e0662041b353f/href</a></iframe><p>The webpack.config.js file of both applications should contain the following code <strong>BUT remember to give the two projects different port variables</strong>. By now, if you run the yarn start command, you should have a happy server 😄.</p><p>Now let’s explain the important parts of what’s been written here.</p><ol><li><a href="https://webpack.js.org/concepts/entry-points/">Entry Point</a>: The entry point is the file that Webpack uses as the starting point. By default, Webpack uses the src/index.js as the entry point. But to conform with the Vue approach we set the entry point as src/main.ts .</li><li><a href="https://webpack.js.org/concepts/output/">Output</a>: The output is where we specify where our bundled application should be placed after the build. By default, Vue applications are built into the dist directory so it’s only right to place the Webpack build in the dist folder.</li><li><a href="https://webpack.js.org/configuration/resolve/#resolveextensions">Resolve</a>: Resolve changes how modules are resolved. It also helps in setting aliases. In our use case, we added a shortcut to the assets folder by adding the @assets property in the resolve.alias. This would make all files in the assets directory accessible through @assets/path/to/file</li><li><a href="https://webpack.js.org/concepts/loaders/">Rules</a>: By default, Webpack only understands Javascript and JSON files. And that is where loaders come in. Loaders make it possible for Webpack to understand other files like typescript, Vue, CSS, e.t.c. In our case, we have added loaders for Vue, typescript, CSS, and SASS.</li><li><a href="https://webpack.js.org/configuration/plugins/">Plugins</a>: Plugins are used to customize the Webpack build process in a variety of ways.</li><li><a href="https://webpack.js.org/configuration/dev-server/#devserver">devServer</a>: This is where the configuration for what’s needed to develop the application is placed.</li></ol><p>After populating your webpack.config.js , navigate to http://localhost:${port} . You would notice that it’s an empty page without the logo of the application and the server is probably crying 😢. To fix this, replace dynamic variables in the public/index.html e.g:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/887545309f24887b894fa071a90d306d/href">https://medium.com/media/887545309f24887b894fa071a90d306d/href</a></iframe><p>After this, if you still have a blank page, check the console and you may see:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dj7D5C2eYQwQi-KKnygH4w.png" /><figcaption>An error resulting from using environment variables in the router.</figcaption></figure><p>To fix this issue, we would add a new plugin:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80301616cc3f561497c0f4265da4e0eb/href">https://medium.com/media/80301616cc3f561497c0f4265da4e0eb/href</a></iframe><p>After this, you can now navigate to your website and see a happy website 👌.</p><h4>Module Federation</h4><p>We are done setting up Webpack and we now have happy servers and a working website. Now, it’s time for us to implement the module federation.</p><p>All the sauce of the module federation is contained in the ModuleFederationPlugin . In this part of the configuration, the two codebases have different configurations.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/78cffbdd55996be3e54c136f9bd71cb0/href">https://medium.com/media/78cffbdd55996be3e54c136f9bd71cb0/href</a></iframe><h4>Few things to note:</h4><ol><li>The ModuleFederationPlugin is imported from require(&quot;webpack&quot;).container and not from require(&quot;webpack&quot;).</li><li>The exposes object of the ModuleFederationPlugin is what’s responsible for sharing code from the project. Also, the keys of the exposes object must be in the format of ./[KEY_NAME].</li><li>The filename can be named anything. But remoteEntry or web_commonRemoteEntry is a great name for it.</li><li>The name can be named anything as well, but I would give it the name of the project.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af2f3d23272415f6b0055043fbd49237/href">https://medium.com/media/af2f3d23272415f6b0055043fbd49237/href</a></iframe><h4>Few things to note:</h4><ol><li>The remotes is where we add remotes of projects we are receiving shared code from.</li><li>The web_common is the name of the project we are receiving shared code from.</li><li>the remote of the project sharing code must be of the format [PROJECT_NAME]@[PROJECT_URL]/[PROJECT_filename] in our case, the filename is remoteEntry.js</li></ol><p>To test the implementation, we would globally import the component. I.E:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ae0771516436441b49b61b497189c9b/href">https://medium.com/media/2ae0771516436441b49b61b497189c9b/href</a></iframe><p>If you make use of typescript, you may need to declare web_common as a module.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5b41cd2d03cd1f9e34ff27c5e1b162a/href">https://medium.com/media/a5b41cd2d03cd1f9e34ff27c5e1b162a/href</a></iframe><p>By now, the server should be happy.</p><p>Now, the HelloWorld component can be used in the main project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2da8eb5239a2b10d50a0b53b5ea79edd/href">https://medium.com/media/2da8eb5239a2b10d50a0b53b5ea79edd/href</a></iframe><p>And, Here is the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AlsdYjQSQkgQzQVYEU0fMw.png" /><figcaption>The HelloWorld component was imported from the web_common project to the main project.</figcaption></figure><h4>One more issue….</h4><p>Hurray!! we are done with the module federation… But you have probably noticed that navigating to another route and reloading the page would cause a 404 which hampers the developer experience😿.</p><p>The fix is to set the <a href="https://webpack.js.org/configuration/dev-server/#devserverhistoryapifallback">historyApiFallback</a> to true.</p><pre>// webpack.config.js<br>module.exports = {<br>  //...<br>  devServer: {<br>    historyApiFallback: true,<br>  },<br>};</pre><h4>Conclusion</h4><p>In this blog post, I gave a clear step-by-step procedure on how to set up Webpack and how to properly set up the module federation plugin. Feel free to reach out to me if this article does not do justice to your use case.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38997c696094" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/implementing-webpacks-module-federation-in-a-vue-2-application-38997c696094">Implementing Webpack’s Module federation in a Vue 2 application.</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building with a design system in a tailwind application.]]></title>
            <link>https://medium.com/geekculture/building-with-a-design-system-in-a-tailwind-application-ac55fa929519?source=rss-9ec1be7e3038------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac55fa929519</guid>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[tailwind]]></category>
            <category><![CDATA[ui-design]]></category>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[Eze Henry]]></dc:creator>
            <pubDate>Tue, 09 Nov 2021 02:03:24 GMT</pubDate>
            <atom:updated>2021-11-09T02:03:24.537Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Design systems bring uniformity in designs. The organization of the design system on the front end also encourages the adoption of the design system and makes it more receptive to change.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xzSA6VEdg5VFCjYs_X1VtQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@balazsketyi?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Balázs Kétyi</a> on <a href="https://unsplash.com/s/photos/design-system?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>What is a design system?</h3><p>A <strong>design system</strong> is a collection of reusable components, guided by clear standards, that can be assembled together to build any number of applications.</p><p>According to Diana Mounter the design systems manager at GitHub, “Design systems are always evolving, and the way you share and encourage the adoption of new iterations will evolve along the way as well.”</p><p>Considering design systems are always evolving, I believe it is only right for them to be implemented in a way that is easily maintainable and easy to change. For example, if there was ever a change of brand colors, then switching to the new colors should be almost seamless and done from the global context as opposed to editing multiple lines of code in the application.</p><p>In this blog post, I would go through procedures I take when working with a design system. The styling framework of choice is <a href="https://tailwindcss.com/">Tailwind</a>, but these procedures can be taken with any styling framework or even plain CSS/SCSS.</p><h3>Adding Base Styles</h3><p>Base styles are the styles at the beginning of a stylesheet that set useful defaults for basic HTML elements. When working with a design system, some tags have a recommended or default style. For example, a design system could signify that all h1 tags by default should have font-weight set as bold and the font-family as nunito-sans. It would be repetitive to add the font-family class to every h1 tag being used. It would also be overkill to create a component for the h1 tags and I feel it should be malpractice. The cleanest solution would be to add base styles for that HTML tag.</p><pre>/****</pre><pre>tailwind.css || a global css file(if tailwind is not being used).</pre><pre>****/</pre><pre>@tailwind base;</pre><pre>@tailwind components;</pre><pre>@tailwind utilities;</pre><pre>@layer base {</pre><pre>h1 {</pre><pre>@apply font-nunito-sans text-3xl md:text-4xl font-bold</pre><pre>}</pre><pre>h2 {</pre><pre>@apply font-nunito-sans text-2xl md:text-3xl font-bold</pre><pre>}</pre><pre>p {</pre><pre>@apply font-nunito-sans text-xs md:text-xs font-bold</pre><pre>}</pre><pre>}</pre><p>The code above sets the base style for the h1, h2, and p tags. These HTML tags when used would have the default style set above. But this default style can still be overridden:</p><pre>&lt;h1 class=&quot;text-2xl font-bold text-left text-black font-halant&quot;&gt;</pre><pre>Sign In</pre><pre>&lt;/h1&gt;</pre><h3><strong>Adding custom colors</strong></h3><p>Design systems come with custom colors and sometimes, tailwind does not offer all or even most of the colors needed. In this case, it’s best to go, rogue, 😄 and create your own colors by adding a color object to the theme object of the tailwind.config:</p><pre>// tailwind.config.js</pre><pre>module.exports = {</pre><pre>purge: [&quot;./index.html&quot;, &quot;./src/**/*.{vue,js,ts,jsx,tsx}&quot;],</pre><pre>darkMode: false, // or &#39;media&#39; or &#39;class&#39;</pre><pre>theme: {</pre><pre>extend: {},</pre><pre>// get colors subsequently.</pre><pre>colors: {</pre><pre>primary: &quot;#06818F&quot;,</pre><pre>&quot;primary-a10&quot;: &quot;#06818F10&quot;,</pre><pre>&quot;primary-a24&quot;: &quot;#06818F24&quot;,</pre><pre>&quot;primary-a75&quot;: &quot;#06818F75&quot;,</pre><pre>&quot;primary-a99&quot;: &quot;#06818F99&quot;,</pre><pre>secondary: &quot;#E1F5F7&quot;,</pre><pre>&quot;secondary-a10&quot;: &quot;#E1F5F710&quot;,</pre><pre>white: &quot;#FFFEFF&quot;,</pre><pre>success: &quot;#22BF3E&quot;,</pre><pre>&quot;success-a10&quot;: &quot;#22BF3E10&quot;,</pre><pre>danger: &quot;#FF5F56&quot;,</pre><pre>&quot;danger-a10&quot;: &quot;#FF5F5610&quot;,</pre><pre>warning: &quot;#FEAD54&quot;,</pre><pre>&quot;warning-a10&quot;: &quot;#FEAD5410&quot;,</pre><pre>&quot;warning-a24&quot;: &quot;#FEAD5424&quot;,</pre><pre>black: &quot;#1E1E24&quot;,</pre><pre>&quot;black-a50&quot;: &quot;#1E1E2470&quot;,</pre><pre>grey: &quot;#C4CECF&quot;,</pre><pre>}</pre><pre>},</pre><pre>variants: {</pre><pre>extend: {},</pre><pre>},</pre><pre>plugins: [],</pre><pre>};</pre><p>This is going to override the default colors that came with tailwind with your new colors.</p><p>There are a few rules I follow when naming color variables:</p><p>a. Make use of contextual names as opposed to direct color names: Making use of contextual names for colors such as primary, secondary, warning, e.t.c makes it easier to maintain as opposed to names like green, red, white, e.t.c. If green is used in place of primary, if the brand color changes to purple, you would not only need to edit the variable value but also the name which means you would need to go edit the name everywhere it was used which makes it very difficult to change.</p><p>b. Using the term alpha for colors with a degree of opacity: When naming colors, I make use of names like primary-a10 which signifies the primary color with 10% opacity. The alpha channel is a color component that represents the degree of transparency (or opacity) of a color.</p><h3>Creating base components</h3><p>Base components are components that act like HTML tags or that apply app-specific styling and conventions. Most times, it’s best to build out components of the design system and make use of them around your application as opposed to designing them separately everywhere it is being used. This way, some behaviors could be shared e.g. Adding a loader to a button or adding an error/success state to an input.</p><h3>Conclusion</h3><p>These few procedures make it easier for me to work with design systems and easier for me to maintain frontend codebases.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac55fa929519" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/building-with-a-design-system-in-a-tailwind-application-ac55fa929519">Building with a design system in a tailwind application.</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working with a flat component directory structure in vue]]></title>
            <link>https://medium.com/geekculture/working-with-a-flat-component-directory-structure-in-vue-6892e121f543?source=rss-9ec1be7e3038------2</link>
            <guid isPermaLink="false">https://medium.com/p/6892e121f543</guid>
            <category><![CDATA[structure]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[components]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[organization]]></category>
            <dc:creator><![CDATA[Eze Henry]]></dc:creator>
            <pubDate>Mon, 13 Sep 2021 07:19:58 GMT</pubDate>
            <atom:updated>2021-10-15T15:06:16.451Z</atom:updated>
            <content:encoded><![CDATA[<p>Vue developers glorify making use of nested directory structure in the components directory of Vue. Well, I have worked with both structures on large-scale projects and I am here to share some views on why I prefer a flat directory structure to a nested directory structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LIYcEHsnc35enCGBP7kpBg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@lishakov?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Andrej Lišakov</a> on <a href="https://unsplash.com/s/photos/flat?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Have you ever worked on a project where you had tons of components and made use of the nested architecture? Let me guess, at some point in the project, you asked yourself what is the best directory to place this particular component. Well, it happens to me a lot when I make use of a nested architecture so I would go ahead and assume it probably happens to you as well. P.S: I may be wrong and probably the only one who has ever faced this issue(But it is highly unlikely).</p><p>When I work with a nested component directory architecture, I face problems like:</p><ol><li>Taking a long time to decide on the particular component sub-directory to place a component.</li><li>Giving two components the same name. (This is more rampant when working in a team that changes happen in real-time) e.g having two files like:</li></ol><pre>src\components\dashboard\QuickActions.vue</pre><pre>And</pre><pre>src\components\profile\QuickActions.vue</pre><p>This could easily bring confusion especially when debugging.</p><p>When a flat component directory structure is used correctly, it eradicates these issues and brings extra advantages. e.g, if I was to represent this using a flat structure, I would name it this way:</p><pre>src\components\DashboardQuickActions.vue</pre><pre>And</pre><pre>src\components\ProfileQuickActions.vue</pre><p>And when these components are used in the template of a vue project, it makes it easier to read, track the exact file, and also makes it easier to differentiate between the two quick actions components. e.g:</p><pre>&lt;dashboard-quick-actions /&gt;<br>&lt;profile-quick-actions /&gt;</pre><p>You are probably saying to yourself: The flat directory structure is not scalable, the grouping of the components could become a mess and the list of files in the directory would grow to be so large. Well, that’s why I am here to show you how to handle this issue effectively 😃.</p><p>First, I would start by telling you the benefits of the flat directory structure:</p><ol><li>The few minutes spent deciding the folder a particular component should go into is eradicated.</li><li>Automation of components through tools like <a href="https://www.hygen.io/">hygen</a> is easier and straightforward.</li><li>There is no possibility of giving two components the same name hence, it could reduce your debugging time.</li><li>It is really easy to group components e.g:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*-GIxMyREnkEPZOpWmQ9VXQ.png" /><figcaption>A group of base components.</figcaption></figure><p>When working with a flat component directory, we still want to be able to group files for ease of access and organization. The best way to achieve this is by using the names of the components by starting the component with the highest level element or parent component. e.g. if we were to have a component named CalendarWidget, and we needed other atoms of the widget like the weekdays, day item, etc. the highest level element, in this case, would be CalendarWidget, hence, the naming of the files would be in the format:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*W1mlXTW6xiizt4t2jVbx7w.png" /><figcaption>Proper grouping of a CalendarWidget component.</figcaption></figure><p>Using this naming format, all components are linked with the highest element or parent component which is CalendarWidget in this case.</p><h3>Navigating through the long length of files</h3><p>You are probably asking, how do you deal with scrolling through the files when you have a very long list of components? Well, except for the fact that it is properly grouped by name, files can be easily located using some quick shortcuts on your preferred IDE. e.g, I make use of visual studio code, and in visual studio code, locating a file can be easily achieved by the command:</p><pre>ctrl + p</pre><p>After which, VS code puts forth a search input box to find the component by name. Whatever tool you use, I can bet there is a shortcut to find files by name. I guess this is a call for you to do research on your chosen IDE and find out the shortcuts that could help increase your productivity. Since you work with your IDE every day, make it your friend 😃.</p><h3>Summary</h3><p>As much as I emphasized more on the flat directory structure, both structures are still great and either of them could suit your team&#39;s needs. But, I have found the flat directory structure easier to work with and automate plus it scales just exactly as the nested structure does.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6892e121f543" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/working-with-a-flat-component-directory-structure-in-vue-6892e121f543">Working with a flat component directory structure in vue</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generating files in a Vue application using Hygen]]></title>
            <link>https://medium.com/swlh/generating-files-in-a-vue-application-using-hygen-65abc40e7af5?source=rss-9ec1be7e3038------2</link>
            <guid isPermaLink="false">https://medium.com/p/65abc40e7af5</guid>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[hygen]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[vue]]></category>
            <dc:creator><![CDATA[Eze Henry]]></dc:creator>
            <pubDate>Mon, 26 Jul 2021 10:21:26 GMT</pubDate>
            <atom:updated>2021-07-26T10:21:26.709Z</atom:updated>
            <content:encoded><![CDATA[<h4>Automation of repetitive tasks improves productivity and gives little allowance to human errors that arise due to repetition and I am here to tell and show you how.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ihN2ovPtrFdCSFpGAs-ABA.jpeg" /><figcaption>Photo by <a href="https://www.pexels.com/@anete-lusina?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Anete Lusina</a> from <a href="https://www.pexels.com/photo/modern-printer-with-paper-in-office-4792283/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Pexels</a></figcaption></figure><p>Growing to become a senior software engineer has prompted a lot of change to the processes I take in writing code starting from my file structure, to my directory structure to the way I structure my tests, to my code quality, and a lot more. Recently, I got to a point where I had to change my file structure and write the unit test of a component directly beside the component for ease of access and to prompt me to write unit tests for all my components. As time went on, The process of creating the files along with their unit tests and initializing the files with the needed or default structure started becoming repetitive, boring, and a waste of time. I searched for tools to solve this issue and immediately fell in love with <a href="https://www.hygen.io/">Hygen</a>.</p><p><a href="https://www.hygen.io/">Hygen</a> is a scalable code generator that saves time.</p><p>In this blog post, we would be making use of <a href="https://www.hygen.io/">Hygen</a> in a vue-ts application, but it can be used with any tech stack at all. As a matter of fact, it was created specifically to serve react and node.js developers but here we are using it in a vue-ts application 😅.</p><p>For the sake of this project, we would be sticking strictly to <a href="https://www.hygen.io/">Hygen</a> and not going deep into the initialization of other technologies.</p><h3><strong>Prerequisites</strong></h3><ol><li><a href="https://nodejs.org/en/download/"><strong>Node.js</strong></a>: to make use of NPM for the global installation.</li><li><strong>A project of any stack</strong>: But for the sake of this blog post, we would be making use of <a href="https://vuejs.org/">Vue</a>. to create a <a href="https://vuejs.org/">Vue</a> project, go through the <a href="https://cli.vuejs.org/guide/creating-a-project.html">documentation</a>.</li></ol><h3><strong>Let’s Begin</strong></h3><p>First and foremost, we would need to add <a href="https://www.hygen.io/">Hygen</a> to our device globally. For this, we would make use of NPM by running this command in your terminal:</p><pre>$ npm i -g hygen</pre><p>This would install <a href="https://www.hygen.io/">Hygen</a> globally on your device. For non-Javascript developers, there are other ways to install <a href="https://www.hygen.io/">Hygen</a> but we won’t be going through that in this tutorial. Nonetheless, the <a href="https://www.hygen.io/docs/quick-start">Hygen Documentation</a> has a comprehensive tutorial on that. Next, we would proceed into the folder we want to set up for the initialization of Hygen. To initialize Hygen in a project, we would run this command in the root directory:</p><pre>hygen init self</pre><p>This command would automatically generate a _template directory in the root directory of your project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*RHSZ8F5bFlscCC3cFDvy5A.png" /><figcaption>Default structure generated after initializing the project.</figcaption></figure><h3><strong>Generators</strong></h3><p>A generator is used to stop repetitive tasks. A generator is responsible for generating files containing default codes known as templates.</p><p>To create a generator, we would run the command:</p><pre>hygen generator new [GENERATOR_NAME]</pre><p>Preferably or for readability, [GENERATOR_NAME] should be the name of what you are trying to automate. For example, if I want to create a generator to create single components, I would run the command:</p><pre>hygen generator new component</pre><p>This would generate a component directory in the _template folder:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*UbqPDxGycPAi6uqbNiy7_g.png" /><figcaption>The default structure of a generator</figcaption></figure><p>To<strong> invoke a generator</strong>, we run the command:</p><pre>hygen [GENERATOR_NAME] new [FILE_NAME]</pre><p>For example, if we are trying to create a component using the component generator, we would run the command:</p><pre>hygen component new [THE_COMPONENTS_NAME]</pre><p>This would automatically run the component generator with [THE_COMPONENTS_NAME] as the name variable. Which can be accessed in the template using the [name] variable as can be seen in the template section.</p><h3><strong>Interactive Prompts</strong></h3><p>Prompts are used for creating interactive generators like the one below.</p><p>Most times, prompts are used to select or configure what the generator should generate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kpc8s6E9liCyRoKIVVAPYA.png" /><figcaption>An example of a prompt used to select what would be placed in a .vue component</figcaption></figure><p>A prompt can be created by creating a prompt.js file in the generator directory:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*K-zNf2YhMZp8RUUpVVzkpA.png" /><figcaption>A prompt.js file is used to write down the questions to be asked when a generator is invoked</figcaption></figure><p>The prompt.js exports an array as a module. In this array, questions that need to be asked would be placed as objects in the array. examples:</p><pre>const _ = require(&quot;lodash&quot;);</pre><pre>module.exports = [</pre><pre>{</pre><pre>type: &quot;input&quot;,</pre><pre>name: &quot;name&quot;,</pre><pre>message: &quot;Name:&quot;,</pre><pre>validate(value) {</pre><pre>if (!value.length) {</pre><pre>return &quot;Components must have a name.&quot;;</pre><pre>}</pre><pre>const fileName = _.kebabCase(value);</pre><pre>if (fileName.indexOf(&quot;-&quot;) === -1) {</pre><pre>return &quot;Component names should contain at least two words to avoid conflicts with existing and future HTML elements.&quot;;</pre><pre>}</pre><pre>return true;</pre><pre>},</pre><pre>},</pre><pre>{</pre><pre>type: &quot;multiselect&quot;,</pre><pre>name: &quot;blocks&quot;,</pre><pre>message: &quot;Blocks:&quot;,</pre><pre>initial: [&quot;script&quot;, &quot;template&quot;, &quot;style&quot;],</pre><pre>choices: [</pre><pre>{</pre><pre>name: &quot;script&quot;,</pre><pre>message: &quot;&lt;script&gt;&quot;,</pre><pre>},</pre><pre>{</pre><pre>name: &quot;template&quot;,</pre><pre>message: &quot;&lt;template&gt;&quot;,</pre><pre>},</pre><pre>{</pre><pre>name: &quot;style&quot;,</pre><pre>message: &quot;&lt;style&gt;&quot;,</pre><pre>},</pre><pre>],</pre><pre>validate(value) {</pre><pre>if (value.indexOf(&quot;script&quot;) === -1 &amp;&amp; value.indexOf(&quot;template&quot;) === -1) {</pre><pre>return &quot;Components require at least a &lt;script&gt; or &lt;template&gt; tag.&quot;;</pre><pre>}</pre><pre>return true;</pre><pre>},</pre><pre>},</pre><pre>];</pre><p>The above configuration asks for the name of the file and validates it. After which it puts forth a multi-select to select the options you may want in the file to be created. The options being put forth in this example are:</p><pre>[&quot;script&quot;, &quot;template&quot;, &quot;style&quot;]</pre><h3>Templates</h3><p>A Hygen template is a header of a markdown-like <a href="https://www.hygen.io/docs/templates/#all-frontmatter-properties">frontmatter</a> and a body of an EJS templating engine. The template is used to specify the location of the file(using the frontmatter):</p><pre>---</pre><pre>to: &quot;src/components/&lt;%= h.changeCase.pascal(name)  %&gt;.vue&quot;</pre><pre>---</pre><p>and the contents of the file using an EJS templating engine:</p><pre>&lt;%</pre><pre>if (blocks.indexOf(&#39;script&#39;) !== -1) {</pre><pre>%&gt;</pre><pre>&lt;script lang=&quot;ts&quot;&gt;</pre><pre>import { Component, Vue } from &quot;vue-property-decorator&quot;;</pre><pre>@Component({</pre><pre>name: &quot;&lt;%= h.changeCase.pascal(name) %&gt;&quot;,</pre><pre>})</pre><pre>export default class &lt;%= h.changeCase.pascal(name) %&gt; extends Vue {}</pre><pre>&lt;/script&gt;</pre><pre>&lt;%</pre><pre>}</pre><pre>if (blocks.indexOf(&#39;template&#39;) !== -1) {</pre><pre>%&gt;</pre><pre>&lt;template&gt;</pre><pre>&lt;div :class=&quot;$style[&#39;c-&lt;%= h.changeCase.kebab(name).toLowerCase() %&gt;&#39;]&quot;&gt;&lt;/div&gt;</pre><pre>&lt;/template&gt;</pre><pre>&lt;%</pre><pre>}</pre><pre>if (blocks.indexOf(&#39;style&#39;) !== -1) {</pre><pre>%&gt;</pre><pre>&lt;style lang=&quot;scss&quot; module&gt;</pre><pre>.c-&lt;%= h.changeCase.kebab(name).toLowerCase() %&gt;{}</pre><pre>&lt;/style&gt;</pre><pre>&lt;%</pre><pre>}</pre><pre>%&gt;</pre><p>Putting it together:</p><pre>---</pre><pre>to: &quot;src/components/&lt;%= h.changeCase.pascal(name)  %&gt;.vue&quot;</pre><pre>---</pre><pre>&lt;%</pre><pre>if (blocks.indexOf(&#39;script&#39;) !== -1) {</pre><pre>%&gt;</pre><pre>&lt;script lang=&quot;ts&quot;&gt;</pre><pre>import { Component, Vue } from &quot;vue-property-decorator&quot;;</pre><pre>@Component({</pre><pre>name: &quot;&lt;%= h.changeCase.pascal(name) %&gt;&quot;,</pre><pre>})</pre><pre>export default class &lt;%= h.changeCase.pascal(name) %&gt; extends Vue {}</pre><pre>&lt;/script&gt;</pre><pre>&lt;%</pre><pre>}</pre><pre>if (blocks.indexOf(&#39;template&#39;) !== -1) {</pre><pre>%&gt;</pre><pre>&lt;template&gt;</pre><pre>&lt;div :class=&quot;$style[&#39;c-&lt;%= h.changeCase.kebab(name).toLowerCase() %&gt;&#39;]&quot;&gt;&lt;/div&gt;</pre><pre>&lt;/template&gt;</pre><pre>&lt;%</pre><pre>}</pre><pre>if (blocks.indexOf(&#39;style&#39;) !== -1) {</pre><pre>%&gt;</pre><pre>&lt;style lang=&quot;scss&quot; module&gt;<br>@import &quot;@/styles&quot;</pre><pre>.c-&lt;%= h.changeCase.kebab(name).toLowerCase() %&gt;{}</pre><pre>&lt;/style&gt;</pre><pre>&lt;%</pre><pre>}</pre><pre>%&gt;<br></pre><p>This template would suffice for a standard vue-ts file or component.</p><h3>EJS</h3><p>Like I said above, <a href="https://ejs.co/">EJS</a> is what’s used in the template of a generator. It is used for embedding Javascript templates.</p><p>In <a href="https://ejs.co/">EJS</a>, javascript can be written by placing the expression in this format</p><pre>&lt;%= [VARIABLE] %&gt;<br>&lt;% [JAVASCRIPT_EXPRESSION] %&gt;</pre><p>In the template, we are using <a href="https://ejs.co/">EJS</a> to set the name of the file dynamically.</p><pre>---</pre><pre>to: &quot;src/components/&lt;%= h.changeCase.pascal(name)  %&gt;.vue&quot;</pre><pre>---</pre><p>and naming the vue.js class:</p><pre>export default class &lt;%= h.changeCase.pascal(name) %&gt; extends Vue {}</pre><h3>One more thing to note about generators</h3><p>Generators generate any <a href="https://ejs.co/">EJS</a> file found in its root directory, hence if you are like me and would want to write components and unit tests in the same folder, you can do so by Creating a unit.ejs.t file in the component generator. e.g:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*Ez2aHVuZhIanFuliqngo3g.png" /><figcaption>A Unit.ejs.t file was created in the component generator.</figcaption></figure><p>Leaving a unit test empty without a <strong>describe</strong> or <strong>it </strong>testing<strong> </strong>block, throws a linting error which is very disturbing when developing. Hence we would place the default code into the unit test template:</p><pre>---</pre><pre>to: &quot;src/components/&lt;%=  h.changeCase.pascal(name) %&gt;.spec.js&quot;</pre><pre>---</pre><pre>&lt;%</pre><pre>const importName = h.changeCase.pascal(name)</pre><pre>%&gt;</pre><pre>/* eslint-disable no-undef */</pre><pre>import { shallowMount } from &quot;@vue/test-utils&quot;;</pre><pre>import &lt;%= importName %&gt; from &quot;./&lt;%= importName %&gt;.vue&quot;;</pre><pre>describe(&quot;@components/&lt;%= name %&gt;&quot;, () =&gt; {</pre><pre>it(&quot;Write a test here&quot;, () =&gt; {</pre><pre>const { element } = shallowMount(&lt;%= importName %&gt;, {});</pre><pre>// Write tests here</pre><pre>});</pre><pre>});</pre><h3>Testing what has been done</h3><p>To test what we have done, we would invoke the generator by running the command:</p><pre>hygen [GENERATOR_NAME] new [FILE_NAME]</pre><h3>Conclusion</h3><p>The developer experience this has given me and my team in projects has been immense and really helpful, it has helped preserve the standard of the project in the sense that everyone gets to use the default structure accepted by the team, it has also helped in eradicating some human errors caused by carrying out processes numerous times especially when working in a large team. Hence, I would really encourage all teams to make use of this awesome piece of tech.</p><p><a href="https://github.com/god-of-js/vue-ts-enterprise-boilerplate.git">GIT REPO</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65abc40e7af5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/generating-files-in-a-vue-application-using-hygen-65abc40e7af5">Generating files in a Vue application using Hygen</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to vuex(part 2)]]></title>
            <link>https://medium.com/swlh/introduction-to-vuex-part-2-384f85a2a9db?source=rss-9ec1be7e3038------2</link>
            <guid isPermaLink="false">https://medium.com/p/384f85a2a9db</guid>
            <dc:creator><![CDATA[Eze Henry]]></dc:creator>
            <pubDate>Wed, 24 Jun 2020 17:45:36 GMT</pubDate>
            <atom:updated>2020-06-24T19:26:27.589Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*L8UzQM6qGwBJiWUn.png" /></figure><p>In<a href="https://medium.com/@Godofjs/introduction-to-vuex-part-one-f0b6153a90d9?source=friends_link&amp;sk=902a8074ed36d35223a049e645da89a6"> part 1</a> of our tutorial, we were able to:</p><ol><li>set up our project</li><li>Set up firebase</li><li>Create our views(pages)</li><li>Set up our routes</li></ol><p>With that done, We would be working on our components and vuex in this part of the tutorial</p><h3>Setting up vuex</h3><p>By default, vuex has been set up by the vue CLI. You can find everything in a folder named store in the src folder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/161/1*UgeWnHWuiaropi8TsVNxHg.png" /><figcaption>Vuex regular structure.</figcaption></figure><p>However, this folder structure might become difficult to handle when writing larger applications, But I won&#39;t be talking on the recommended structure in this tutorial, However, I have written on it previously so you can know more about it <a href="https://medium.com/swlh/building-large-scale-applications-with-vuex-6d7e8ce0dfef?source=friends_link&amp;sk=cd343c3d40274e766c872839a7854050">here</a>. Moving on….</p><p>The index.js file of the store folder would initially look like this</p><pre><em>import</em> Vue <em>from</em> &quot;vue&quot;;</pre><pre><em>import</em> Vuex <em>from</em> &quot;vuex&quot;;</pre><pre>Vue.use(Vuex);</pre><pre><em>export</em> <em>default</em> <em>new</em> Vuex.Store({</pre><pre>state: {},</pre><pre>getters: {},</pre><pre>mutations: {},</pre><pre>actions: {},</pre><pre>modules: {}</pre><pre>});</pre><p>If you noticed, there are 5 objects in the store,</p><ol><li>State: The state is where all data is stored, also known as “the single source of truth”. In this application, the state would be used to store data e.g user details, books, e.t.c.</li><li>Getters: Getters are like the computed property of a vue.js component, it is used for filtering or sorting data. e.g to get all active users</li><li>Actions: Actions are used for asynchronous operations, basically actions are functions where you can fetch from an API, post to an API, perform complex logical operations e.t.c. Actions can be accessed by dispatching or mapping them. e.g</li></ol><pre>this.$store.dispatch(&#39;action&#39;,param)</pre><p>4. Mutations: Mutations are used for synchronous operations and is mostly used to mutate state, It has many similarities with the actions the only difference is that actions are asynchronous while mutations are not. Mutations can be accessed by committing or mapping them. e.g</p><pre>this.$store.commit(&quot;mutation&quot;, param)</pre><ol><li>Modules: Modules are used for breaking the store into modules or compartments. I wouldn&#39;t be talking on this today, but I have written on this previously <a href="https://medium.com/swlh/building-large-scale-applications-with-vuex-6d7e8ce0dfef?source=friends_link&amp;sk=cd343c3d40274e766c872839a7854050">here</a></li></ol><p>Now moving on to development, we would be writing code from here on. First, we would create our registration component’s template:</p><pre>&lt;template&gt;</pre><pre>&lt;div&gt;</pre><pre>&lt;form <em>@</em>submit.prevent=&quot;submitForm&quot;&gt; // .prevent is an event modifier <br>//it performs the same thing as .preventDefault() which stops a page from loading when submitting a form.</pre><pre>&lt;input type=&quot;email&quot; <em>v-model</em>=&quot;email&quot; placeholder=&quot;email&quot;&gt;</pre><pre>&lt;input type=&quot;text&quot; <em>v-model</em>=&quot;name&quot;  placeholder=&quot;name&quot;&gt;</pre><pre>&lt;input type=&quot;password&quot; <em>v-model</em>=&quot;password&quot;  placeholder=&quot;password&quot;&gt;</pre><pre>&lt;button&gt;Register &lt;/button&gt;</pre><pre>&lt;/form&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/template&gt;</pre><p>Now to the script part of our registration component</p><pre>&lt;script&gt;</pre><pre><em>import</em> {mapMutations} <em>from</em> &#39;vuex&#39;</pre><pre><em>export</em> <em>default</em> {</pre><pre>data: () <em>=&gt;</em> {</pre><pre><em>return</em> {</pre><pre>email: null,</pre><pre>name: null,</pre><pre>password: null</pre><pre>}</pre><pre>},</pre><pre>methods: {</pre><pre><em>...</em>mapMutations([&#39;setUserInfo&#39;]), <em>//mapping mutations to be able to //access it</em></pre><pre>submitForm() {</pre><pre><em>this</em>.$firebase.auth</pre><pre>.createUserWithEmailAndPassword(<em>this</em>.email, <em>this</em>.password)</pre><pre>.then(result <em>=&gt;</em> {</pre><pre><em>let</em> data <em>=</em> {</pre><pre>name: <em>this</em>.name,</pre><pre>email: <em>this</em>.email,</pre><pre>id: result.user.uid,</pre><pre>createdAt: Date.now()</pre><pre>};</pre><pre><em>this</em>.$firebase.db</pre><pre>.ref(&quot;users&quot;)</pre><pre>.child(result.user.uid)</pre><pre>.set(data)</pre><pre>.then(() <em>=&gt;</em> {</pre><pre><em>this</em>.setUserInfo(data); // accessing the mutation<br>//this is one way to access the mutation by mapping it. another way //is - this.$store.commit(&#39;setUserInfo&#39;, data)</pre><pre><em>this</em>.$router.push(&quot;/borrowbooks&quot;);</pre><pre>});</pre><pre>})</pre><pre>.catch(err <em>=&gt;</em> {<br><em>let</em> message <em>=</em> Object.values(err)[0];</pre><pre>alert(message);</pre><pre>});</pre><pre>}</pre><pre>}</pre><pre>}</pre><pre>&lt;/script&gt;</pre><p>We are able to access the firebase class in various components because we made it accessible in the entry point of our application in<a href="https://medium.com/@Godofjs/introduction-to-vuex-part-one-f0b6153a90d9?source=friends_link&amp;sk=902a8074ed36d35223a049e645da89a6\"> part 1</a>. Now let&#39;s look at our setUserInfo mutation:</p><pre><em>import</em> Vue <em>from</em> &quot;vue&quot;;</pre><pre><em>import</em> Vuex <em>from</em> &quot;vuex&quot;;</pre><pre>Vue.use(Vuex);</pre><pre><em>export</em> <em>default</em> <em>new</em> Vuex.Store({</pre><pre>state: {</pre><pre>user: null</pre><pre>},</pre><pre>mutations: {</pre><pre>setUserInfo(state, userInfo) {</pre><pre>state.user <em>=</em> userInfo; // a mutation is used to mutate state</pre><pre>}</pre><pre>},</pre><pre>actions: {},</pre><pre>modules: {}</pre><pre>});</pre><p>Now moving on to the add books component:</p><pre>&lt;template&gt;</pre><pre>&lt;div&gt;</pre><pre>&lt;input type=&quot;file&quot; <em>@</em>change=&quot;uploadFile&quot; class=&quot;file&quot;&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/template&gt;</pre><pre>&lt;script&gt;</pre><pre><em>import</em> {mapActions} <em>from</em> &#39;vuex&#39;</pre><pre><em>export</em> <em>default</em> {</pre><pre>methods: {</pre><pre><em>...</em>mapActions([&#39;getFile&#39;]), <em>// a mapped action</em></pre><pre>uploadFile() {</pre><pre><em>const</em> fileInput <em>=</em> document.querySelector(&quot;.file&quot;);</pre><pre><em>const</em> file <em>=</em> fileInput.files[0];</pre><pre><em>this</em>.$firebase.storage</pre><pre>.child(&#39;library book&#39;)</pre><pre>.put(file)</pre><pre>.then(() <em>=&gt;</em> {<br><em>this</em>.getFile(<em>this</em>); <em>//how to access an action</em></pre><pre>}).catch(err <em>=&gt;</em> {console.log(err)})</pre><pre>}</pre><pre>}</pre><pre>}</pre><pre>&lt;/script&gt;</pre><p>In the template, we added input to take the file from a directory, then in the script we imported mapActions.</p><p>Note: mapActions and mapMutations are destructured in the methods property while mapState and mapGetters are destructured in the computed property.</p><p>With the code above we could upload a file to the firebase storage bucket. Now let&#39;s look at the action we mapped</p><pre><em>import</em> Vue <em>from</em> &quot;vue&quot;;</pre><pre><em>import</em> Vuex <em>from</em> &quot;vuex&quot;;</pre><pre>Vue.use(Vuex);</pre><pre><em>export</em> <em>default</em> <em>new</em> Vuex.Store({</pre><pre>state: {</pre><pre>user: null,<br>doc: []</pre><pre>},</pre><pre>mutations: {</pre><pre>setUserInfo(state, userInfo) {</pre><pre>state.user <em>=</em> userInfo;</pre><pre>},<br>setDoc(state, doc) {<br>state.docs.push(doc)</pre><pre>},</pre><pre>actions: {</pre><pre>getFile({commit}, vueApp) {</pre><pre>vueApp.$firebase.storage<br>.child(&#39;library book&#39;)<br>.getDownloadURL()</pre><pre>.then(link <em>=&gt;</em> {<br>commit(&#39;setDoc&#39;, link)</pre><pre>})</pre><pre>.catch(err <em>=&gt;</em> console.log(err));</pre><pre>}</pre><pre>},</pre><pre>modules: {}</pre><pre>});</pre><p>The aim of the action we mapped was to get the URL of the document we uploaded. If you noticed we committed instead of assigning to state, It is possible to do that but it is recommended that only mutations should be able to mutate the state. With this done, let&#39;s move to the borrowing component</p><pre>&lt;template&gt;</pre><pre>&lt;div&gt;</pre><pre>&lt;button <em>v-for</em>=&quot;(path, index) <em>in</em> doc&quot; <em>:</em>key=&quot;index&quot; <em>@</em>click=&quot;borrowDoc(path.link)&quot;&gt;Borrow Document&lt;/button&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/template&gt;</pre><pre>&lt;script&gt;</pre><pre><em>import</em> {mapState} <em>from</em> &#39;vuex&#39;</pre><pre><em>export</em> <em>default</em> {</pre><pre>computed: {</pre><pre><em>...</em>mapState([&#39;doc&#39;, &#39;user&#39;]) <em>//mapped user and doc so it could me //accessible in this component</em></pre><pre>},</pre><pre>methods: {</pre><pre>borrowDoc(link) {</pre><pre><em>let</em> data <em>=</em> {</pre><pre>name: this.user.name, <em>// mapping state makes this accessible</em></pre><pre>doc: link</pre><pre>}</pre><pre><em>this</em>.$firebase.db</pre><pre>.ref(&quot;borrowers&quot;)</pre><pre>.set(data)</pre><pre>}</pre><pre>}</pre><pre>}</pre><pre>&lt;/script&gt;</pre><p>In this component you would see that we mapped doc and user which are objects in the state, mapping makes it accessible in the component.</p><p>Now let’s move to the part where we can see people who borrowed books</p><pre>&lt;template&gt;</pre><pre>&lt;div&gt;</pre><pre>&lt;div <em>v-for</em>=&#39;(person, index) <em>in</em> fetchBorrowers&#39; <em>:</em>key=&quot;index&quot;&gt;{{person.name}}&lt;/div&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/template&gt;</pre><pre>&lt;script&gt;</pre><pre><em>import</em> {mapGetters} <em>from</em> &#39;vuex&#39;</pre><pre><em>export</em> <em>default</em> {</pre><pre>computed: {</pre><pre><em>...</em>mapGetters([&#39;fetchBorrowers&#39;]) //a mapped getter</pre><pre>},</pre><pre>mounted() {</pre><pre><em>this</em>.$store.dispatch(&#39;getBorrowers&#39;, <em>this</em>) //another way to access an action</pre><pre>}</pre><pre>}</pre><pre>&lt;/script&gt;</pre><p>Now let&#39;s move to the store to see the getter and the action we declared</p><pre><em>import</em> Vue <em>from</em> &quot;vue&quot;;</pre><pre><em>import</em> Vuex <em>from</em> &quot;vuex&quot;;</pre><pre>Vue.use(Vuex);</pre><pre><em>export</em> <em>default</em> <em>new</em> Vuex.Store({</pre><pre>state: {</pre><pre>user: null,</pre><pre>doc: [],</pre><pre>borrowers: []</pre><pre>},</pre><pre>getters: {</pre><pre>fetchBorrowers: state <em>=&gt;</em> {</pre><pre><em>return</em> state.borrowers.filter(x <em>=&gt;</em> x.name <em>!==</em> null)</pre><pre>}</pre><pre>},</pre><pre>mutations: {</pre><pre>setUserInfo(state, userInfo) {</pre><pre>state.user <em>=</em> userInfo;</pre><pre>},</pre><pre>setDoc(state, doc) {</pre><pre>state.docs.push(doc)</pre><pre>},</pre><pre>setBorrowers(state, people) {</pre><pre>state.borrowers.push(people)</pre><pre>}</pre><pre>},</pre><pre>actions: {</pre><pre>getFile({commit}, vueApp) {</pre><pre>vueApp.$firebase.storage</pre><pre>.child(&#39;library book&#39;)</pre><pre>.getDownloadURL()</pre><pre>.then(link <em>=&gt;</em> {</pre><pre>commit(&#39;setDoc&#39;, link)</pre><pre>})</pre><pre>.catch(err <em>=&gt;</em> console.log(err));</pre><pre>},</pre><pre>getBorrowers({commit}, vueApp) {</pre><pre>vueApp.$firebase.db</pre><pre>.ref(&quot;borrowers&quot;)</pre><pre>.once(&quot;value&quot;)</pre><pre>.then(result <em>=&gt;</em> {</pre><pre>commit(&quot;setBorrowers&quot;, { <em>...</em>result.val(), id: result.key });</pre><pre>}).catch(err <em>=&gt;</em> console.log(err))</pre><pre>}</pre><pre>},</pre><pre>modules: {}</pre><pre>});</pre><p>Like I defined getters previously they are used for filtering, so in this case, we are filtering borrowers who do not have their name set to null.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*g1wh5ibJzYX-XnkN.jpg" /><figcaption>Well don&#39;t mind the stern face 😅.. Send me a note for clarifications.</figcaption></figure><p>Thank you for your time 😉.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=384f85a2a9db" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/introduction-to-vuex-part-2-384f85a2a9db">Introduction to vuex(part 2)</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to vuex (part one)]]></title>
            <link>https://medium.com/swlh/introduction-to-vuex-part-one-f0b6153a90d9?source=rss-9ec1be7e3038------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0b6153a90d9</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[vue-router]]></category>
            <category><![CDATA[vuex]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[firebase]]></category>
            <dc:creator><![CDATA[Eze Henry]]></dc:creator>
            <pubDate>Wed, 24 Jun 2020 17:45:10 GMT</pubDate>
            <atom:updated>2020-06-25T17:37:50.244Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9im9rl-23fmRHWGu.png" /></figure><p>Vuex is the official state management library of vuex, It is used for state management as the description implies. It serves as a centralized store for the components in an application, with rules ensuring that the state can only be mutated predictably.</p><p>Starting up as a vuejs developer, vuex gave me a tough time, was confusing, and took sometime before I could master it.</p><p>In the course of this tutorial, We would be building a book library using vue and firebase. So brace yourself</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/0*9Z9OlePM5htHUVr1.gif" /></figure><h3>App Overview</h3><p>The aim of this application is for registered users to borrow books and for the bookkeeper to keep track of the books that were borrowed. The major features we would be implementing would be:</p><ol><li>Authentication</li><li>Real-time database</li></ol><p>From a technical point of vue…(wordplay 😆)</p><ol><li><a href="https://vuejs.org/v2/guide/installation.html">Vue</a> — a modern javascript framework</li><li><a href="https://firebase.google.com/">Firebase</a> — Authentication and real-time database</li><li><a href="https://vuex.vuejs.org/">Vuex</a>- For state management</li><li><a href="https://router.vuejs.org/">Vue-Router</a> — For routing</li></ol><p>Note: This tutorial covers the full set up for this project. If you want to go straight into vuex and the core functionality implementation, visit <a href="https://medium.com/@Godofjs/introduction-to-vuex-part-2-384f85a2a9db?source=friends_link&amp;sk=78304dd1d013718aecdba96fee8a197e">part 2</a> of this tutorial</p><h3>Setting up the project</h3><p>First, we would be installing the official vue CLI as follows:</p><pre>npm install --global vue-cli</pre><p>After which we would create our application as follows:</p><pre>vue create vuex-library</pre><p>After which you would be prompted to select a preset. As you can see I have some saved presets already but I would be selecting “manually select features”. You can select it by going down to it and tapping Enter on your keyboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*Puy95jJbcCvNtccne8Ma_g.png" /><figcaption>Options of presets to pick from</figcaption></figure><p>After selecting ‘manually select features ’, You would get another prompt with options of features to pick from. The options to be used for this tutorial has been manually selected already in the picture below. You can select a feature by tapping space bar then finish selection by tapping enter on your keyboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/1*ZhjzDf52QMP3E_pfp7OGvQ.png" /><figcaption>These are our chosen features</figcaption></figure><p>After which we would need to select the mode of vue-router to use. You can select it by typing ‘y’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*ET1yr0qJHTlqFW5l9GM_8A.png" /></figure><p>For this tutorial, we would be using the <a href="https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations">vue router’s history mode</a>. Vue router’s default mode is the hash mode. The hash mode doesn’t reload when the URL changes also the vue router’s history mode utilizes history.push to achieve navigations.</p><p>For the remaining feature selection, they are based on preference and are of no consequence to this tutorial, So I would be skipping them. So now you can proceed into the vuex-library directory we generated now.</p><h3>Starting the development server</h3><p>You can start the vue.js development server by running the command:</p><pre>npm run serve</pre><h3>Firebase Setup</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O9BgUp9OIp061AAB76rjpQ.png" /></figure><p>Let’s start by creating a Firebase account <a href="https://firebase.google.com/">here</a>. Go to Console and click “Add project”. Give it any name you like and choose your country (the country doesn’t affect the project). After that, you will be redirected to the home page of a newly created project. From this console, you can configure your Firebase app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_-qz3dLX9Gpx85QzL_R3oQ.png" /></figure><p>In order to use Firebase in our app, we need to set up the Firebase SDK first. To do that just run following (don’t forget to stop dev server if it’s up):</p><pre>npm install --save firebase</pre><p>In the src folder, we would be creating a firebase folder where we would store firebase credentials:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/174/1*-026_g_TTmtUT3ZAnoEVnw.png" /><figcaption>Create a firebase folder</figcaption></figure><p>In the firebase folder, we would create an index.js folder where we would place our firebase credentials:</p><pre><em>import</em> &quot;firebase&quot;;</pre><pre><em>import</em> firebase <em>from</em> &quot;firebase/app&quot;;</pre><pre><em>import</em> &quot;firebase/auth&quot;;</pre><pre><em>import</em> &quot;firebase/database&quot;;</pre><pre><em>import</em> &quot;firebase/storage&quot;;</pre><pre><em>var</em> firebaseConfig <em>=</em> {</pre><pre>apiKey: &#39;YOUR_API_KEY&#39;,<br>  authDomain: &#39;YOUR_AUTH_DOMAIN&#39;,<br>  databaseURL: &#39;YOUR_DATABASE_URL&#39;,<br>  projectId: &#39;YOUR_PROJECT_ID&#39;</pre><pre>};</pre><pre><em>class</em> Firebase {</pre><pre><em>constructor</em>() {</pre><pre>firebase.initializeApp(firebaseConfig);</pre><pre>firebase.analytics();</pre><pre><em>this</em>.auth <em>=</em> firebase.auth();</pre><pre><em>this</em>.db <em>=</em> firebase.database();</pre><pre><em>this</em>.storage <em>=</em> firebase.storage().ref();</pre><pre>}</pre><pre>}</pre><pre><em>export</em> <em>default</em> Firebase;</pre><p>If you noticed, we are making use of Javascript classes, This is because we are trying to prevent memory leaks by using one firebase instance throughout the application as opposed to importing it everywhere it is needed.</p><p>After this, we would import firebase into our application’s entry point and make it accessible throughout the application.</p><pre><em>import</em> Vue <em>from</em> &quot;vue&quot;;</pre><pre><em>import</em> App <em>from</em> &quot;./App.vue&quot;;</pre><pre><em>import</em> router <em>from</em> &quot;./router&quot;;</pre><pre><em>import</em> store <em>from</em> &quot;./store&quot;;</pre><pre><em>import</em> firebase <em>from</em> &#39;./firebase&#39; <em>//imported firebase into main.js</em></pre><pre>Vue.config.productionTip <em>=</em> false;</pre><pre>Vue.prototype.$firebase <em>=</em> <em>new</em> firebase(); <em>//made it accessible</em></pre><pre><em>new</em> Vue({</pre><pre>router,</pre><pre>store,</pre><pre>render: h <em>=&gt;</em> h(App)</pre><pre>}).$mount(&quot;#app&quot;);</pre><p>Now moving on……</p><h3>Setting up our pages</h3><p>First, we would start by creating our views. Here I created two extra views excluding the Home and about views generated by the vue CLI. The location of the views are in the views folder which is located in the src folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/191/1*rZOuo4LsQS6Puad57qBmJQ.png" /></figure><p>Now for these views to be connected to our application we would have to import them into our router and set their routes. e.g:</p><pre><em>import</em> Vue <em>from</em> &quot;vue&quot;;</pre><pre><em>import</em> VueRouter <em>from</em> &quot;vue-router&quot;;</pre><pre><em>import</em> Home <em>from</em> &quot;../views/Home.vue&quot;;</pre><pre><em>import</em> register <em>from</em> &#39;../views/registration.vue&#39;</pre><pre><em>import</em> borrowbooks <em>from</em> &#39;../views/borrowbooks.vue&#39;</pre><pre><em>import</em> viewborrowers <em>from</em> &#39;../views/viewborrowers.vue&#39;</pre><pre>Vue.use(VueRouter);</pre><pre><em>const</em> routes <em>=</em> [</pre><pre>{</pre><pre>path: &quot;/home&quot;,</pre><pre>name: &quot;Home&quot;,</pre><pre>component: Home</pre><pre>},</pre><pre>{</pre><pre>path: &quot;/&quot;, // making it the default route or landing page of the //application</pre><pre>name: &quot;register&quot;,</pre><pre>component: register</pre><pre>},</pre><pre>{</pre><pre>path: &quot;/borrowbooks&quot;,</pre><pre>name: &quot;borrowbooks&quot;,</pre><pre>component: borrowbooks</pre><pre>},</pre><pre>{</pre><pre>path: &quot;/viewborrowers&quot;,</pre><pre>name: &quot;viewborrowers&quot;,</pre><pre>component: viewborrowers</pre><pre>},</pre><pre>{</pre><pre>path: &quot;/about&quot;,</pre><pre>name: &quot;About&quot;,</pre><pre><em>// route level code-splitting</em></pre><pre><em>// this generates a separate chunk (about.[hash].js) for this route</em></pre><pre><em>// which is lazy-loaded when the route is visited.</em></pre><pre>component: () <em>=&gt;</em></pre><pre>import(<em>/* webpackChunkName: &quot;about&quot; */</em> &quot;../views/About.vue&quot;)</pre><pre>}</pre><pre>];</pre><pre><em>const</em> router <em>=</em> <em>new</em> VueRouter({</pre><pre>mode: &quot;history&quot;,</pre><pre>base: process.env.BASE_URL,</pre><pre>routes</pre><pre>});</pre><pre><em>export</em> <em>default</em> router;</pre><p>With that done, our routes are now accessible.</p><h3>Summary</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*CYtgyxTydZhQJw7B.gif" /><figcaption>Wow, you’re still here? Perfect!!!</figcaption></figure><p>In this tutorial, we were able to completely</p><ol><li>set up our project</li><li>Set up firebase</li><li>Create our views</li><li>Set up our routes</li></ol><p>Now moving on to <a href="https://medium.com/@Godofjs/introduction-to-vuex-part-2-384f85a2a9db?source=friends_link&amp;sk=78304dd1d013718aecdba96fee8a197e">part 2</a> of this tutorial, which would cover:</p><ol><li>State management</li><li>Implementation of the core functionalities of this application.</li></ol><p>In case you feel the need to go through the git repository, I provided the link to the repository <a href="https://github.com/god-of-js/library">right here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*u0wwoqDz1p4oVb6v" /><figcaption>See you soon</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0b6153a90d9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/introduction-to-vuex-part-one-f0b6153a90d9">Introduction to vuex (part one)</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building large-scale applications with vuex]]></title>
            <link>https://medium.com/swlh/building-large-scale-applications-with-vuex-6d7e8ce0dfef?source=rss-9ec1be7e3038------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d7e8ce0dfef</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[vue-router]]></category>
            <category><![CDATA[vuex]]></category>
            <dc:creator><![CDATA[Eze Henry]]></dc:creator>
            <pubDate>Fri, 12 Jun 2020 18:44:30 GMT</pubDate>
            <atom:updated>2020-06-27T09:18:31.145Z</atom:updated>
            <content:encoded><![CDATA[<h3>Modularization in Vuejs and Vuex</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m6PGLUA_ZySmwKYcOsPvog.png" /></figure><p>When writing large front end applications, state management can be quite a difficult and tiring task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*TA6gFjp7zfEYiJvfc4wBDQ.gif" /></figure><p>For vue.js, a plugin named vuex was created for the purpose of state management. By default it comes with the folder structure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/162/1*yjbewgYe4bhjrRERrgJtcg.png" /><figcaption>the default folder structure of a vuex store</figcaption></figure><p>This folder structure could be used in small applications but if used in large applications the codebase would most likely look unreadable, dirty, and over time become difficult to handle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*yr1Q7fjXoG9zgnpAyeIMaQ.gif" /><figcaption>Yeah I learned this the hard way</figcaption></figure><p>The recommended folder structure would be to break your store into various modules. Example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/159/1*H9Bt6vyBzLDLj_2FFyNDKA.png" /><figcaption>The recommended vuex structure</figcaption></figure><p>This folder structure breaks down the store into modules with each of the modules having its own separate folder. The modules folder is positioned in the same folder as the index.js generated by vuex . As expected the content of the index.js file has to change too. e.g:</p><pre><em>import</em> Vue <em>from</em> &quot;vue&quot;;</pre><pre><em>import</em> Vuex <em>from</em> &quot;vuex&quot;;</pre><pre><em>import</em> state <em>from</em> &#39;./state.js&#39;</pre><pre><em>import</em> actions <em>from</em> &#39;./actions.js&#39;</pre><pre><em>import</em> mutations <em>from</em> &#39;./mutations.js&#39;</pre><pre><em>import</em> getters <em>from</em> &#39;./getters.js&#39;</pre><pre><em>import</em> user <em>from</em> &#39;./modules/user/index.js&#39;</pre><pre>Vue.use(Vuex);</pre><pre><em>export</em> <em>default</em> <em>new</em> Vuex.Store({</pre><pre>state,</pre><pre>mutations,</pre><pre>actions,</pre><pre>getters,</pre><pre>modules: {</pre><pre>user</pre><pre>}</pre><pre>});</pre><p>In this example I created a module named “user”, I imported it into the index.js file provided by vuex. This way the user module has been connected to the store and can now be accessed.</p><p>Moving on to the “user” module we would be importing state, actions, getters, and mutations into the index.js file in this manner:</p><pre><em>import</em> state <em>from</em> &#39;./state.js&#39;</pre><pre><em>import</em> mutations <em>from</em> &#39;./mutations.js&#39;</pre><pre><em>import</em> actions <em>from</em> &#39;./actions.js&#39;</pre><pre><em>import</em> getters <em>from</em> &#39;./getters.js&#39;</pre><pre><em>export</em> <em>default</em> {</pre><pre>namespaced: true,</pre><pre>state,</pre><pre>mutations,</pre><pre>getters,</pre><pre>actions,</pre><pre>}</pre><p>If you notice, the namespaced field was set to true, this is because we want to be able to specify the particular module to check for a particular action, state or getter as the case may be. Moving on….</p><h3>State:</h3><p>Due to the change from the default vuex structure to the vuex modular structure, the methods by which we access our vuex state has to change. e.g we won’t be able to access a userAvatar field from the user module’s state by just mapping userAvatar. So we would mapState in this manner in the component’s script:</p><pre>&lt;script&gt;</pre><pre><em>import</em> {mapState} <em>from</em> &#39;vuex&#39;</pre><pre><em>export</em> <em>default</em> {</pre><pre>computed: {</pre><pre><em>...</em>mapState({</pre><pre>userAvatar: state <em>=&gt;</em> state.user.userAvatar</pre><pre>})</pre><pre>},</pre><pre>}<br>&lt;/script&gt;</pre><p>Above is the recommended method for accessing the state of a module, while the state of the module would look like this.</p><pre><em>export</em> <em>default</em> {</pre><pre>userAvatar: &quot;img-location&quot;</pre><pre>};</pre><h3>Actions:</h3><p>We also can’t expect an action in the user module to be accessible by just mapping actions. We would have to specify the particular module we are trying to access. e.g</p><pre>&lt;script&gt;</pre><pre><em>import</em> {mapActions} <em>from</em> &#39;vuex&#39;</pre><pre><em>export</em> <em>default</em> {</pre><pre>methods: {</pre><pre><em>...</em>mapActions(&quot;user&quot;, [&quot;getUserInfo&quot;]),</pre><pre>userInfo() {<br><em>this</em>.getUserInfo()</pre><pre><em>// you could either map it like we did above or call it the same way <br>// it was called below</em></pre><pre><em>this</em>.$store.dispatch(&#39;user/getUserInfo&#39;)</pre><pre><em>// this two methods execute the same task which is calling the //getUserInfo action</em></pre><pre>}</pre><pre>},</pre><pre>}</pre><pre>&lt;/script&gt;</pre><p>Above is the preferred method to access an action from a modular vuex while the actions file would look like this</p><pre><em>export</em> <em>default</em> {</pre><pre>getUserInfo() {</pre><pre>alert(&#39;Successful&#39;)</pre><pre>}</pre><pre>}</pre><h3>Mutations:</h3><p>Mutations are used for non-asynchronous functions and most times used to mutate state. The method by which we access the mutation also has to change.</p><pre>&lt;script&gt;</pre><pre><em>export</em> <em>default</em> {</pre><pre>methods: {</pre><pre>setuserInfo() {</pre><pre><em>let</em> data <em>=</em> {</pre><pre>name: &#39;Henry&#39;</pre><pre>}</pre><pre><em>this</em>.$store.commit(&#39;user/setUserInfo&#39;, data)</pre><pre>}</pre><pre>},</pre><pre>}</pre><p>Above is the recommended method for accessing a mutation from a modular vuex while the mutation file would look like this</p><pre><em>export</em> <em>default</em> {</pre><pre>setUserInfo: (state, data) <em>=&gt;</em> {<br>state.user = data</pre><pre>}</pre><pre>}</pre><h3>Getters:</h3><p>Getters are like the computed property of a component. They are used for calculations or filtering. A common use of getters is sorting out by the difference in fields or availability of fields. e.g:</p><pre>export default {<br>getActiveUsers: state =&gt; {<br>return state.users.filter(x =&gt; x.active === true)<br>}</pre><pre>}</pre><p>Above is the recommended method of declaring or writing a getter while it can be accessed by mapping getters in the computed property. e.g:</p><pre>&lt;script&gt;</pre><pre><em>import</em> {mapState} <em>from</em> &#39;vuex&#39;</pre><pre><em>export</em> <em>default</em> {</pre><pre>computed: {</pre><pre><em>...</em>mapGetters(&#39;user&#39;, [&#39;getActiveUsers&#39;])</pre><pre>},</pre><pre>}<br>&lt;/script&gt;</pre><p>This was a long ride, hopefully, you were able to use the vuex modular store and write cleaner code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d7e8ce0dfef" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/building-large-scale-applications-with-vuex-6d7e8ce0dfef">Building large-scale applications with vuex</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a static website using Vuepress]]></title>
            <link>https://medium.com/@Godofjs/building-a-static-website-using-vuepress-b6cc34f70f70?source=rss-9ec1be7e3038------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6cc34f70f70</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[vuepress]]></category>
            <category><![CDATA[markdown]]></category>
            <category><![CDATA[webpack]]></category>
            <dc:creator><![CDATA[Eze Henry]]></dc:creator>
            <pubDate>Sun, 08 Sep 2019 20:15:45 GMT</pubDate>
            <atom:updated>2019-09-10T06:31:57.610Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*00It4P85mTQBnmIh.png" /></figure><h3>In this tutorial we would be learning how to build static websites and documentation using vuepress</h3><p>Vuepress is a minimalistic Vue-powered static site generator by Evan you used for generation of static sites and documentations. A static web page is a web page that is delivered to the user’s web browser exactly as stored, in contrast to dynamic web pages which are generated by a web application( A site meant solely for Visual purposes and passing of information or A site with little to no JavaScript).</p><p>VuePress is composed of two parts: a minimalist static site generator with a Vue-powered theming system and a default theme optimized for writing technical documentation.</p><p>Vuepress was built to document the need’s of Vue’s sub projects . Each page generated by vuepress has its own pre-rendered HTML and is also Search Engine Optimization friendly(SEO-friendly) also vuepress generates Single Page Apps powered by <a href="https://vuejs.org/">vue</a>, <a href="https://github.com/vuejs/vue-router">vue-router</a> and <a href="https://webpack.js.org/">webpack</a>. Vuepress is written with markdown which is compiled to HTML using <a href="https://github.com/markdown-it/markdown-it">markdown-it</a>.</p><p>As a developer clear and trustworthy documentation is a must. Reason being it helps consumers of your project have a better understanding and experience on how to use your product ,It also helps remind you of the uses and applications of your project .</p><p>First let’s look at examples of Vuepress sites online today :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*U5HZlJnDcGOh7iI5.png" /><figcaption><a href="https://vuepress-portfolio.netlify.com/">https://vuepress-portfolio.netlify.com/</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uZbxqxfktyuMRI7r.png" /><figcaption><a href="https://www.amie-chen.com/">https://www.amie-chen.com/</a></figcaption></figure><p>Even the <a href="https://vuepress.vuejs.org/">Vuepress</a> and <a href="https://vuejs.org/">Vue</a> official documentation sites were built using vuepress.</p><p>In this post we would talk on creating static websites and documentations for your products.</p><p>We would be starting from installation for this reason you should have <a href="https://nodejs.org/en/download/">node</a> installed or head on to <a href="https://nodejs.org/en/download/">nodejs.org</a> to download .To check if node is installed run the below command in your terminal</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*WOoOu7V66xa6dw_JA9uljg.png" /><figcaption>To check for the version of node installed</figcaption></figure><h3>Installation of vuepress</h3><p>There are two ways to install vuepress .The first is globally and the second is locally.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*ZgCLxKdFrdPpMLht_WtBwQ.png" /><figcaption>The installation can be done using either node package manager(npm) or yarn. Inside an existing project it is best to use yarn instead of npm because npm fails to generate the required dependency tree in this case .</figcaption></figure><h3>Configuration and arrangement of files</h3><p>Vuepress has a specific configuration for the arrangement of the folder and files.It is advisable to use the below format</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*b8qQibChnLbyyvVEeb-wdw.png" /><figcaption>Arrangement of the files and folders in your vuepress folder</figcaption></figure><h3>Creation of files through terminal</h3><p>I would be creating the files and folders from a windows terminal. Here I am trying to create the root folder in which our project would lie.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*OMvpOMwgsQ9glpGBLA-9jg.png" /><figcaption>this command is used to create the folder and go into the folder</figcaption></figure><p>After creating the root folder the next step is creating the docs folder , the docs folder should be directly placed in the root folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*mwszFXrUUxSuFu6PPIQzOw.png" /><figcaption>Now the folder has been created</figcaption></figure><p>the next step is to create a .vuepress folder where the config.js file would be placed. This folder would be would be directly placed in the docs folder together with the pages or routes of your website and your README.md which would be the landing page of your project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*KtLWyhf4_2BmaHu3t7Vj6g.png" /><figcaption>The touch word is used to create a file as mkdir is to create a folder</figcaption></figure><p>The config.js file is where all the configurations of your site would be placed. e.g the title of your site , the description of the site , the navbar of the site, the sidebar of the site e.t.c. Every configuration is placed inside the module.exports object. Also the theme configurations like navbar and sidebar are placed within the themeConfig object just as shown below. Also the navbar and sidebar are arrays containing objects which are the link display text and the router link.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*pk2gyK-86HaQMDosB9nb7w.png" /><figcaption>The title gives the title of the page as well as the description also the navbar and sidebar must be in the themeConfig object in the navbar and sidebar we provide the text and links as objects as seen above.</figcaption></figure><h3>Creating the index page</h3><p>The index page is the landing page which is the first page that appears on the site. The README.md file directly in the docs folder is what vuepress takes as the landing page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*s6pjLHqw2pHZwaG4wCrGJQ.png" /></figure><h3>Starting the development server</h3><p>We start the development server by running the command below in our terminal. Most times it comes out with the url <a href="http://localhost:8080/">http://localhost:8080/</a> to see the result of what you have done ctrl + click</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*rZ3nqf2VnJKvdS40bb9oGg.png" /><figcaption>Development server is activated in this way</figcaption></figure><h3>Creating Routes</h3><p>Routes are configured in the config.js file but first their respective folders have to be generated with their README.md files where the markdown of the page would be written. So in the docs folder generate various folders depending on the number of pages you want to have and name the folders according to their function. The extension .md stands for markdown</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*Z7A9ulWi0uBGuoYADmZRBQ.png" /><figcaption>This is used to create various folders with their individual README.md files in them</figcaption></figure><p>Within the above created route (about) we would update the README.md with the code below. The single hashtag(#) gives the heading a HTML equivalent of the h1 heading just as the double hashtag gives it an equivalent of the h2 tag</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*tZlvXVvQbLyS7fTriJSobA.png" /><figcaption>The single hashtag(#) gives it a HTML h1 tag.</figcaption></figure><h3>Asset handling</h3><p>Images can be added to static websites using the code format below . The code in the square brackets is the alternate text of the picture while the text in the bracket is the link of the image. In a situation where the image is local or placed in your device it can be accessed in this format(‘/image.png’).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*oSXyWBSk2usVa0f2knKkqg.png" /><figcaption>The link in the bracket is the image link</figcaption></figure><h3>Tabular content</h3><p>Most times tables are used to differentiate or compare between objects and may be useful in the documentation of your product</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*URzpCPu1uYsZ6fcXDytuqQ.png" /></figure><h3>Building</h3><p>when you are done with your vuepress site you can now build it using the command below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*rKSqypwHtTt0_NqecFquFQ.png" /></figure><h3>Conclusion</h3><p>In conclusion vuepress is a vue-themed static site generator used for documentation and static website generation.The configurations are done in the config.js file whcih resides in the .vuepress folder.Every route has its own singular folder with a README.md file where the markdown would be written</p><h3>ARIGATO(Thank you)</h3><p>Thanks for reading.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6fsxg5vNRv-do6e0.jpe" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6cc34f70f70" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>