<?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[paramsingh_66174 - Medium]]></title>
        <description><![CDATA[Let’s Javascript together - Medium]]></description>
        <link>https://medium.com/paramsingh-66174?source=rss----b94f230112f1---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>paramsingh_66174 - Medium</title>
            <link>https://medium.com/paramsingh-66174?source=rss----b94f230112f1---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 09:01:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/paramsingh-66174" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Automate E2E testing of Angular 4 apps with ProtractorJS & Jasmine]]></title>
            <link>https://medium.com/paramsingh-66174/automate-e2e-testing-of-angular-4-apps-with-protractorjs-jasmine-fcf1dd9524d5?source=rss----b94f230112f1---4</link>
            <guid isPermaLink="false">https://medium.com/p/fcf1dd9524d5</guid>
            <category><![CDATA[protractor]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[angular-4]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[jasmine]]></category>
            <dc:creator><![CDATA[Param Singh]]></dc:creator>
            <pubDate>Thu, 14 Sep 2017 14:20:55 GMT</pubDate>
            <atom:updated>2019-10-25T02:50:15.792Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*uHzesVW7BYvkvM6JXvMLtA.jpeg" /></figure><p>The other thing that works in tandem with any web app development is testing which happens at various levels — Unit testing, Integration testing, End to End testing and a lot more. The E2E or End to End testing can be either performed manually or automated to save a lot of time. And that’s precisely is our topic of discussion in this article. So, if you’re a software tester yearning to expand your horizons towards automation using the hottest web technologies of the era, hold on tight!</p><p>It’s not going to be a monotonous textual reading, you’ll have to move some muscles to make the most out of it.</p><h3>Understanding the rudiments</h3><p>Automation with Angular apps has been a breeze since the very beginning cause you might not know but Angular was built by software testers at Google. Say what!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/185/1*vaO1dChd0ZHqk-kSC3M_Zw.png" /><figcaption>ProtractorJS</figcaption></figure><p><a href="http://www.protractortest.org/#/">Protractor</a> is an official library to used for writing E2E test suites with an Angular app. It’s nothing but a wrapper over the Selenium WebDriverJS Api that translates its succinct code and methods to WebDriver JS methods. That said, you can use WebDriverJS methods too inside your e2e script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*Uf4siFkuBeF2v1Fqw_goMw.png" /><figcaption>Working of Automation Scripts using ProtractorJS</figcaption></figure><p>Not delving too much into the technical nitty-gritty, I’ll skim thorough it’s internal dynamics.</p><ol><li>There exists a Selenium Web Server that listens to Selenium commands in a special format called <a href="https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol">JSON Wire Protocol</a>.</li><li>The automation script written in WebDriver JS shoots these HTTP commands to the browser driver to “drive” or “dictate” the actions it needs to perform via Selenium web server.</li><li>The server determines the steps needed to be performed by the web driver and execute them on the app being tested and send the status back to the automation script.</li></ol><p>So, as you can see Protractor is nothing but a wrapper on top of <a href="https://github.com/SeleniumHQ/selenium/wiki/WebDriverJs">WebDriverJS</a> which in turn is nothing but a language binding of Selenium Web Driver for JavaScript.</p><h3>Jasmine</h3><p>Besides all this, <a href="https://jasmine.github.io/">Jasmine</a> is something you gotta learn and believe me it’s a piece of cake.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*0iLO5nljoMpCWnBlw_MxAg.png" /><figcaption>Jasmine Framework Logo</figcaption></figure><blockquote>Jasmine is a behavior-driven development framework for testing JavaScript code. It does not depend on any other JavaScript frameworks. It does not require a DOM. And it has a clean, obvious syntax so that you can easily write tests.</blockquote><p>Here’s a snapshot from Jasmine docs itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fBDNKILvTqF8FeauvawE_A.png" /></figure><p>And that’s it, indeed it looks “obvious”. You write the test suites and cases using the describe and it blocks respectively. You pass in a name to your test suite or case in the first argument of these blocks and a function object defining that block in the second argument. Inside the test case functions, you can use Jasmine keywords like expect something to be something.</p><p>Here’s the <a href="https://jasmine.github.io/edge/introduction">link</a> to it’s lucid and well maintained documentation.</p><h3>JumpStart</h3><p>The first step is you need to create or obtain an Angular 2+ App. If you don’t have one, you can generate it using the <a href="https://cli.angular.io/">Angular CLI</a> very easily like this:</p><pre>ng new my-test-project</pre><p>or you can clone this existing demo github <a href="https://github.com/paramsinghvc/angular-realworld-example-app">repo</a> as.</p><pre>git clone <a href="https://github.com/paramsinghvc/angular-realworld-example-app">https://github.com/paramsinghvc/angular-realworld-example-app</a></pre><pre>cd <a href="https://github.com/paramsinghvc/angular-realworld-example-app">angular-realworld-example-app</a></pre><p>Open it in your favourite text editor and get started. You can run the app using npm start in the terminal and open http://localhost:4200 in the browser to see the app.</p><h3>Writing the first Test Suite</h3><p>All we need to be concerned about is this folder, e2e</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*CbfLZ8g70OBJObXJXQi78w.png" /></figure><p>index.spect.ts is the main entry file of our automation script.</p><p>Let’s write a basic test case to check whether the title of our app is “Conduit” or not. Here’s the code for the same.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45bf49f490c6fd4e9bd81e40f298bf3b/href">https://medium.com/media/45bf49f490c6fd4e9bd81e40f298bf3b/href</a></iframe><p>Don’t get intimidated if this TypeScript + Jasmine syntax looks pretty new to you. If you aren’t comfortable with ES6, go ahead and use ES5.</p><p>The first two lines state we’re importing some stuff of code from other libraries or files like these special keywords by, browser, element from protractor library and HomePage class from our own file home.page.ts residing inside pages folder in the same directory. It’s just a module design pattern implementation since we don’t wanna overcrowd our index.spec.ts file.</p><p>Inside home.page.ts is just a class that exposes helper methods for writing our test cases for a certain section of the app.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/efc3dc438e060039f1cb9959e557dc95/href">https://medium.com/media/efc3dc438e060039f1cb9959e557dc95/href</a></iframe><p>If you’re coming from any OOPS language background, you’ll feel at home with TS. We’ve just created two methods that returns some operations on browser object of protractor.</p><p>And then we’re using these methods in our main index.spec.ts file by instantiating this class as</p><pre>const homePage = new HomePage();</pre><p>inside our main app test suite which in turn holds further sub test suites for every page of the app.</p><p>beforeAll method of Jasmine runs the function passed to it before running any of its test cases. So, we want to navigate to our home page before running any test cases on the home page.</p><p>Moving on to our main test case for determining title of our web page.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd6b0f629e6f9715e2203231584b5242/href">https://medium.com/media/bd6b0f629e6f9715e2203231584b5242/href</a></iframe><p>The browser.getTitle() method of protractor is <a href="https://blog.risingstack.com/asynchronous-javascript/">asynchronous</a>. It returns a <a href="https://developers.google.com/web/fundamentals/getting-started/primers/promises"><strong>Promise</strong></a><strong> </strong>of a value being resolved in the future which is title in our case. In the then function of this returned promise, we write a Jasmine expect case to equate the title got to be “Conduit”.</p><p>Now, lets run our test suite using npm run e2e</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*rzpfUmPmxdEmKcOXPQAywg.png" /><figcaption>Test Passing</figcaption></figure><p>The test passes successfully. Now let me just mess around, with the case as</p><pre>expect(title).toEqual(&#39;Conduits&#39;);</pre><p>This time it fails with an output like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TLjr7nYh-9xs9tM3LEJBhA.png" /><figcaption>Failing test case — Jasmine Reporter</figcaption></figure><h3>A level up</h3><p>Congrats, we just ran our first basic test e2e test case. But it’s just the tip of the iceberg. There’s hell lot more things you can do using protractor + jasmine test scripts.</p><p>Now, kindly checkout to complete git branch of the project using</p><pre>git checkout complete</pre><p>If you now observe home.page.ts file, it has the following function</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e29a4b74cf85a825658dffd3ba87bcc/href">https://medium.com/media/0e29a4b74cf85a825658dffd3ba87bcc/href</a></iframe><p>It’s using the protractor ElementFinder syntax to locate an element in the DOM by it’s tagName. As you can see, the syntax is really intuitive.</p><p>You can locate elements using several techniques like through CSS as</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c291ff767dc1f69f40150b9e7ee25e09/href">https://medium.com/media/c291ff767dc1f69f40150b9e7ee25e09/href</a></iframe><p>or even xpath</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0cd9882543bbff123c08d91d834d7d06/href">https://medium.com/media/0cd9882543bbff123c08d91d834d7d06/href</a></iframe><p>For the complete list of protractor locators, refer to <a href="http://www.protractortest.org/#/api?view=ProtractorBy">docs</a>.</p><p>The index.spec.ts has some new things too like some jasmine functions as toContain or toBeTruthy or toBeGreaterThan.</p><p>Also, if you have worked on writing automation scripts before in any framework or language, you might have found yourself waiting for the asynchronous events to complete by introducing nasty delays like</p><pre>browser.sleep(4000);</pre><p>Cheer up! No more need of these uncertain nasty sleeps with protractor. You can run automation tests with more confidence by using methods like browser.wait</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4b080c109854746a720da4d2fd8ac12/href">https://medium.com/media/e4b080c109854746a720da4d2fd8ac12/href</a></iframe><p>So, basically we’re waiting for our loader element on the page to become hidden which marks the loading of our articles list successfully. In the second argument, we’re passing a max timeout to prevent the wait from running infinitely.</p><p>After this statement, we can run our case on the loaded articles in a clean and legit way.</p><h3>Summary</h3><p>There’s lot more to cover but the idea of this little tutorial is to help you kickstart automation scripting for Angular apps. So, now that you’ve got your hands dirty with it, go ahead, fork the repo and don’t stop until you finish the complete e2e testing of this app seeking help from those vast Protractor and Jasmine docs. For me, that’s the best way to learn. Learn by practice! Not only does automation helps you save a lot of time for regression testing but also it’s fun letting the magic happening in front of you.</p><p>If you’re wondering whether I can use protractor for testing non-angular apps, you’re not wrong. We can. So, stay tuned. Rumour has it, next post coming up would be pertaining to this. Till then, keep automating 🤖.</p><p>Happy Testing 🤓</p><p>Liked the article? Support me since it keeps me motivated to write more stuff like this 🙂</p><figure><a href="https://www.buymeacoffee.com/7tUA9TS"><img alt="" src="https://cdn-images-1.medium.com/max/434/1*SGCT6C60o4t58wRqeU2viQ.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fcf1dd9524d5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/paramsingh-66174/automate-e2e-testing-of-angular-4-apps-with-protractorjs-jasmine-fcf1dd9524d5">Automate E2E testing of Angular 4 apps with ProtractorJS &amp; Jasmine</a> was originally published in <a href="https://medium.com/paramsingh-66174">paramsingh_66174</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Up Close and Personal with VueJS]]></title>
            <link>https://medium.com/paramsingh-66174/getting-up-close-and-personal-with-vuejs-37bea694e0cf?source=rss----b94f230112f1---4</link>
            <guid isPermaLink="false">https://medium.com/p/37bea694e0cf</guid>
            <category><![CDATA[vuex]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Param Singh]]></dc:creator>
            <pubDate>Tue, 15 Aug 2017 12:57:32 GMT</pubDate>
            <atom:updated>2017-08-15T12:57:02.711Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*wqYF-8Dmh7LhtLkKfERc3Q.png" /><figcaption>VueJS Logo</figcaption></figure><p>Amidst the tug-of-war going on between the most popular JS frameworks Angular and React, I found solace with another kid on the block namely VueJS(pronounced /vjuː/). But this kid is as powerful and plush as the already existing frameworks out there. In fact, the folks at Vue claim it to be more powerful and performant than any other JS framework. Check out this <a href="https://vuejs.org/v2/guide/comparison.html">link</a> for more info.</p><p>Let’s see how to and why there’s even a need to delve into this yet another UI framework.</p><h3>Orchestration</h3><p>It’s very easy to jumpstart on Vue for beginners since the scaffolding is really a breeze when it comes to Vue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*15boHZjyoHHNO1qg3Z3ILw.jpeg" /></figure><p>It’s as simple as this</p><pre>&lt;script src=&quot;https://unpkg.com/vue&quot;&gt;&lt;/script&gt;</pre><p>Unlike other frameworks out there, it’s really simple to start using Vue. To be specific, I’m talking about Angular in which I honestly don’t bother to learn about another module loader be it SystemJS or rollup with those verbose configurations. While Angular enforces you to use TypeScript and React coerces you to use JSX, Vue inculcates pure web standards like real html, css and JS.</p><h3>Data Binding</h3><p>When it comes to data binding, Vue is no less than various plush frameworks out there. It supports all kinds of data and event binding syntaxes and even more. Consider this pug template snippet</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/efc65dfc9d63e8268b580100d36bca98/href">https://medium.com/media/efc65dfc9d63e8268b580100d36bca98/href</a></iframe><p>And here’s the script for the same</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d424b300e868c0f5c6eb1fa12a129167/href">https://medium.com/media/d424b300e868c0f5c6eb1fa12a129167/href</a></iframe><p>For binding the html attributes and component input properties, you can use the v-bind directive or a shorthand property :attrName while providing a valid JS expression in the right side of the equal operator.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da0c9a149a708be23985d0876c410f06/href">https://medium.com/media/da0c9a149a708be23985d0876c410f06/href</a></iframe><h3>Looping</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*TsB_oosluyKhNKyMINHvyg.png" /></figure><p>Pretty much like Angular’s *ngFor, but the v-for directive supports looping over object using the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in">for-in</a> loop and iterators using the <a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for...of">for-of</a> loop.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a1d15dee53d399f2324205d88683608/href">https://medium.com/media/8a1d15dee53d399f2324205d88683608/href</a></iframe><p>The data looks like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a80e2559964e6545631780aba0a84fc8/href">https://medium.com/media/a80e2559964e6545631780aba0a84fc8/href</a></iframe><h3>Event Handling</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/248/1*VtDLOsSq_Q3UeJs6BLOqmQ.jpeg" /><figcaption>User Input Events like keypress or mouse click</figcaption></figure><p>This part I love the most over Angular’s since it‘s more improved</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6b160d77819e2798b2d42929f419457/href">https://medium.com/media/f6b160d77819e2798b2d42929f419457/href</a></iframe><p>And for the sake of brevity, you can use this @ notation too</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b18adef3def1fb029d35fc0a0dd80f43/href">https://medium.com/media/b18adef3def1fb029d35fc0a0dd80f43/href</a></iframe><p>Here’s the JS for the same, nothing fancy here.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30ccb539ea1b8baf4529eca012e1036b/href">https://medium.com/media/30ccb539ea1b8baf4529eca012e1036b/href</a></iframe><p>And here comes the most solicited feature that I like, <strong>Event Modifiers</strong>, i.e there’s no more need to preventDefault or stopPropagation inside your event handler function. You can easily do that declaratively inside your template like this</p><pre>a(@click.capture.stop.prevent=&quot;doSomething&quot;)</pre><p>or</p><pre>input(v-on:keyup.13=&quot;submit&quot;)</pre><p>How succinct! Isn’t it? These little features of Vue attributes to its ease of use and brevity which not only speeds up the development time but also makes the code look less verbose.</p><h3>Single File Components</h3><p>So far, we have just witnessed how Vue syntax looks like. But talking in more practical sense, you might be wondering how can I use this simple looking library to substitute my existing mammoth project built over maybe Angular or React?</p><p>The thing with Vue is that, it comes in all the forms you like, be it a teensy hobby project or a corporate level project. You as a developer are given full liberty to tailor it according to your needs.</p><p>Consider this Vue component that holds all of the three things together encapsulated in a single file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UAhKGxGXVeCMw5bL0FBp8Q.png" /></figure><p>So, as you can see, a single file is holding template tag, style tag and a script tag making it really comprehensive just at the first look. And there’s not even a single thing that breaches the W3C guidelines. In fact, this is the most W3C true-blue version of creating a web component I’ve ever seen after Polymer.</p><h3>The Sassy way</h3><p>Astute readers might observe from the previous example, I’ve used SASS for the styling needs and pug for templating. All you need to do is set the lang attribute of template and style tags and install pug and sass related packages from npm</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/1*9uPRH3nebr03jq8xwRkPKA.png" /><figcaption>Syntactically Awesome Style Sheets</figcaption></figure><blockquote>Vue.js is pretty cool in that it works with <a href="https://github.com/tj/consolidate.js">lots</a> of HTML template languages out of the box.</blockquote><p>So, all you need to do is</p><pre>&lt;template lang=&quot;pug&quot;&gt;</pre><p>and for SASS</p><pre>&lt;style lang=&quot;scss&quot;&gt;</pre><h3>State Management</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*FuX6v0XoU7Xd1FFBuEX9nQ.png" /><figcaption>Vue + Vuex + Nuxt</figcaption></figure><p>Ever since the inception of Flux with React, Centralised State Management pattern has become an elixir for creating any heavy web app these days. While there’s insanely popular Redux, Vue does State Management in it’s own way through a library <a href="https://vuex.vuejs.org/en/intro.html"><strong>Vuex</strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sl2AAI-zL-8LiRg47NGJgg.png" /><figcaption>Vuex Core Concept Flow Diagram</figcaption></figure><p>The core concept is same as Redux which includes immutability, central management of state etc. Only the jargon differs a bit. Reducers are apparently called <strong>mutations </strong>and the <strong>actions</strong> commit these mutations to make a change in the state. Also, actions can be async too inherently unlike Redux where you have to remain dependent on <a href="https://github.com/gaearon/redux-thunk">redux-thunk</a> middleware to handle this “special case” of asynchronicity.</p><p>Here’s an example from the <a href="https://vuex.vuejs.org/en/actions.html">docs</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/34f3da1ad150fe66944de26c646d8b13/href">https://medium.com/media/34f3da1ad150fe66944de26c646d8b13/href</a></iframe><p>and then an action can be dispatched on some user’s or asynchronous event as</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/650ee8dd0948a6d30896500831d91606/href">https://medium.com/media/650ee8dd0948a6d30896500831d91606/href</a></iframe><h3><strong>NuxtJS</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*m0p_ovZ1d2CqGvvVmsXs2g.png" /></figure><p>If you’re concerned about the rapid first meaningful paint for your public facing B2C web app. You must look for integration with <a href="https://nuxtjs.org/guide">NUXT</a> for Universal or Server Side Rendering. You can easily generate a Nuxt powered Vue app with vue-cli as</p><pre>$ vue init nuxt/starter project-name</pre><p>It’ll provide you with a folder <a href="https://nuxtjs.org/guide/directory-structure">sturucture</a> which gets automatically translated to Vue Router internally. For eg, you can create parameterised routes by creating a file name prefixed with underscore.</p><p>Also, for loading some data prior to rendering a view, it provides with a <a href="https://nuxtjs.org/guide/async-data">asyncData</a> lifecycle hook in which you can perform some asynchronous task and hydrate your view when it’s visible. It’s with full support of async/await proposal.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/404558501783ce65cfd817fddc52b56b/href">https://medium.com/media/404558501783ce65cfd817fddc52b56b/href</a></iframe><p>It also provides a wonderful support for SEO using <a href="https://github.com/declandewet/vue-meta"><strong>Vue Meta</strong></a>, pretty much like <a href="https://github.com/nfl/react-helmet">react-helmet</a> out of the box. Check out this <a href="https://nuxtjs.org/examples/seo-html-head">example</a> for more info.</p><h3>Vue CLI</h3><p>Vue has emanated to decrease the development efforts while alleviating the problems present with other JS frameworks in the market. Keeping this in mind, the Vue team has provided us with this beautiful CLI for scaffolding your first Vue project swiftly.</p><pre>$ vue init pwa project-name</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7ATpnJF-3FsyWIJAco3FyA.png" /><figcaption>Initialising a vue project using vue-cli</figcaption></figure><p>Vue offers various scaffolding templates. You may choose any of them based on your requirement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O0v5jjwD2dD9qB6Jrs04bQ.png" /><figcaption>Vue CLI scaffolding templates</figcaption></figure><p>And that’s all you need to hit to start working like a pro with all the production ready build scripts for you without worrying about webpack configs and all.</p><h3>Vue Dev Tools</h3><p>Debugging has never been such a breeze. Thanks to this awesome <a href="https://github.com/vuejs/vue-devtools">devtools</a> by the Vue team with the support for both Vue Component level and Vuex level debugging.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_KhPP7io0QJ06y_H7Ztl-Q.gif" /><figcaption>Vue Chrome Dev Tools</figcaption></figure><p>Yet another reason for picking Vue for your next project.</p><h3>Conclusion</h3><p>While the dev community is going frenzy over whether to choose React or Angular, I believe it won’t be a wrong move to choose Vue because not only it inhabits all the already existing features of other frameworks but also it does it in a better, clean and standardised way. Also, as evident, Vue takes the W3C specs and proposals quite seriously, so I don’t see it being tossed away any sooner amidst the bloodshed of JS frameworks.</p><p>True, choosing Vue will impact your project but in a positive way by reducing your development time and minimising your bundle size too.</p><p>So after getting “up close and personal” with Vue, I’m totally sold! What about you?</p><p>Thank You! Happy Coding 🤓</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37bea694e0cf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/paramsingh-66174/getting-up-close-and-personal-with-vuejs-37bea694e0cf">Getting Up Close and Personal with VueJS</a> was originally published in <a href="https://medium.com/paramsingh-66174">paramsingh_66174</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AngularJS vs ReactJS]]></title>
            <link>https://medium.com/paramsingh-66174/angularjs-vs-reactjs-e651a194dfcb?source=rss----b94f230112f1---4</link>
            <guid isPermaLink="false">https://medium.com/p/e651a194dfcb</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angularjs2]]></category>
            <category><![CDATA[angularjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Param Singh]]></dc:creator>
            <pubDate>Sun, 06 Aug 2017 11:24:47 GMT</pubDate>
            <atom:updated>2016-08-04T11:49:54.779Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*Uv4p86CnyzJ6sfRHxoew7Q.png" /></figure><p>Hello folks, I kept my promise and here I am with my second post on comparison between what it is working with AngularJS and ReactJS.</p><p>Disclaimer: All these points are a conglomeration of my thoughts and experience. They might vary from person to person. I’m just sharing my take on choosing one of them.</p><p><strong>Framework vs Library</strong></p><p>Here we are comparing a full fledged framework (Angular) with a mere library (React). This is the very first thing every frontend developer needs to understand. Angular comes up as a whole “opinionated package” I must say while the latter is just a plain JS library. Now, while it is easier to learn an opinionated environment from scratch, it’s most of the times a confusion to start with a library to make it <em>behave </em>like a framework. I was really bewildered by the introduction of this new library while I was flowing in the Angular waves and this was the very first difference I observed between the two. The very thought of collating several third party or maybe official libraries to make it at par with the already existing standard framework of Angular kept me loyal towards Ng than this new little library. So, working with framework and library has their own pros and cons. While framework gives a well defined path in an opinionated way to develop things, using libraries, you have to depend on few other libraries to achieve the same task.</p><p><strong>Learning Curve</strong></p><p>This is one of the major driving force making developers choose what they should go with. After working with both Angular 1&amp;2 and React, definitely learning AngularJS is tougher than ReactJS. Reason being, ReactJS is truly JS while for learning Angular especially Angular 2, you have to learn TypeScript, RxJS which I’m a fan of. I too was very rigid of not choosing TS or RxJS in the beginning, but when I used them, I saw their pros and found that, it was worth the effort. Though choosing between es6 or TS is a common source of confusion for beginners of ng 2. I suggest you go as per the ng 2 community advice and adapt TypeScript. If you know any oops language, it’s a piece of cake for you to learn it. Now, talking about React, it took me just a day to learn it! Since, it was just JS, I adapted it pretty quickly. JSX though seemed a little odd in the beginning but when you get a hold of it, its nothing. On the other hand, it took me a month to learn Angular 2 with all the RxJS and TS stuff and learning the completely new facet of Angular 2 as you might know that Angular 1 and 2 are very much different in terms of semantics and architecture.</p><p><strong>Speed</strong></p><p>When Angular 1 was introduced years back, being the sole player in the market, it took a huge popularity among the devs and it was really something very fascinating thing introduced by Google. It completely revolutionised the way we used to write those ugly looking spaghetti JQuery web pages. The code and folder structure now was more organised and clean. It went for a lot of time but on the introduction of ReactJS and its fast performance, questions starting rising up on the performance of AngularJS. Yes, I’m talking about the notorious ng-repeat. When it comes to handling thousands of DOM rows, its wise to go for React than Angular 1 but hey what about Angular 2? They (Angular creators) claim Angular 2 to be 5x times faster than Angular 1 as now the UI thread is freed up from JS computation. Angular 2 makes use of web workers to free up the UI thread for rendering purpose. All the heavy JS tasks will happen in the backend. Having said that, I find the famous “Virtual DOM” of ReactJS taking all the lime light in this case. This is what makes React so popular. As we all know, DOM operations are pretty expensive in a web app and when it comes to handling thousands of records or elements, React uses its powers like the Virtual DOM and smart diff Algorithm. I don’t wanna get into the details but the end result is superb. The web apps using react are fast and less juddery.</p><p><strong>Scaffolding &amp; Packaging</strong></p><p>I can recall those days of struggling with requirejs for modules and dependency management and the main struggle comes when you need to bundle up the things for your production environment. Angular 2 though provides a beautiful angular-cli as a scaffolding tool that generates the boilerplate for you to start with. I didn’t try much to peek under the hood of that scary scaffolding. With React, you have this wonderful tool called webpack, very lucid and easy to use with features like code chunking and production environment compression etc, its makes it very easy to ship apps easily.</p><p><strong>Server Side Rendering</strong></p><p>With Angular 1, there has always been a complain that it takes huge time for the users to see the initial view of the page load. While there are ways to mitigate that by applying app bootstrap loaders but it doesn’t solve the real problem. With Angular 2, we have this tool called Angular Universal that supports Server Side Rendering. What it means is that, when the app is being loaded, the server will render an initial view of the page and then when slowly the client apps loads its main bundle js file, Angular will kick in and handle the UI interactions. And the same is true for React using Redux, you can specify the initial state of the application that helps you render the initial view of the page.</p><p><strong>Component based Approach</strong></p><p>As web has evolved over time, there has been introduction of this nice component based architecture. Everything on your web page is a component that can further have sub components and so on. This makes it very clear for the developers to comprehend about their apps before building them. I find it very clean now as opposed to that <em>mess </em>before. Angular 1 doesn’t encourage Component based architecture while Angular 2 does and so does React.</p><p><strong>Bytes Matters</strong></p><p>Now, lets cut to the chase and discuss about yet another important aspect for deciding frontend framework for your apps, <strong>Sizing.</strong></p><p><strong>Angular 2:</strong> 766k (with RxJS)<strong><br>Angular 1:</strong> 143k<br><strong>React + Redux:</strong> 139k</p><p>Whoa, that’s a lot of numbers. At the very first glance, it makes Angular 2 a poor contender for our choice. But lemme tell you, these are the numbers I got from internet and the pragmatic numbers vary. Practically, my react redux app takes like 1.2 mb! Ouch! And thats because, its not just react+redux required to build a beautiful app, it takes libraries like Material-UI or Angular Material which takes a heavy toll on size. That said, I’m able to mitigate that concern through webpack chunking about which I’ll write a post about soon. But lets limit our discussion to creating apps without material-ui libraries for now, and you can see the difference. I’m not really sure about this but I understand in ng-conf 2016, they claimed the Angular 2 size to be about 150 kb. In the end, I’d like to say that don’t go by these numbers, there are a number of other libraries you need to rely for your particular requirements, so it may vary.</p><p><strong>Building for Mobile</strong></p><p>How cool it would be for you if what you have learnt to create web apps could be used to create Mobile Apps at the same time. Yes, both of these frameworks help you to create mobile apps but in different ways. For Angular 1 &amp; 2, there’s Ionic 1 &amp; 2 respectively. The 2 versions of both Angular and Ionic haven’t stabilised yet while React Native on the other has gained a lot of popularity and many of the popular apps in my knowledge have shifted to React Native. There’s also a buzz about NativeScript for Angular folks. The main difference between Ionic and React Native is that Ionic is used to build Hybrid web apps using AngularJS architecture and Cordova while React Native gives you a fully native experience.</p><p><strong>P.S.</strong></p><p>Both of these frameworks have performed well and has revolutionised the way we developed web apps before. Angular 1 has been there for quite a long time and since the launch of ReactJS, a lot of commotion has been there. Reason being, React seems to adapt to the new web standards way earlier than Angular. Angular 2 has come but is late, it’s still in RC(Release Candidate) at the time of writing this post. I have enjoyed working with ReactJS more over AngularJS. So, lets put an end to this discussion. As per me, concluding that ReactJS is more powerful contender for choosing frontend framework won’t be wrong. Though, definitely learning isn’t harmful in any way. You can always learn and come out with a mixture of good features from both the frameworks and have the best of both worlds.</p><p>Thank You! Comments most welcome.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e651a194dfcb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/paramsingh-66174/angularjs-vs-reactjs-e651a194dfcb">AngularJS vs ReactJS</a> was originally published in <a href="https://medium.com/paramsingh-66174">paramsingh_66174</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web Accessibility — Developing web with empathy]]></title>
            <link>https://medium.com/paramsingh-66174/web-accessibility-developing-web-with-empathy-2aee08ebe97c?source=rss----b94f230112f1---4</link>
            <guid isPermaLink="false">https://medium.com/p/2aee08ebe97c</guid>
            <category><![CDATA[web]]></category>
            <category><![CDATA[a11y]]></category>
            <category><![CDATA[accessibility]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Param Singh]]></dc:creator>
            <pubDate>Sun, 06 Aug 2017 11:24:37 GMT</pubDate>
            <atom:updated>2016-12-06T16:49:06.559Z</atom:updated>
            <content:encoded><![CDATA[<p>Even while developing web apps for years, we forget about one really important thing and that’s called Web Accessibility. It’s going to be our topic of discussion in this article. We’ll be learning what accessibility is, why is it important, how to develop well accessible web apps and in the end see an example.</p><h3><strong>What’s accessibility?</strong></h3><p>As per wiki,</p><blockquote><strong>Accessibility or A11y </strong>refers to the design of products, devices, services, or environments for people who experience disabilities.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JCxvynyoqfCCwDF86mf1Qw.jpeg" /></figure><p>Hence, by making web accessible means we are targeting a wide range of users by making our web app reachable to people with a plethora of disabilities. Here’s an excerpt from <a href="https://www.w3.org/WAI/intro/accessibility.php">w3</a> website.</p><blockquote><strong>Web accessibility means that people with disabilities can use the Web</strong>. More specifically, Web accessibility means that people with disabilities can perceive, understand, navigate, and interact with the Web, and that they can contribute to the Web. Web accessibility also benefits others, including <a href="https://www.w3.org/WAI/bcase/soc.html#of">older people</a> with changing abilities due to ageing.</blockquote><p><strong>WCAG</strong>: The Web Content Accessibility Guidelines are part of a series of Web accessibility guidelines published by the <strong>Web Accessibility Initiative(WAI) </strong>of the World Wide Web Consortium (<strong>W3C</strong>).</p><p><strong>WAI-ARIA</strong>: Web Accessibility Initiative — Accessible Rich Internet Applications is a technical specification published by the W3C that specifies how to increase the accessibility of web pages, in particular Dynamic Content and UI components developed with AJAX.</p><h3><strong>Why should I care?</strong></h3><p>We developers are in a habit of doing RAD (Rapid Application Development). Many a times we find ourselves in a scurry of finishing our projects in order to meed the deadlines using plush frameworks and tools out there. In this haste, we forget the notion of ARIA (Accessible Rich Internet Applications) and simply assume that my website is going to be used by people like me. This thought is really perilous for both you and your users. In fact, out of all the Front End developers I’ve met and interviewed, most of them don’t even know what ARIA or even accessibility is because no one bothers to learn about it. We treat it as an “additional” feature to our apps. I too used to think the same way ever since it hit me while using bootstrap in the good old days. Watching those “useless” aria-* and role attributes, frankly I used to delete them from my markup (*chuckle*). But learning their significance, I understand their importance now.</p><h3>Understanding your users</h3><p>One important step while creating ARIA is understanding the diversity of users. There are several people with different kind of disabilities like visual, motor, auditory, speech or cognitive impairments. The way they access your web apps is different. Most of them use Screen Readers, Braille device, eye tracking etc to access it. These impairments could be temporary or permanent. In fact, in our lifetime, we all experience the such situations in one way or the other like a temporary broken arm, blurry vision etc. So, if you develop web apps using proper web standards, it’ll become easier for all of your users to perceive your web content easily which otherwise is impossible.</p><h3>How can I make my web apps Accessible?</h3><p>Okay, enough of the theory now, lets learn how we can actually make ARIA apps. There are several steps involved.</p><p><strong>Managing Focus</strong>: First and foremost, you need to make sure your app is capable to be browsed by using keyboard only. By keyboard I mean using tabs and focus. An element that is focusable is the one which is able to receive input from the user like a focused button could be clicked by hitting enter or an input field could receive text by simply typing the letters. So, for people with motor and visual impairments, those who are unable to or find it difficult to use the mouse might be solely dependent on using keyboard for accessing your app. Hence, managing focus in your app is a really important step towards making your web app accessible.</p><p>All native input elements like buttons, input form fields are by default focusable but the problem comes when most of the time you create custom elements or <strong>web components </strong>I should say in this current trend of creating web apps. I guess none of us like to see those hideous radio buttons or checkboxes, autocomplete boxes, file inputs etc. To counter that and maybe to meet the expectations of the UI/UX designer, we tend to create custom elements by ourselves and completely forget about managing focus in our component. In fact, there’s a wide range of components rubrics available on w3 website at <a href="https://www.w3.org/TR/wai-aria-practices-1.1/">https://www.w3.org/TR/wai-aria-practices-1.1/</a>. One must go through them while creating a custom component.</p><p>Talking about focusing elements by using tab key to move the focus forward to the next element and shift + tab to move backward, we as developers must respect it to make sure it reaches the right element in the Accessibility tree. Imagine a visually impaired user using screen reader to narrate the next elements using tabbed focus, if the focus reaches an irrelevant info element like an icon or some adornment thing in your app, it can be perplexing. Hence, you might wanna provide some meaning response to the user while he presses tab on your app. A very nice example is available on our beloved site <a href="http://www.github.com/">github.com</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W9Bg_jEq84t4iJD_EUyMqA.gif" /><figcaption>Skip Links implementation on github</figcaption></figure><p>On pressing tab after landing on github, you see a “Skip to Content” div which is hidden otherwise to facilitate navigating to the main content of the page right away.</p><p>This is one example, the main challenge comes when one has to fill in a form and you have created the form using custom elements. And if you haven’t taken care of focus management, the users might not be able to submit the information to your form. So, it’s very important to go through the w3 <a href="https://www.w3.org/TR/wai-aria-practices-1.1/">rubrics</a> cited above while creating custom components. Here’s a <a href="https://codepen.io/paramsinghvc/pen/gLoYQg">codepen</a> I created using the proper focus management for my custom tab component using a technique called <a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/Keyboard-navigable_JavaScript_widgets#Technique_1_Roving_tabindex"><strong>Roving Focus</strong></a>. In this, you set the initial tabindex of all your sibling elements (tabs in our case) to -1 and then set only one of them as 0 to receive focus and this shifting it over in the list by listening to the arrow keys events.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*oaONfnVqPo8aS1zvKKPVrg.gif" /><figcaption>Custom Tabs and Tabpanel example</figcaption></figure><p>Same way, if you’re creating a group of checkboxes or radio boxes you need to take immense care of focus and these keys events. One could encounter problems like keyboard traps as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*Cz45zhwtqRHd6ksOxlqgmA.gif" /><figcaption>Keyboard trap for tab key</figcaption></figure><p>So, in this example, I can’t move to the next ‘Date From’ element because the tab key is trapped as an event in the Search Terms input field. The good UX states there should be no such keyboard traps since it’s very blocking in nature, there should be some way developed to get out of this trap say by using escape key. Also, as per the <a href="https://www.w3.org/TR/UNDERSTANDING-WCAG20/keyboard-operation-trapping.html">WCAG guidelines section 2.1.2</a> keyboard trap should not be there.</p><p>The DOM order and tab order should be in sync</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4899635637edbd354640e01e6a2cb7c/href">https://medium.com/media/c4899635637edbd354640e01e6a2cb7c/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/814037446fec36917b5814d7f5b33559/href">https://medium.com/media/814037446fec36917b5814d7f5b33559/href</a></iframe><p>Setting the DOM order the latter way will confuse the users using screen readers. So, it’s an anti pattern to use such practice. In fact, your tabindex most of the time would be either 0 or -1.</p><p><strong>Semantic HTML</strong>: Making use of HTML5 semantic tags can be really helpful here. Tags like &lt;header&gt;, &lt;main&gt;, &lt;section&gt;, &lt;footer&gt; helps the assistive technologies interpreting your web content easily. Also, using these semantic tags give a boost for SEO(Search Engine Optimisation). These tags are nothing but a &lt;div role=””&gt;, div with a role attribute set “banner” for &lt;header&gt;, “main” for &lt;main&gt;, “contentinfo” for &lt;footer&gt;. In fact, it used to be a way of writing semantic html in the period that predated HTML5.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*flrGosulN9g5588-h9_jHw.gif" /><figcaption>HTML 5 Semantic Tags</figcaption></figure><p><strong>ARIA Roles</strong>: ARIA roles define the type of element and suggest what purpose it serves.</p><pre>&lt;div role=&quot;alert&quot;&gt;<br>    Please upgrade to the latest version of your browser for the best experience.<br>&lt;/div&gt;</pre><p>Specifying a role to an element helps the browser treat in its own way. For eg: If you add a role of button to a div, it’ll become focusable automatically to behave like a button.</p><p>For a full list of available roles and aria attributes in HTML5, see this lucid graph by w3 <a href="https://www.w3.org/TR/wai-aria/rdf_model.svg">https://www.w3.org/TR/wai-aria/rdf_model.svg</a></p><p><strong>ARIA Attributes</strong>: The ARIA attributes are used in conjunction to provide supportive information for the assistive technologies to determine. For eg: helping the screen reader speak out the state of your custom checkbox, you might wanna include aria-checked property as follows:</p><pre>&lt;span role=&quot;checkbox&quot; <br>      aria-checked=&quot;true&quot;<br>      tabindex=&quot;0&quot;<br>      id=&quot;myCheckbox&quot;&gt;<br>&lt;/span&gt;</pre><p>Also, you must handle the click event of this span to toggle the aria-checked state along with the visual change. This kind of aria attribute is state based attribute.</p><p>There exist another kind of aria attribute called property attributes like aria-label</p><pre>&lt;p aria-label=”author name”&gt;Param Singh&lt;/p&gt;</pre><p>For further reading about the classification of ARIA attributes and their uses, I suggest referring to <a href="https://www.w3.org/TR/wai-aria/states_and_properties">https://www.w3.org/TR/wai-aria/states_and_properties</a></p><h3>ARIA rules and Caveats</h3><p><strong>Use Semantic HTML where possible</strong>: Always prefer using &lt;header&gt; for your web app header section since they already have a role=”banner” set implicitly. Also, good from SEO perspective.</p><p><strong>One Element — One Role</strong>: There should be only one role per one element.</p><p><strong>Never change native semantic tag roles</strong>: We must never do something like this</p><pre>&lt;footer role=&quot;button&quot;&gt;</pre><p><strong>Using those unsung native tags</strong>: I’m talking about tags like blockqoute, cite, q</p><pre>&lt;blockquote cite=&quot;<a href="http://www.imdb.com/character/ch0000672/quotes">http://www.imdb.com/character/ch0000672/quotes</a>&quot;&gt;<br>    &lt;p&gt;<br>        You know the golden rule, don’t you boy? Those who have the gold make the rules.<br>    &lt;/p&gt;<br>    &lt;footer&gt;<br>        &lt;a href=&quot;<a href="http://www.imdb.com/character/ch0000672/quotes">http://www.imdb.com/character/ch0000672/quotes</a>&quot;&gt;Crazy hunch-backed old guy in Aladdin&lt;/a&gt;<br>    &lt;/footer&gt;<br>&lt;/blockquote&gt;</pre><p><strong>Using alt with images</strong>: We should always develop a habit of including alt attribute in our image tag, not only from ARIA perspective it’s right but also in case the image has failed to load, one could see some descriptive text in place of it which is in favour of <strong>Progressive Enhancement</strong>. And not to mention SEO, the crawlers and spiders look for such attributes helping them index your web content easily.</p><pre>&lt;img src=&quot;dog.jpg&quot; alt=&quot;A golden labrador playing in the park&quot;&gt;</pre><pre>&lt;figure aria-labelledby=&quot;operahouse_1&quot; role=&quot;group&quot;&gt;<br>    &lt;img src=&quot;operahousesteps.jpg&quot; alt=&quot;The Sydney Opera House&quot;/&gt;<br>    &lt;figcaption id=&quot;operahouse_1&quot;&gt;We saw the opera &lt;cite&gt;Barber of Seville&lt;/cite&gt; here!&lt;/figcaption&gt;<br>&lt;/figure&gt;</pre><p><strong>Color &amp; Contrast</strong>: Taking into account the visually impaired users, we should spend some time choosing the right palette for the theme of our web app. The primary and accent colors should have a good contrast ratio. We should avoid camouflaging coloured text over a div with the same color. Instead, one should follow the golden rule of KISS(Keep it Simple Stupid!). One of the prominent examples of this is Google.com in that it’s so user friendly because it’s really simple with a white background and simplified user interaction.</p><p>As per WCAG 2.0 level AA requires a contrast ratio of <strong>4.5:1</strong> for normal text and 3:1 for large text. Level AAA requires a contrast ratio of 7:1 for normal text and <strong>4.5:1</strong> for large text. Large text is defined as 14 point (typically 18.66px) and bold or larger, or 18 point (typically 24px) or larger.</p><p>Also, out touch targets like buttons, input fields must be large enough to receive user touch inputs. The optimum size of such touch targets should be around 48px.</p><p>Here’s an example of a little app I created with accessibility taken care of. <a href="https://restaurants-reviewer.herokuapp.com/">https://restaurants-reviewer.herokuapp.com/</a></p><h3>Conclusion</h3><p>The one thing I love about web is that it makes any mundane information readily available. You just have to navigate to a web site. So, following this norm, making it reachable to every person becomes our responsibility as web developers. Remember one thing, developing accessible web apps is not only good for ARIA but also for SEO.</p><p>At last, all I would say is “Just be considerate!”</p><p>Thanks</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2aee08ebe97c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/paramsingh-66174/web-accessibility-developing-web-with-empathy-2aee08ebe97c">Web Accessibility — Developing web with empathy</a> was originally published in <a href="https://medium.com/paramsingh-66174">paramsingh_66174</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modern Web Development & Practices]]></title>
            <link>https://medium.com/paramsingh-66174/modern-web-development-practices-64194d9a48?source=rss----b94f230112f1---4</link>
            <guid isPermaLink="false">https://medium.com/p/64194d9a48</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[framework]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angularjs]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Param Singh]]></dc:creator>
            <pubDate>Sun, 06 Aug 2017 11:24:27 GMT</pubDate>
            <atom:updated>2017-02-19T09:35:19.919Z</atom:updated>
            <content:encoded><![CDATA[<p>The web platform has been expanding just like the Universe as per the Big Bang Theory. Every day or the other we hear about a new library or tool that’s there on npm or github. Gone is the time when all we needed to create a web page was a primitive HTML page with some inline CSS and a bit of JavaScript to add “interactivity” to the web page. The contemporary era demands way more than this. Hence, leaving us with a myriad of Frameworks and libraries one day or the other. I love this power of Open Source, it’s created for us and by us. But, these numerous tools and libraries might leave one overwhelmed to choose one over the other. So, without saying much here I’m sharing my preferred practices for building kickass development environment and end products.</p><h3>Editors</h3><p>Editors being the important part of our lives as developers. We should be choosy enough to pick the best one for our needs. Below are a few popular ones.</p><p><a href="https://www.sublimetext.com/"><strong>Sublime Text 3</strong></a>: As they say, “<em>The text editor you’ll fall in love with</em>”. Indeed, its the one and personally my favourite. Why? Because, it’s simply really fast and for a multi-tasker like me who keeps a number of projects open at a time, it bears me well (unlike other text editors :P). Not only this, it has a really good open source support for plugins, be it code formatting, theming, auto completion etc. All of this at a minimal cost of size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mie32xyKng86Ioe4Rsbusw.png" /><figcaption>Sublime Text 3 Editor</figcaption></figure><p><a href="https://atom.io/"><strong>Atom</strong></a>: Another good open source editor to fit your needs is Atom built using electron and hence “<em>hackable to the core</em>” in their words. Just like Sublime it has good support for plugins and themes. Also, it’s crude theme is very cute and luring. But do not fall for this cuteness if you plan to use it for multiple projects at a time. I used it for some time and it used to crash as it couldn’t hold the burden like Sublime does. That said, one reason I would favour using it over Sublime would be it’s support for in built terminal</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LwenlBkVgnPcMocOamjpGA.gif" /><figcaption>Atom Editor</figcaption></figure><p><a href="https://www.jetbrains.com/webstorm/"><strong>WebStorm</strong></a>: It’s more than just an editor since it’s an IDE (Integrated Development Environment) by JetBrains with a lot of features like code completion, breakpoint debugging, tracing and profiling etc and yeah an in built terminal too (pretty much like Eclipse for web). Only thing is that it’s paid and again good things come at a cost of memory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*X5AycZ1e4CHlZlC6g4HYYw@2x.png" /><figcaption>IntelliJ — WebStorm</figcaption></figure><p><a href="https://vim.sourceforge.io/"><strong>Vim</strong></a>: Say What? Yeah, Vim it is. Let’s never undermine the power of this cool text editor with unique support for those cool commands to make you work like a boss. It’s notoriously difficult to master initially, but once mastered, there’s no going back. And who said it can’t look pretty!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bmTC0ffo79ky4eTFA1hxqg.png" /><figcaption>Vim</figcaption></figure><h3>JS Frameworks &amp; Libraries</h3><p>Frameworks are a great way to save your time and sweat by providing standard scaffolded structures already cooked for you. In most of the organisations where there are high demand of build and ship kind of products, frameworks fit best. While there are a lot of JS frameworks already, plus more coming up day by day. It might seem overwhelming for a person to start on one of them. The prominent ones being Angular, React, Polymer, Vue, Aurelia, Meteor, Ember. Without favouring anyone of them, I’ll discuss the ones I like the most</p><p><a href="https://facebook.github.io/react/"><strong>React JS</strong></a>: Although a library, not a framework. But immensely popular and with a really good community support, React has been the first choice for UI developers because of the advancements it offers in terms of Universal</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/238/1*kTiNBY21REjyGii966veUQ.png" /><figcaption>ReactJS</figcaption></figure><p>Isomorphic Apps (Server Side Rendering), good support for native apps using React Native and not to mention the speed it offers over the conventional DOM operations exploited by libraries like jQuery. It uses the concept of <a href="https://github.com/Matt-Esch/virtual-dom">Virtual DOM</a> and <a href="https://facebook.github.io/react/docs/reconciliation.html">Smart Diff Algorithm</a> which makes it fast and hence popular. Also, very easy to pick up if you know JS. Only problem is it’s a bit perplexing to setup for beginners since a myriad of boilerplates exist for the same, some using browserify, some using webpack. Also, the folder structure might vary from project to project. Although, there are tools like <a href="https://www.npmjs.com/package/react-cli">react-cli</a> available.</p><p><a href="http://angular.io/"><strong>Angular JS</strong></a>: The framework that revolutionised the way we used to write frontend code introducing the MVVM design pattern into the mix. Backed by Google, Angular 1.x has been really popular ever since it was launched in 2011. It happened in mid 2015, React started to take over the prevalence providing better stuff than Angular. Angular folks in an attempt to be at par with React’s increasing popularity, released Angular 2 last year claiming it to be 5x times faster than Angular 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*C3gmcanRjM1tulvlTlwlaA.png" /><figcaption>Angular 2</figcaption></figure><p>And it looks nothing like Angular 1 cause it uses TypeScript and RxJS too. Due to this, developers fear about it’s learning curve. And yes, having doing a project using it at the time of writing this post, the learning curve is indeed steep. It’s not as easy as pie if you’re completely agnostic towards using any JS frameworks or JS itself before. But after experiencing it, I must say, don’t care about what critics have to murmur about TS, I love it. I think it’s a very nice move by Angular Team to use it for Angular 2 due to the features it offers like type safe code, generics etc. In short, it eliminates a lot of code like this:</p><pre>if(typeof name !== ‘string) throw ‘Name should be string’</pre><p>Simply, specifying the datatypes while declaring variables will do the job.</p><pre>isPristine: boolean = true;</pre><p>Plus, another thing is using an standard cli tool as <a href="https://github.com/angular/angular-cli">Angular CLI</a>, it saves you from the pain of scaffolding and generating the components on the fly.</p><p><a href="https://vuejs.org/"><strong>VueJS</strong></a>: Another new kid on the block that’s setting fire. The Vue folks <a href="https://vuejs.org/v2/guide/comparison.html">claims</a> it to be faster than React and every other framework.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/160/1*UZ8ClPlsziYYRAzhsjA7gQ.png" /><figcaption>VueJS</figcaption></figure><p>Just like React, it uses Virtual DOM. In fact, it uses a more optimised and light weight version of v dom, a fork of <a href="https://github.com/snabbdom/snabbdom">snabbdom</a> that reduces the JS computations. Another good reason to choose it is that unlike React, that introduced JSX, yet another thing for you to learn, Vue uses plain standard HTML templates which are easier to understand for a beginner.</p><pre>&lt;template&gt;</pre><pre>&lt;div class=&quot;list-container&quot;&gt;</pre><pre>&lt;ul v-if=&quot;items.length&quot;&gt;</pre><pre>&lt;li v-for=&quot;item in items&quot;&gt;</pre><pre>{{ item.name }}</pre><pre>&lt;/li&gt;</pre><pre>&lt;/ul&gt;</pre><pre>&lt;p v-else&gt;No items found.&lt;/p&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/template&gt;</pre><p>More goodness comes with the Component Scoped CSS it offers. Since, building web components is always a pain when it comes to styling. If you’re using React, you have to depend on third party tools like Radium. More to that is, it includes challenges like one can’t use Media Queries or pseudo css selector like hover, active etc in them. Vue seems to solve all these challenges well.</p><pre>&lt;style scoped&gt;</pre><pre>@media (min-width: 250px) {</pre><pre>.list-container:hover {</pre><pre>background: orange;</pre><pre>}</pre><pre>}</pre><pre>&lt;/style&gt;</pre><p><a href="https://www.polymer-project.org/1.0/"><strong>Polymer</strong></a>: The Polymer Project is an open source project by the Google team that utilised the full benefits of <a href="https://w3c.github.io/webcomponents/spec/imports/">HTML Imports</a>. It introduced to us the notion of reusable Web Components i.e self contained grouped elements supposed to perform certain task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/269/1*4j481Yy_3_AruLk4WOZ8UA.png" /><figcaption>Polymer</figcaption></figure><p>It’s api consists of a lot of elements like Paper Elements for material components, iron elements (Core elements), gold elements for E Commerce (Credit Card &amp; purchases stuff), Neon elements for animations and effects and a lot more.</p><p>Vue is related closely to Polymer. But</p><blockquote>The biggest difference is that Polymer is built upon the latest Web Components features and requires non-trivial polyfills to work (with degraded performance) in browsers that don’t support those features natively.</blockquote><p>More on this available <a href="https://vuejs.org/v2/guide/comparison.html">here</a>.</p><h3>CSS Preprocessors</h3><p>Writing crude CSS for smaller projects makes sense where we make a main.css or home.css kind of file and include it directly in our index.html, but as your project grows and also with the increasing trend of web components, it becomes necessary to modularise and introduce some programming features like variables declarations, functions or macros (mixins in Sass) etc into it. Css Preprocessors like SASS, LESS, Stylus, Myth solves these problems. My favourite one being SASS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/176/1*ugGlMKtU76HkD1HGF76Cmg.png" /><figcaption>Sass</figcaption></figure><p><a href="http://sass-lang.com/"><strong>SASS</strong></a>: Short for Syntactically Awesome Style Sheets, SASS is indeed awesome. You can declare variables, use imports, create mixins very handy for generating things like vendor prefix css properties, media queries, text truncation and a lot more. You can also use on the fly computation of values for certain css properties. There are two ways or versions to use SASS. SASS itself which is the original syntax that uses indentation for block scoping as.</p><pre>$serif-font-stack: &quot;Georgia&quot;, &quot;Times New Roman&quot;, serif<br>$monospace-font-stack: &quot;Cousin&quot;, &quot;Courier&quot;</pre><pre>body<br>    font: normal 18px/22px $serif-font-stack</pre><pre>pre, code<br>    font: 600 bold 18px/22px $monospace-font-stack</pre><p>The other more popular version is called SCSS, which is similar to native CSS as:</p><pre>$serif-font-stack: &quot;Georgia&quot;, &quot;Times New Roman&quot;, serif;<br>$monospace-font-stack: &quot;Cousin&quot;, &quot;Courier&quot;;</pre><pre>body {<br>    font: normal 18px/22px $serif-font-stack;<br>}</pre><pre>pre, code {<br>    font: 600 bold 18px/22px $monospace-font-stack;<br>}</pre><h3>Template Engines</h3><p>Consider you’re creating a portfolio static website for yourself and you have to create a list of your projects each consisting of a title, a description and maybe some tags. Each project node in html has the similar syntax, only the fields like title, description and tags are dynamic. So, it’d be wiser to create a template and iterate it using a loop construct supplying the dynamic values in each iteration. Although, you can accomplish the same using VanillaJS too, but template engines like <a href="https://mustache.github.io/">Mustache</a>, <a href="https://pugjs.org/api/getting-started.html">Pug</a> (formerly known as Jade), <a href="http://handlebarsjs.com/">Handlebars</a> make it fairly easier for you providing you to write html like syntax with placeholders embedded in them for dynamic values along with the loop constructs too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*osz85GCyLMtSzEL7bjAJfw.png" /><figcaption>Handlebars</figcaption></figure><p>Below is snippet of Handlebars template.</p><pre>&lt;script id=&quot;entry-template&quot; type=&quot;text/x-handlebars-template&quot;&gt;<br>  &lt;div class=&quot;entry&quot;&gt;<br>    &lt;h1&gt;{{title}}&lt;/h1&gt;<br>    &lt;div class=&quot;body&quot;&gt;<br>      {{body}}<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/script&gt;</pre><p>And to compile it passing the data or dynamic values, we can do:</p><pre>var source   = $(&quot;#entry-template&quot;).html();<br>var template = Handlebars.compile(source);</pre><p>All the JS frameworks we discussed above, have their own templating engines built in.</p><h3><a href="http://redux.js.org/">Redux</a></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/236/1*Af6hzg6iwXPGk-qzDxmgQw.png" /><figcaption>Redux</figcaption></figure><p>As the official docs say</p><blockquote>Redux is a predictable state container for JavaScript apps</blockquote><p>Hmm, perplexing for a newbie to understand. Let me explain a bit more about it with a practical example. Redux is nothing but a design pattern in my eyes to manage the “state” of your application. Consider the following snapshot from one of my React app — <a href="http://harp-56f2d.firebaseapp.com/">Harp</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*REZSMImKiNevSdx6woc7qA.png" /><figcaption>Harp — A progressive web app using React + Redux + ImmutableJS</figcaption></figure><p>What can you deduce about the current instantaneous state of the application from the given snapshot? Let me sum it down for you.</p><p>The search text is set to “ed sheeran”</p><p>Selected Artist is set to “Ed Sheeran” which holds information like artist name, genre tags, profile picture, number of followers etc.</p><p>The lower area holds a list of songs of the selected artist.</p><p>Considering the state of the player, the selected song is “Shape of You”, artist name is “Ed Sheeran”, audio is in play state, audio position is around 70%. Volume is set to 3 (although not visible here).</p><p>So, what I’m trying to explain is that the template is same, only on the basis of some criteria which is a route param like artistId in our case, the api call is fetching the details from Spotify API and populating the template with the “<strong>current state</strong>” or simply we can say the “data”. On this state if some event happens say the user seeks the player seek bar to 90%, the current state has to be updated by you by dispatching what is called an <strong>Action </strong>in Redux jargon. It could be any event, triggered by user or by network (Ajax call), player event etc.</p><p>There are <a href="http://redux.js.org/docs/introduction/ThreePrinciples.html">three golden principles</a> of Redux that it follows:</p><ol><li><strong>Single Source of Truth</strong>: Any change in the state throughout the application that happens has to be updated in the state by dispatching an Action. The changes from the state are in turn subscribed by the components to update their content or bindings.</li><li><strong>State is Read Only</strong>: You can’t or should not try to mutate the state directly. The ethical way to do that is by dispatching an action. In response to that action, a function called <strong>Reducer </strong>updates the state.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*N-L1PRC-YjFgq4w-AG0McQ.jpeg" /><figcaption>Redux Data Flow</figcaption></figure><p>3. <strong>Changes are made with pure functions</strong>: The Reducer function we discussed above is a <a href="https://www.wikiwand.com/en/Pure_function"><strong>Pure Function</strong></a>. We read about pure functions in Mathematics, functions like sin(x), cos(x) are pure. We know that the value of sin 30 is going to be 1/2 , no matter what. Given a certain input, it’s output is the same always unlike Impure functions like rand() or printf(). Coming back, the reducer is a function which takes two parameters: Previous State and an Action and returns a completely new state without mutating or changing the previous state since it’s a pure function.</p><p>Redux is a very cool state management library as of now and I highly recommend using it. It’ll save you from cooking spaghetti code and unpredictable errors. Also, debugging will be a breeze with the really awesome dev tools created by community. Here’s one really popular, <a href="https://github.com/gaearon/redux-devtools">redux-devtools</a> with features like Time Travel Debugging. Thanks to <a href="https://github.com/gaearon">Dan Abramov</a>, the creator of Redux himself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YhUOfGhrxzJMRNEKD2-gRw.png" /><figcaption>Redux Dev Tools Snapshot</figcaption></figure><h3><a href="https://facebook.github.io/immutable-js/">ImmutableJS</a></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*eR9adTs9YKuedPVTrwhEcA.png" /><figcaption>ImmutableJS</figcaption></figure><p>Talking in tandem with our discussion on Redux, we noticed a little problem with it. As we mentioned, the reducer is a pure function which takes the previous state and returns an entirely new state object with the changes done for a given action. Now, say your app state tree grows a lot over time. Creating such a huge state tree object every time is not economical memory wise. A solution to this is an attempt by Facebook devs with <a href="https://facebook.github.io/immutable-js/">ImmutableJS</a>. It enforces immutability and function purity in the very first place. It provides constructs like Map, Sets, List with a plethora of methods on them like underscore of lodash for data manipulation.</p><p>Since, our reducers in Redux has to be pure functions, if the state passed is immutable, one can’t even deliberately mutate it ever if we use Immutable.Map for the State being passed. In addition to this, the new change being done to the state doesn’t actually create a new object, instead it gives a reference to the new tree with a leaf attached to it. It’s called <a href="https://www.wikiwand.com/en/Persistent_data_structure">Structural Sharing</a>. Thus, it helps avoiding memory leaks. There’s also another library supporting the same cause called <a href="https://github.com/swannodette/mori">MoriJS</a>.</p><p>A reducer using Immutable construct looks something like this:</p><pre>import { fromJS, Map } from &#39;immutable&#39;;</pre><pre>import ArtistConstants from &#39;./ArtistConstants&#39;;</pre><pre>const initialState = fromJS({<br>    data: {<br>        images: [{}],<br>        genres: []<br>    },<br>    tracks: []<br>});</pre><pre>const ArtistReducer = (state = initialState, action) =&gt; {<br>    switch (action.type) {<br>        case ArtistConstants.SET_ARTIST_DATA:<br>            return state.setIn([&#39;data&#39;], fromJS(action.payload))<br>        case ArtistConstants.SET_ARTIST_TRACKS:<br>            return state.merge(fromJS({<br>                tracks: action.payload<br>            }))<br>        default:<br>            return state;<br>    }<br>};</pre><pre>export default ArtistReducer;</pre><h3><a href="https://github.com/ReactiveX/rxjs">RxJS</a></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*k7yoTsoCbKBHLRs5dFZGgA.png" /><figcaption>RxJS</figcaption></figure><blockquote>An API for asynchronous programming with observable streams</blockquote><p>RxJS is a library or an implementation of Reactive Programming Paradigm which aims at managing the asynchronous behaviours of our application. It treats every event happening in the app as an Asynchronous Data Streams using the Push &amp; Pull pattern, means you can create a source from where you can publish events based on some activity and there’s a sink in which you can subscribe or listen to those events and do some appropriate actions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*n66DxQZKoXqEnRZXbgqBMA.jpeg" /><figcaption>Reactive Programming Principle</figcaption></figure><p>If you are finding it confusing, below is a little but very useful example from one of my apps. So consider, there’s a “buy now” button on your app checkout page. The tester comes to you and reports that if the user taps this button very fast and continuously, say twice or thrice within a matter of seconds, multiple orders get created for that user. So, how can you handle such problem becomes very easy once you get a hold of Rx. You just need to convert the click event of the button into a Rx Stream and use throttle operator. What it does is, within an interval of 1.5 seconds, doesn’t matter how many time the user taps the button, it’ll be counted only as 1. The next event will be triggered only after 1.5 secs. Just what we need to avoid such silly user interaction problems.</p><pre>Rx.Observable.fromEvent(ReactDOM.findDOMNode(this.refs._btn), &#39;click&#39;)<br> .throttle(1500)<br> .subscribe((event) =&gt; {<br>    this.handleBuy(event);<br>})</pre><p>The use of Rx is not only limited to this, there’s another very useful example from the Rx Docs</p><pre>var input = document.getElementById(&#39;input&#39;);<br>var dictionarySuggest = Rx.Observable.fromEvent(input, &#39;keyup&#39;)<br>  .map(() =&gt; input.value)<br>  .filter(text =&gt; !!text)<br>  .distinctUntilChanged()<br>  .throttle(250)<br>  .flatMapLatest(searchWikipedia)<br>  .subscribe(<br>    results =&gt; {<br>      list = [];<br>      list.concat(results.map(createItem));<br>    },<br>    err =&gt; logError(err)<br>  );</pre><p>Say you wanna create a search anything functionality using wikipedia api in your app. Triggering an Ajax call every time with an alphabet typed in the input box using the keyup event would not be a good idea. Also showing the user stale result of the previous call is also not good. RxJS provides us with really useful operators like distinctUntilChanged, throttle, flatMapLatest to cater to all our needs. The above snippet will help you only trigger an Ajax call when the user has typed some input (filter), the input is not similar to previous one (distinctUntilChanged, because arrow keys are also included in keyup event), only show latest results to the user (flatMapLatest) etc.</p><p>We’ve barely scratched the surface of Reactive Programming <a href="https://github.com/Reactive-Extensions/RxJS">here</a>. I recommend reading the full docs here for better understanding. The more you use RxJS in your app, more benefits you can observe.</p><h3>Hot Module Replacement (HMR)</h3><p>One of the coolest thing that has happened is HMR. Ah, no more annoying waiting times when you updated a little thing in your code and the whole app is recompiling and then you have to refresh it in the browser! So, much pain. Isn’t it? If you’re going through the same pangs, say aloha to HMR. Just try it once, and you’ll fall it love with it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q3CBcVvEm_VfbVeyR2QaMw.png" /><figcaption>Hot Module Replacement Diagram</figcaption></figure><blockquote>“Hot Module Replacement” (HMR) is a feature to inject updated modules into the active runtime.</blockquote><p>Only problem is it’s a bit difficult to setup. I’ve used <a href="https://github.com/gaearon/react-hot-loader">react-hot-loader</a> again by Dan Abramov. If you’re facing issues integrating it, use this boilerplate already including all of the stack items we discussed above for a react project. <a href="https://github.com/paramsinghvc/react-boilerplate">https://github.com/paramsinghvc/react-boilerplate</a></p><p>Angular 2 also supports HMR. Here’s an implementation by <a href="https://github.com/AngularClass/angular2-hmr">AngularClass</a>.</p><h3>Task Runners</h3><p>Task Runners are workflow management tools. With all of the above third party tools and libraries we discussed above, we need to compile them to something what our browser or rendering engine understands. For eg, your browser is not going to understand SASS or the code written in TypeScript or ES6 at all. It needs to be compiled. Also, it becomes very critical for you to bundle up your code and ship it to production server by applying Concatenation of files and subsequent Minification by removing comments, name mangling, white space removal, deduplication etc. Usually, we write shell scripts to accomplish such things which might get cumbersome at some point of time. Task Runners like GulpJS, GruntJS not only solves such problems but also provides you with a better management of your build configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/233/1*Cb5-DsSIOE05GPAanfuOtA.png" /><figcaption>GruntJS</figcaption></figure><p><a href="http://gruntjs.com/"><strong>GruntJS</strong></a>: Introduced in 2012, it’s a quite old task runner that seems to have been replaced by Gulp now a days. It used configuration over code in a gruntfile.js included in your project root directory that allowed you use plugins to accomplish all the bric-a-brac tasks of your web app discussed above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/93/1*15XyDlIOVia42hC14pw_0A.png" /><figcaption>GulpJS</figcaption></figure><p><a href="http://gulpjs.com/"><strong>GulpJS</strong></a>: A widely used task runner that favours code over configuration using NodeJS kind of streams and modules. It provides almost all kind of functionality with its wide support of plugins all over npm. You name it and you’ll get it. Be it, css auto-prefixer, angular 1 dependency array injection, sass to css etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*eXdX_sQKzEZomscFgpEwRQ.png" /><figcaption>Webpack 2</figcaption></figure><p><a href="http://webpack.github.io/"><strong>Webpack</strong></a>: It’s exactly a task runner. Instead, it a module bundler. But in many cases it can be used as a substitute for task runners. It goes well with React Project, very easy to configure with again a very good support for plugins. With the release of Webpack 2 lately, there are features like Tree Shaking, Lazy Loading introduced for better optimisation of your app code for production environment.</p><p>There are several others like JSPM, Rollup, SystemJS etc that are worth checking out.</p><h3>Conclusion</h3><p>The web platform is really dynamic. One day or the other, there are tons of libraries and tools being produced by the community. It’s impractical to use all of them obviously. But the technologies we discussed above are some of the popular ones and widely accepted by the developers. Also, these are the bits and pieces I’ve found from my experience with various frameworks and libraries. It’s nothing like you can’t use TypeScript or RxJS in React project. And if you haven’t used any of these, you MUST consider using it in your next project. Cause, its not only good for your users but also for your development workflow. As they say “Necessity is the mother of invention”. These cool technologies have been invented for people like us and by us. So, we should brace ’em and start using them happily.</p><p>Hope you enjoyed reading it, kindly leave your comments and feedback.</p><p>Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64194d9a48" width="1" height="1" alt=""><hr><p><a href="https://medium.com/paramsingh-66174/modern-web-development-practices-64194d9a48">Modern Web Development &amp; Practices</a> was originally published in <a href="https://medium.com/paramsingh-66174">paramsingh_66174</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PugJS Primer for your next Angular 4 Project]]></title>
            <link>https://medium.com/paramsingh-66174/pugjs-primer-for-your-next-angular-4-project-409ee6696fad?source=rss----b94f230112f1---4</link>
            <guid isPermaLink="false">https://medium.com/p/409ee6696fad</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[angular-cli]]></category>
            <category><![CDATA[template]]></category>
            <category><![CDATA[pug]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Param Singh]]></dc:creator>
            <pubDate>Sun, 06 Aug 2017 11:23:02 GMT</pubDate>
            <atom:updated>2017-08-05T19:07:02.397Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qSm2gfEgzqtTpEjRNAHyUQ.jpeg" /></figure><p>Because writing markup in plain HTML is too mainstream and toilsome. Here’s to the introduction of really cool templating engine called “Pug”, formerly named as Jade. Happened to use it once couple of years back in my Node project, I so wanted to use it in my mundane projects. I adore it not only for its succinctness but also for it’s cool programming like features that saves a lot of development time by ruling out monotonous typing. After all, who likes pressing Shift + Angular brackets every now and then.</p><h3>How does it look like?</h3><p>It looks like indentation adjusted elements to mark their hierarchical relationships. If you have worked on Python programming ever, you’ll feel at home.</p><pre>section.container<br>  h1 Hola Mundo<br>  p(align=&quot;center&quot;) Hello from the other side.</pre><p>As python doesn’t use braces like most other languages out there to distinguish between its lexical constructs (functions etc), same way Pug doesn’t use starting and closing tags like html to segregate the elements in markup. This gives us another advantage by enforcing good formatting from the beginning.</p><h3>Integration with Angular CLI generated project</h3><p>Unfortunately, Angular CLI doesn’t provide support for pug out of the box. So, you’ll have to muscle a little extra to make it work in your Angular project.</p><p>After you generate an Angular 2+ project like this</p><pre>ng new project</pre><p>You’ll have to take out the webpack configuration from it to gain more control over your project build mechanics. You do so by doing</p><pre>ng eject</pre><p>It’ll take out the webpack.config.js in the root directory of your project.</p><p>Now that you have ejected webpack config out, you can very easily register a rule to intercept .pug files and a loader to compile them to html at build time.</p><p>Just look for the blow section and make an entry there</p><pre>&quot;module&quot;: {</pre><pre>  &quot;rules&quot;: [</pre><pre>    {</pre><pre>      &quot;test&quot;: /\.pug$/,</pre><pre>      &quot;loader&quot;: [&#39;raw-loader&#39;, &#39;pug-html-loader&#39;]</pre><pre>    }</pre><pre>    ...</pre><p>For it to work, you have to install some modules from npm.</p><pre>npm i -D pug pug-html-loader</pre><p>And you’re ready to go.</p><p>Create a file anywhere in your src folder with .pug extension while changing it in the ts file too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*dKlieU8NPRNiyjqqhpqO4A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*X3E6fyFTTDi8mtU9FHlQWQ.png" /></figure><p>Run project with npm start and relish the conciseness of Pug.</p><h3>Points to Ponder</h3><ol><li>While generating a new component using ng generate command. Don’t forget to change the extension and it’s entry in the ts file manually as Angular CLI will generate .html file for you.</li><li>While using template reference variables in Angular 2+, make sure you wrap it in quotes like this and provide it an empty value like this</li></ol><pre>input(type=&quot;file&quot;, &#39;#inputFileEl&#39;=&quot;&quot;, multiple, (change)=&quot;filesAdded($event)&quot;)</pre><h3>Conclusion</h3><p>So, what are you waiting for? Go ahead and lunge onto using Pug with not only your Angular project but any project in general. I’m sure once you get cozy with it, you’ll despise working on those html verbose semantics at all. It might be a little difficult or an extra work to orchestrate it into your existing projects initially but mind that it’s a one time configuration and you’ll be sorted for life. So, don’t let any second thoughts prevail your cerebral territory and start using it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*3VhF1ch7HJsPC7RFXy3bhA.jpeg" /></figure><p>Happy Coding! Woof!! 🐶</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=409ee6696fad" width="1" height="1" alt=""><hr><p><a href="https://medium.com/paramsingh-66174/pugjs-primer-for-your-next-angular-4-project-409ee6696fad">PugJS Primer for your next Angular 4 Project</a> was originally published in <a href="https://medium.com/paramsingh-66174">paramsingh_66174</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Catalysing your Angular 4 app Performance]]></title>
            <link>https://medium.com/paramsingh-66174/catalysing-your-angular-4-app-performance-9211979075f6?source=rss----b94f230112f1---4</link>
            <guid isPermaLink="false">https://medium.com/p/9211979075f6</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular2]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Param Singh]]></dc:creator>
            <pubDate>Sun, 06 Aug 2017 11:22:41 GMT</pubDate>
            <atom:updated>2017-07-07T15:19:29.639Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qz-08Mri7WI-V_CEjxTl5w.jpeg" /></figure><p>As important it is to finish your project on time, the performance of the developed product matters a lot too. Further, the stakes are high when a lot of users are dependent on your piece of development. With great power n freedom comes great responsibility. While the JS world has provided us with voluminous libraries and frameworks, its the responsibility of the developer ultimately to make the most out of it and match up with the business needs while providing a slick user interface experience to its users.</p><p>Similar has been my experience and learning. Delivering a colossal product with sated customers has never been an easy job. But over time, we have thrived to meet our users needs at par with other apps in the market using the cutting edge front-end technologies. Some of which are Angular 2, Redux, ImmutableJS, webpack etc. So, below are some caveats that I have learnt so far for revving up your Angular app and would like to share with you.</p><h3>Keep track of the loops</h3><p>Any app you’ll take will definitely embody a lot of *ngFor loops. So, just target these loops in the very first place because any silly booboo you’re gonna make in any of the repeating entity or component will cost you a good toll on performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*g21zN9FVPxCxbLNmIPKhfg.jpeg" /></figure><p>A very prime way to optimise your loops is to keep track of *ngFor them using the <a href="https://angular.io/guide/structural-directives#microsyntax">trackBy</a> property.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13ca3fc6b1717b7166d3f4f95b843818/href">https://medium.com/media/13ca3fc6b1717b7166d3f4f95b843818/href</a></iframe><p>And then you can create a trackBy function in your ts file like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b36821289120f8f2b09284f1a11705e/href">https://medium.com/media/0b36821289120f8f2b09284f1a11705e/href</a></iframe><p>So, you can either track your song list data through the indices or through a primary key in your data model like a usual id. Specifying trackBy in Angular loops helps it to identify the rows being added or removed when the model/data of the application changes. Since, DOM operations are quite expensive, it would be wise to not have Angular create all the siblings nodes in a collection if a single node is being added, removed or modified. Tracking mechanism helps Angular avoid such a mishap. If you’re from a ReactJS background, it’s synonymous to <a href="https://facebook.github.io/react/docs/lists-and-keys.html">keys</a>.</p><h3>Go Fully Immutable</h3><p>To understand this point, we need to understand what makes frameworks slow. Can you guess?? Yes, it the re-renders. In the declarative style frameworks like Angular wherein you bind the dynamic model values in your template like {{valueName}}, the framework has to do a lot of work every time the value of a bound variable changes from anywhere in the code. And as your app grows, you can imagine the number of such re-renders due to such bindings! So, does that mean we shouldn’t use bindings. No, that’s an absurd suggestion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*uwH41JAdHbEqNHFyjJVQcQ.jpeg" /><figcaption>The Domino Effect</figcaption></figure><p>Instead, lets peep into how Change Detection in Angular works. Discussing it would deviate us from our current discussion. So, I leave it to you to understand how it works from this fabulous explanation by <a href="https://angular-2-training-book.rangle.io/handout/change-detection/">rangle</a> folks.</p><p>The crux of the above reference turns out that we should supply Immutable inputs to our components and use the ChangeDetectionStrategy.OnPush</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c6eb6821623539af51286d5b01f92db/href">https://medium.com/media/0c6eb6821623539af51286d5b01f92db/href</a></iframe><p>Hence, except from the primitive datatype input properties, always resort to using Immutable Inputs. In fact, all the data communication in your app should happen using Immutable Data Structures. One way you can enforce Immutability is by using this Facebook’s library called <a href="https://facebook.github.io/immutable-js/">ImmutableJS</a>. It’ll reduce the number of re-renders and you may end up improving your app performance smartly.</p><h3>Be vigilant of the Scroll Handlers</h3><p>While talking about the app performance or slick User Interfaces, one of the key factors that determines a good user experience is the Scroll Performance. Nothing’s more frustrating than a jerky scroll experience. So, have you ever pondered why that jerk happen after all? You need to determine the cause of the problem for reaching it’s solution. Here’s a nice <a href="https://www.html5rocks.com/en/tutorials/speed/scrolling/">article</a> by Paul Lewis you can refer to.</p><p>So, in most of the cases scroll performance suffers due to some expensive scroll event listeners. Since scroll event is something that going to be triggered very frequently and if you’re doing some heavy DOM operation inside a scroll handler, definitely you’re gonna experience a nasty judder while scrolling your page. You can try it out by placing some DOM computation logic of a heavy or dynamic element inside your scroll handlers like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/297cd82bddb68eafcbb235a77afebf4a/href">https://medium.com/media/297cd82bddb68eafcbb235a77afebf4a/href</a></iframe><p>In my case, I have encountered such problems in places where I were to implement Infinite Scroll i.e when I have to make an api call automatically to load next set of data in a list when the user has reached the bottom of the page.</p><p>I have an infinite Scroll Directive in my Angular app that applies a scroll event handler to the given element like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf5ce285a6aff06126bd358d310822a2/href">https://medium.com/media/bf5ce285a6aff06126bd358d310822a2/href</a></iframe><p>which I’m using in a scrollable container div like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/22d6dc2641229aca834e2d5227db1365/href">https://medium.com/media/22d6dc2641229aca834e2d5227db1365/href</a></iframe><p>The problem is that on every little scroll, the logic for “reachedBottom?” is being checked. Though, in this example it’s still fine but consider the case you want to use function like getBoundingClientRect() or getComputedStyle. You’ll observe serious effect on your scroll perf.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cy0mHHZ6ZSY7N_j46Mtnpw.png" /><figcaption>Longer frames causing Jank</figcaption></figure><p>Does that mean we can’t use such logic inside our handlers? Well, you can if you can do it smartly by taking a pinch of RxJS ingredient as follows.</p><p>If there’s a way to trigger the scroll handler only when like the user has paused for a few milliseconds, we’re set. And yes, RxJS is a panacea offering an operator called <a href="https://www.learnrxjs.io/operators/filtering/debouncetime.html">debounceTime</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oN6g9OCkxzxvGLKOO7Cxog.png" /></figure><p>What it does basically is it doesn’t triggers the event at all while the event is happening over time but when there’s a pause of more than the specified debounceTime like 20ms in the above case, it triggers the event. So, you see the user only pauses for some activity to happen and 20 ms pause is quite fast, so there won’t be any negative effects on your current experience. Instead, the experience would improve because earlier when the same event was happening for every little scroll sliding, now it’s happening only in that pause duration.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/220331ed95a6d1eedc3b728e375157fb/href">https://medium.com/media/220331ed95a6d1eedc3b728e375157fb/href</a></iframe><p>Problem solved 😀! Let’s audit the performance timeline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*FMhYjMzItWhuZDYSbtyG5g.png" /><figcaption>Chrome Performance Timline — Still long frames</figcaption></figure><p>Wait what?? 😵 Even after applying debounce, still there are those nasty red frames causing jank! And the cause seems to be lot of scripting as evident from those canary sand dunes.</p><p>Meh! What’s causing so much scripting now? Let’s dig more deep into these dunes to figure out the cause.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GMK_bTX7c13KHEMBRhXDyA.png" /><figcaption>Flame Chart of a single scripting frame</figcaption></figure><p>Eureka! It’s the Angular 2 Change Detection. But why it’s being called on every Scroll Event. We aren’t making any change in any local variable until there’s a pause. Are we?</p><p>To reason about this, we need to understand how and when change detection triggers and trickles down the Change detection process in the whole Angular’s component tree. Here’s a beautiful <a href="https://blog.thoughtram.io/angular/2016/02/01/zones-in-angular-2.html">explanation</a> on this.</p><p>As it says,</p><blockquote>Zones monkey-patches global asynchronous operations such as setTimeout() and addEventListener(), which is why Angular can easily find out, when to update the DOM.</blockquote><p>Did you get the clue now? Actually, when we did this:</p><pre>Observable.fromEvent(this.el.nativeElement, &#39;scroll&#39;)</pre><p>It internally added a scroll event listener and somehow zone js had been triggering the change detection cycle on every scroll event.</p><p>So, we found the culprit. Now, what’s the solution? Stick around for a little longer.</p><p>NgZone service of Angular which is a wrapper around ZoneJS provides us with a method <a href="https://angular.io/api/core/NgZone#runOutsideAngular">runOutsideAngular</a>.</p><blockquote>It allows you to escape Angular’s zone and do work that doesn’t trigger Angular change-detection or is subject to Angular’s error handling.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aef1019812291860e0c3768213702a2a/href">https://medium.com/media/aef1019812291860e0c3768213702a2a/href</a></iframe><p>So, after wrapping up my handler inside the NgZone runOutsideAngular, my perf timeline looks something like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*TAhAc9pMEPlvCHOAmxY0Ig.png" /><figcaption>Chrome Performance Timeline: After runOutsideAngular</figcaption></figure><p>Aloha Greenery! 🍃😍 Finally, now we can kiss those nasty red frames a goodbye. You know what it means, a blazing fast silky smooth scrolling experience.</p><h3>Spruce up the “Dirt”</h3><p>In our ts or js files we end up subscribing or observing to Observables or Event Listeners but often forget to unsubscribe ’em from there which not only gifts us with unexpected side effects called bugs but also eats up a good share in performance specially if that component is being repeated in loop, you’re screwed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*GDUGbu15xB8oQwEpWN-BwA.jpeg" /></figure><p>Hence, as I said with great freedom comes great responsibility, you must always clean up the subscriptions, timers, event listeners in the destructor which happens to be the ngOnDestroy lifecycle hook of an Angular 2 app component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/09def19458fa1583d873e0a9f2d3d6f8/href">https://medium.com/media/09def19458fa1583d873e0a9f2d3d6f8/href</a></iframe><h3>Fend off too much piping</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*WAU5ygdf0TIsSK1-xMimxg.jpeg" /></figure><p>Avoid making recurring use of async pipe in your Angular Components. What I mean by that is avoid something like doing this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/767d5450a79de07b5e618361fa83f132/href">https://medium.com/media/767d5450a79de07b5e618361fa83f132/href</a></iframe><p>As you can see from the above example (data | async) is being used so rampantly. Now, mind this thing that as many async pipes you’re gonna write, there’ll be that number of observable subscriptions too which means more number of handlers to process anytime a single change happens. So, avoid doing such things. If you find yourself in such a scenario, you can and should create a child component; a dumb or stateless component if I say in Redux jargon, and pass around the data as an immutable input property after async piping it in there.</p><h3>Conclusion</h3><p>There are a lot of other reasons why your web app could be sluggish. This article just lists the causes and their solutions if you app is built using Angular 2 or above. In some cases the load time of the app could be high due to a longer CRP (Critical Rendering Path) or it could be poor programming practices like ignoring the above mentioned nook and corners. So, now you can go ahead and at least optimise the latter part causing your app to impede the user experience or maybe dwindling number of users. While working on a small project, it’s fine to overlook these things but for larger projects I highly recommend employing these practices out for a nimble user experience.</p><p>Thank You! Happy Coding! 😎</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9211979075f6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/paramsingh-66174/catalysing-your-angular-4-app-performance-9211979075f6">Catalysing your Angular 4 app Performance</a> was originally published in <a href="https://medium.com/paramsingh-66174">paramsingh_66174</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>