<?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[jsdownunder - Medium]]></title>
        <description><![CDATA[Pragmatic js dev - Medium]]></description>
        <link>https://medium.com/jsdownunder?source=rss----b402dfdac7eb---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>jsdownunder - Medium</title>
            <link>https://medium.com/jsdownunder?source=rss----b402dfdac7eb---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 17:05:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/jsdownunder" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Cloud Functions Emulator]]></title>
            <link>https://medium.com/jsdownunder/cloud-functions-emulator-cdc5f486ee77?source=rss----b402dfdac7eb---4</link>
            <guid isPermaLink="false">https://medium.com/p/cdc5f486ee77</guid>
            <category><![CDATA[google]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[function]]></category>
            <category><![CDATA[debug]]></category>
            <category><![CDATA[emulator]]></category>
            <dc:creator><![CDATA[Yusinto Ngadiman]]></dc:creator>
            <pubDate>Fri, 13 Apr 2018 11:28:05 GMT</pubDate>
            <atom:updated>2018-04-13T11:37:00.886Z</atom:updated>
            <content:encoded><![CDATA[<p>Gettin jiggy with Google’s faas</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aOLfSxvRn-zPupXIfZmFMg.png" /></figure><p>Cloud functions are cool because now you just write code instead of worrying about deploying that code. Google has an emulator which lets you write your function, run it locally, repl the hell out of it, and then and only then when you are finished, deploy it! Let’s check it out.</p><h4>1. Install functions emulator</h4><pre>yarn global add @google-cloud/functions-emulator</pre><p>After installation is complete, start the emulator:</p><pre>functions start</pre><h4>2. Write your code</h4><p>Create a temp dir, cd into it and create a single file called index.js containing your code. If you are lazy you can just <a href="https://github.com/yusinto/functions-emulator-demo">git checkout my demo repo</a>.</p><pre>mkdir functions-emulator-demo &amp;&amp; cd functions-emulator-demo</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/36203f98a987f5ebd1044783b8de276e/href">https://medium.com/media/36203f98a987f5ebd1044783b8de276e/href</a></iframe><p>Some notes:</p><ul><li>By default the emulator looks for an index.js file in the current working directory. You can specify a different directory by using the <strong>— local-path </strong>option.</li><li>Ensure your module.exports refers to an object keyed with your function names.</li></ul><h4>3. Deploy your code to the emulator and run</h4><pre>functions deploy greet --trigger-http</pre><p>Then run your function:</p><pre>functions call greet</pre><h3>Useful Tips</h3><h4>Tip #1: See console logs</h4><pre>functions logs read</pre><h4>Tip 2: Debug using inspector</h4><p>You can step through your functions code in many ways, but I’ll show you how to use the chrome devtools here. First, you need to run your function in inspection mode:</p><pre>functions inspect greet</pre><p>Then open chrome, type chrome://inspect and click on the inspect link on your target. It’s easier to visually demo this, so check out the video below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fknb8UK4RGN8%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dknb8UK4RGN8&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fknb8UK4RGN8%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f778b7512b2f29c852797fc4813a2a12/href">https://medium.com/media/f778b7512b2f29c852797fc4813a2a12/href</a></iframe><h3>Conclusion</h3><p>Google cloud functions emulator kicks ass! Happy coding.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cdc5f486ee77" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jsdownunder/cloud-functions-emulator-cdc5f486ee77">Cloud Functions Emulator</a> was originally published in <a href="https://medium.com/jsdownunder">jsdownunder</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rollup vs Webpack (JavaScript bundling in 2018)]]></title>
            <link>https://medium.com/jsdownunder/rollup-vs-webpack-javascript-bundling-in-2018-b35758a2268?source=rss----b402dfdac7eb---4</link>
            <guid isPermaLink="false">https://medium.com/p/b35758a2268</guid>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[parcel]]></category>
            <category><![CDATA[rollup]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[bundling]]></category>
            <dc:creator><![CDATA[Luke Boyle]]></dc:creator>
            <pubDate>Thu, 22 Feb 2018 04:11:08 GMT</pubDate>
            <atom:updated>2018-02-22T04:11:07.932Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2IGjvDrmofi7h9j5fPGvPw.png" /></figure><p>Although tooling standards have begun to stabilise in JavaScript land, there’s still a bit of confusion around the right tool for the job. This is a somewhat detailed comparison between Rollup and Webpack. Let’s start by comparing their respective configuration files.</p><h3>Configuration</h3><h4>rollup.config.js</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3003da6731d80e3904be774f7bbb340/href">https://medium.com/media/f3003da6731d80e3904be774f7bbb340/href</a></iframe><h4>webpack.config.js</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f941bd1ffaced28f93f553028235d29/href">https://medium.com/media/4f941bd1ffaced28f93f553028235d29/href</a></iframe><p>Quick differences to note:</p><p>Rollup has node polyfills for import/export, whereas webpack doesn’t</p><p>Rollup has support for relative paths, whereas webpack does not, so we either use path.resolve or path.join</p><p>Rollup requires you have modules set to false on es2015 presets, because it will process modules as ES2015 if it can and do scope hoisting magic before transpiling the module.</p><p>Let’s take a very simple example:</p><h4>some-file.js</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9850bc01cf934efd932a9ee76ee07ee/href">https://medium.com/media/a9850bc01cf934efd932a9ee76ee07ee/href</a></iframe><h4>index.js</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5db269c07b451d27abfee4caa056d00e/href">https://medium.com/media/5db269c07b451d27abfee4caa056d00e/href</a></iframe><p>What would you expect the output of this be?</p><p>This is arguably where Rollup shines. For simpler modules, it returns a very efficiently transformed, minimal bundle, whereas Webpack has a lot of magic™ included in the bundle.</p><h4>bundle.rollup.js — ~245 bytes</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e128077f29f94287e99b7d46d3805d33/href">https://medium.com/media/e128077f29f94287e99b7d46d3805d33/href</a></iframe><h4>bundle.webpack.js — ~4108 bytes</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3d761fae007a7483e2ed7df271eed0d/href">https://medium.com/media/f3d761fae007a7483e2ed7df271eed0d/href</a></iframe><p>In the Webpack bundle, the actual imports occur on around line ~100. If you navigate to this point, you will see that the actual module code is <strong>mostly </strong>the same (below), with the biggest difference being that in the Webpack bundle, each module is wrapped in a function which can be internally invoked. This is why Webpack bundles are considered to be ‘safer’ for larger/more complex applications.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/95c08f587cff426ff98701ba4132a1a0/href">https://medium.com/media/95c08f587cff426ff98701ba4132a1a0/href</a></iframe><p>A lot of the mess is removed in production mode builds and the bundle size.</p><p>So, how do you tell which one is right for you? In recent history, the conventional wisdom has been:</p><blockquote><strong><em>“Use webpack for apps, and Rollup for libraries”</em></strong></blockquote><p>However, it’s becoming more difficult to justify this as a rule. Webpack enhancements have really levelled the playing field in terms of general bundling efficiency, and Rollup recently added <a href="https://medium.com/rollup/rollup-now-has-code-splitting-and-we-need-your-help-46defd901c82">code splitting</a> (the major lacking features between the two).</p><p>To make a real life parallel, I’d compare this bundler battle to the product design theory called the “Kano model”. The Kano model essentially states that “over time, delightful innovation becomes another basic need”.</p><p>Take for example the arrow on the fuel gauge of a car to indicate which side to face the fuel pump (figure 1). When the idea was conceived, it was considered to be a great innovation, however, now it is simply an expectation amongst users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/0*rrQDKg7mEK5ty-a_." /><figcaption>Fig 1: Fuel cap side indicator</figcaption></figure><p>To see the real differentiating features, we have to go back to the wild west of 2016.</p><h3>Rollup (circa 2016)</h3><h4>Pros:</h4><ul><li>Tree shaking (live code inclusion / dead code elimination)</li><li>esnext:main entry in package.json to import es2015+ (renamed to ‘module’)</li><li>Scope hoisting</li><li>Simple API</li></ul><h4>Cons:</h4><ul><li>Limited support for alternative file type loading (css, images etc)</li><li>No code splitting</li></ul><h3>Webpack (circa 2016)</h3><h4>Pros:</h4><ul><li>Advanced support for CSS/HTML/image loading</li><li>Code splitting</li><li>Hot module replacement for super fast dev builds</li></ul><h4>Cons:</h4><ul><li>No tree shaking</li><li>No Scope hoisting</li><li>No native support for ES2015+ modules</li><li>Complicated API</li></ul><p>A lot has changed since then (the above is not an exhaustive list, and both of the libraries have additional pros and cons I couldn’t possibly list), and both libraries have taken cues from one another. The community surrounding both libraries has also grown which has helped accelerate the implementation of novel features.</p><h3>Rollup (now) — What’s changed?</h3><ul><li>Rich ecosystem of plugins for file loading/dev servers</li><li>Code splitting (Added 8th of Feb 2018 after a 2 year wait! 🎉🎉)</li></ul><h3>Webpack (now) — What’s changed?</h3><ul><li>Tree shaking &amp; ES2015+ module support (Added in Webpack 2)</li><li>Scope hoisting (Added in Webpack 3)</li><li>Support for esnext:main / module</li></ul><p>In my opinion, you should still probably prefer Rollup for libraries, but the option of using Rollup for large apps is much more realistic now. One thing’s for sure, both Webpack and Rollup are here to stay. I’d say the main reason for the staying power of these two libraries is the amazing internal teams and the unending effort they put into maintaining them and answering issues and StackOverflow questions.</p><p>For a more detailed comparison of the internals of the two libraries, Rich Harris (creator of Rollup) has a great writeup <a href="https://medium.com/webpack/webpack-and-rollup-the-same-but-different-a41ad427058c">here</a>.</p><h3>BONUS: A challenger approaches</h3><p><a href="https://parceljs.org/">Parcel</a> is a new and interesting bundler that has many of the same features as Rollup and Webpack (e.g. code splitting and asset loading), but the big feature it’s touting is a zero-configuration get up and go solution for bundling. If you were around in the community in 2015, you’d remember the infamous blog post <a href="https://medium.com/@ericclemmons/javascript-fatigue-48d4011b6fc4">“JavaScript Fatigue”</a>. One of the points the author makes is our tooling was just a mess, and it was. The world hadn’t decided which tools we should be using so most of my projects were a mixture of Gulp, browserify (with babelify) and getting started was never easy.</p><p>With Parcel, the selling point is that you have an index.html file which points to a JavaScript entry, and you can just run parcel index.html and have a fancy dev server running in moments. It also brags that it has blistering fast bundle speeds (though their comparison table omits a Rollup comparison, so I can only assume they are similar).</p><p>If Parcel proves to have the staying power as Webpack/Rollup, I’m sure we’ll see many of the zero configuration features bubble to the surface in those libraries.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b35758a2268" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jsdownunder/rollup-vs-webpack-javascript-bundling-in-2018-b35758a2268">Rollup vs Webpack (JavaScript bundling in 2018)</a> was originally published in <a href="https://medium.com/jsdownunder">jsdownunder</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimising Web Page: A Simple Step with intersection observer]]></title>
            <link>https://medium.com/jsdownunder/optimising-web-page-a-simple-step-66f7f4ba417c?source=rss----b402dfdac7eb---4</link>
            <guid isPermaLink="false">https://medium.com/p/66f7f4ba417c</guid>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ux]]></category>
            <dc:creator><![CDATA[Bill Luo]]></dc:creator>
            <pubDate>Mon, 05 Feb 2018 01:19:11 GMT</pubDate>
            <atom:updated>2018-08-04T07:13:23.778Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kVzLb0ixuHS9n8zyivmeeA.png" /></figure><p>Single page applications (SPA) has become increasingly mainstream. Thanks to those brilliant Javascript frameworks for making the web application greater and more advanced 👏🏼.</p><p>Right now, however, optimisation of web page performance is critical. This is because, the responsiveness of a page significantly impacts whether a customer will remain on a particular site or not.</p><p>Over the past few weeks, our team has been working hard to improve our website performance. Those beautiful but large images on our pages really slow down the page load and delay the meaningful paint time. So we thought of easily lazy loading them with a placeholder to remediate this problem.</p><p>The web indeed provides numerous solutions for lazy load images. But they do not support responsive images, placeholders with animation out of box, and allowing the specification of an image distance threshold to be met before triggering the load. Hence, we decided to tackle this problem and contribute to the React community. ✍️ I would like to thanks <a href="https://medium.com/u/3c95cbc72757">Yusinto Ngadiman</a> and <a href="https://medium.com/u/ec9acadcbea7">Will Po</a> for their wonderful efforts in contributing 🎩.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*J4lLfpPda5jdFOkEcnZTyQ.png" /></figure><p>Introducing <a href="https://github.com/bluebill1049/react-simple-img">React Simple Img</a>: A React component library makes images load on demand and super simple to set up with placeholders and animation. Here is a quick example code on how it works 😘.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ddfc778f11c974bba4e87eb2bdb3d8a/href">https://medium.com/media/5ddfc778f11c974bba4e87eb2bdb3d8a/href</a></iframe><p>You only need to run the initSimpleImg() once at your app or client level and your entire app’s &lt;SimpleImg /&gt; will be lazy loaded with animation 💥</p><p>This is what the placeholder part of <a href="https://github.com/bluebill1049/react-simple-img">react simple img</a> achieves:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rMNR49qQA76tx9JzbI6JeA.png" /><figcaption>without (left) and with react simple img (right)</figcaption></figure><p>Super simple right!!</p><p>We now get a much faster meaningful paint time, which happens before the image is fully loaded even with a slow network connection. All images are lazy loaded with placeholders and animation. The page looks even more beautiful 👏👏👏</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*YZu4XD896bPrEcHehyYXkw.gif" /><figcaption>Web page under network throttle</figcaption></figure><p>So, if you looking for a way to optimise your web page, why not give <a href="https://github.com/bluebill1049/react-simple-img">React Simple Img</a> a quick try! If you find it useful leave me a star on the <a href="https://github.com/bluebill1049/react-simple-img">GitHub</a>. It would definitely make my day. ❤️❤️❤️ Also, please feel free to leave question in the comment section below too.</p><p>Finally, I really appreciate for reading the blog. I hope you will find it useful. Let’s all make our web apps a better place to give a more desirable experience to our customers!</p><p><em>Thanks </em><a href="https://medium.com/u/ec9acadcbea7"><em>Will Po</em></a><em> and </em><a href="https://medium.com/u/7b503bc01277"><em>Zahid Sumon</em></a><em> for reviewing the blog article 👍</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=66f7f4ba417c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jsdownunder/optimising-web-page-a-simple-step-66f7f4ba417c">Optimising Web Page: A Simple Step with intersection observer</a> was originally published in <a href="https://medium.com/jsdownunder">jsdownunder</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Body scroll lock — making it work with everything]]></title>
            <link>https://medium.com/jsdownunder/locking-body-scroll-for-all-devices-22def9615177?source=rss----b402dfdac7eb---4</link>
            <guid isPermaLink="false">https://medium.com/p/22def9615177</guid>
            <category><![CDATA[body-scroll]]></category>
            <category><![CDATA[modal]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-scroll-lock]]></category>
            <dc:creator><![CDATA[Will Po]]></dc:creator>
            <pubDate>Wed, 24 Jan 2018 06:19:38 GMT</pubDate>
            <atom:updated>2018-02-14T21:07:28.948Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XAi1FRsBgjsXhUSm4GW0AA.jpeg" /></figure><p>Have a google of how people lock the body scroll and you’ll come across a few solutions to accomplish this. The basic use case is:</p><ol><li>Enable some targetElement to appear above the body with position: absolute.</li><li>After it appears, use some solution to disable body scrolling so scrolling within the targetElement doesn’t scroll the body content.</li></ol><p>Here are the likely solutions you’ll come across:</p><h3>1. CSS Overflow</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a979324e97b998c9d9141b7112668023/href">https://medium.com/media/a979324e97b998c9d9141b7112668023/href</a></iframe><p>This approach works for desktop browsers, and mobile Android. However, it fails for mobile iOS (phone and tablets). OK, let’s try approach <strong>#2</strong>.</p><h3>2. Prevent Default</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3f78cfa11636bc9f98453704629b43f/href">https://medium.com/media/e3f78cfa11636bc9f98453704629b43f/href</a></iframe><p>Great solution — scrolling is blocked! But it also blocks scrolling inside the targetElement. If content in the targetElement has height exceeding the element’s set height, you will want to have it scroll!!!!!</p><h3>3. Position Fixed</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0734d88b1eb270a7f7bd10ecc803afb/href">https://medium.com/media/a0734d88b1eb270a7f7bd10ecc803afb/href</a></iframe><p>If you make the body position: fixed, the body will scroll to the top thus losing the body’s original scroll position. Not ideal UX!</p><h3>Proposed Solution — body-scroll-lock</h3><blockquote>Body scroll locking that just works with everything 😏</blockquote><p>Since all devices except iOS respect the overflow: hidden on the html/bodyelements, we can use this approach for these devices.</p><p>For iOS — we check if targetElement has been scrolled to the bottom or top. If it has, then apply the e.preventDefault() solution. Some Javascript is needed to determine this.</p><p>The logic to achieve the proposed solution can be found <a href="https://github.com/willmcpo/body-scroll-lock/blob/master/src/bodyScrollLock.js"><strong>here</strong></a>.</p><p>For convenience, the solution can be downloaded as an NPM package<strong> </strong><a href="https://www.npmjs.com/package/body-scroll-lock"><strong>body-scroll-lock</strong></a><strong> </strong>and used in projects using vanilla JS or frameworks such as React.</p><p>(btw, if you found the <a href="https://www.npmjs.com/package/body-scroll-lock"><strong>body-scroll-lock</strong></a><strong> </strong>package useful, please star the <a href="https://github.com/willmcpo/body-scroll-lock"><strong>GitHub repo</strong></a> to help others solve their body scroll locking issues more easily!).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22def9615177" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jsdownunder/locking-body-scroll-for-all-devices-22def9615177">Body scroll lock — making it work with everything</a> was originally published in <a href="https://medium.com/jsdownunder">jsdownunder</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A tale of three Graphql clients]]></title>
            <link>https://medium.com/jsdownunder/a-tale-of-three-graphql-clients-6c2c29a095a5?source=rss----b402dfdac7eb---4</link>
            <guid isPermaLink="false">https://medium.com/p/6c2c29a095a5</guid>
            <category><![CDATA[graphcool]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[relayjs]]></category>
            <category><![CDATA[apollo]]></category>
            <dc:creator><![CDATA[Yusinto Ngadiman]]></dc:creator>
            <pubDate>Tue, 03 Oct 2017 03:56:43 GMT</pubDate>
            <atom:updated>2017-10-03T03:56:42.893Z</atom:updated>
            <content:encoded><![CDATA[<p>One project. Three Graphql clients.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y_7n5EwFhkzdSlthnIJrFA.png" /></figure><p>Recently I was involved in a project which required real time information to be displayed on my react app. The app had no real time capabilities prior to this. The closest thing to anything real-time in the app was <a href="https://launchdarkly.com/">feature toggling</a>, implemented using <a href="https://github.com/yusinto/ld-redux">ld-redux</a> and <a href="https://github.com/launchdarkly/js-client">Launch Darkly’s js client</a>. Under the hood, this uses server sent events which are like web sockets but the data flows in one direction only from the server to the clients.</p><p>My spider senses told me that graphql subscriptions was the perfect fit for implementing real time capabilities. The app is already using relay classic with my own graphql server, so it’s perfect! Right? Well.. not so fast.</p><p>Relay Classic is … classic. They should really have picked a better name for it like: Relay Outdated or Relay Complicated or Relay Life Sux. Quick googling reveals that the only option to get subscriptions working for relay classic is this <a href="https://github.com/edvinerikson/relay-subscriptions">npm package</a>. It involves directly dealing with sockets, which is not the best/cleanest option.</p><h3>Relay Modern</h3><p>You must have heard of the Relay Modern which is the latest version of Relay with subscriptions support. It’s a much better version of Relay. Easy! Upgrade relay and implement subscriptions. Right? Well… again not so fast.</p><p>The upgrade from relay classic to modern is not a trivial upgrade. There are syntax changes. Routing is a problem because relay modern is incompatible with react router 4 due to query aggregation issues. No server side rendering for relay modern (in classic there are 3rd party packages which make this possible).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*fZSUcGKrECDKlZF-JHy0lg.jpeg" /></figure><h3>Apollo</h3><p>I then began to consider the possibility of using Apollo alongside Relay Classic in the project. Two graphql clients? Really? For one thing the size of including the extra packages is a negative right? Secondly it feels like a hack, a new developer will look at the code and say “Wtf? Why are there 2 graphql clients?” It will be confusing to say the least.</p><p>Size is definitely a concern. I had to add the following packages to get apollo to work:</p><pre><strong>react-apollo<br>apollo-client<br>add-graphql-subscriptions<br>subscriptions-transport-ws</strong></pre><p>I build my app using webpack with BundleAnalyzerPlugin to inspect the sizes of these packages. In total, adding apollo adds about 25kb of overhead to the app (see below). This is not too bad, don’t forget if I don’t use apollo I would still need to add other packages to get subscriptions to work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jnOZb7lLhZA1kyGJgad1AA.png" /><figcaption>Package sizes to illustrate apollo’s overhead — total 25kb</figcaption></figure><p>To make it as least confusing as possible, I restrict the use of apollo to a single route only, the real time route. Apollo is setup at the root of this route only, so only this part of the app is touched. As illustrated in the gist below, only the ApolloLanding component has access to apollo.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/568a43fc116378785c11fb6716cc01ae/href">https://medium.com/media/568a43fc116378785c11fb6716cc01ae/href</a></iframe><p>The ApolloLanding component looks something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/072a7e7b7590049cf36d7cbb7be2c263/href">https://medium.com/media/072a7e7b7590049cf36d7cbb7be2c263/href</a></iframe><h3>Graphcool and graphql-request</h3><p>That’s the story on the client side. On the server side, I use <a href="https://www.graph.cool/">Graphcool</a> to serve the subscriptions. The actual data gets inserted from an external service into graphcool via aws lambda. This lambda code is written in node, using a lightweight graphql client called <a href="https://github.com/graphcool/graphql-request">graphql-request</a> written by Johannes Schickling from graphcool.</p><p>The external service invokes this lambda at high frequency (e.g. once a minute) so the data in graphcool is updated also at high frequency which means that clients get frequent updates from the service. Where does graphql-request fit in this picture?</p><p>The lambda code that updates graphcool has to perform graphql mutations. Graphql mutations (like queries) are just http posts so it’s perfectly ok to use node-fetch or isomorphic-fetch like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c09626c19301da5b7763cbad1adbc53/href">https://medium.com/media/7c09626c19301da5b7763cbad1adbc53/href</a></iframe><p>Or using graphql-request:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/845b6de622d3b86f4b69acd0e00876c0/href">https://medium.com/media/845b6de622d3b86f4b69acd0e00876c0/href</a></iframe><p>I prefer graphql-request because it feels cleaner to me.</p><h3>Conclusion</h3><p>Having both relay and apollo in one project is definitely not the best way to go. However, given the time constraints I think it made sense at the time . I should further optimise the apollo landing route by using webpack dynamic imports. This ensures the component and its packages are not loaded until needed on the client side.</p><p>The long term solution is to upgrade relay to relay modern though. I want statically compiled queries! However there are challenges ahead. I need to solve server side rendering, so I think I have to look at pre-rendering instead.</p><p>Plus graphcool rocks! Check them <a href="http://graph.cool/">out</a>!</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c2c29a095a5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jsdownunder/a-tale-of-three-graphql-clients-6c2c29a095a5">A tale of three Graphql clients</a> was originally published in <a href="https://medium.com/jsdownunder">jsdownunder</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React UI animation made simple]]></title>
            <link>https://medium.com/jsdownunder/react-ui-animation-made-simple-c2ff98056659?source=rss----b402dfdac7eb---4</link>
            <guid isPermaLink="false">https://medium.com/p/c2ff98056659</guid>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Bill Luo]]></dc:creator>
            <pubDate>Tue, 19 Sep 2017 03:53:44 GMT</pubDate>
            <atom:updated>2018-09-12T10:43:25.660Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EB9th1YxD5mypXfQnU4UHw.png" /></figure><p>What makes UI elegant, sexy and beautiful? Design is the first thing that pops up in mind. The modern web has a long way to go! It’s time to push web UI to the next level with animations. I lost count how many times I was amazed by iOS and Android’s beautiful animation, while most of my web apps remain static and “boring”. Static design is like a beautiful 👸 on a poster. It doesn’t move or interact with you! Animation makes static UI alive and vivid.</p><p>Rewind back to my experience, toggling (showing/hiding) an element is one of the most common tasks in UI, which I have done like below for a long time… (shamefully)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/794cc2794db93f049645ba8c8a6d7418/href">https://medium.com/media/794cc2794db93f049645ba8c8a6d7418/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/67490e3e921bc9b33e9900995bdc5f53/href">https://medium.com/media/67490e3e921bc9b33e9900995bdc5f53/href</a></iframe><p>I slowly evolved from this to css to perform the toggling.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d6d15a1b6bbc03af4fd3505a8160fdbb/href">https://medium.com/media/d6d15a1b6bbc03af4fd3505a8160fdbb/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b83c71fe569065b09f91bd81a9bd765f/href">https://medium.com/media/b83c71fe569065b09f91bd81a9bd765f/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f59eda0280a6603c7bac068bf7f4abb3/href">https://medium.com/media/f59eda0280a6603c7bac068bf7f4abb3/href</a></iframe><p>While that works, I often lost track of what the actual style looks like when glancing quickly at the code. I kept feeling this is not the best approach to implement animation.</p><p>There should be a better and easier way to perform animations in react. So I wrote my own. I present to you react-simple-animate.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e81c418fcfbb603601e4058522b754f/href">https://medium.com/media/7e81c418fcfbb603601e4058522b754f/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e8bdc076e0c4f752ceab0c48a4158a3/href">https://medium.com/media/6e8bdc076e0c4f752ceab0c48a4158a3/href</a></iframe><p>A declarative and simple way to perform animation in react. I can control the start of the animation and the styles to apply at the end of the animation. This is a good pattern in my opinion. Hooray!</p><h4>React Simple Animate</h4><p><a href="https://github.com/bluebill1049/react-simple-animate">React simple animate</a> 🤘 is the way to go! Oh yes, it’s my 2c worth contributing to the community after years of using open source software (first time too). The goal is make UI animation as easy as possible for react</p><p>Here are two awesome examples of what I was able to achieve using <a href="https://github.com/bluebill1049/react-simple-animate">react-simple-animate</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*B3dpLJF_p33hpmdt3wWA9A.gif" /><figcaption>Navigation with react-simple-animate(note the frame rate is dropped due to animated gif)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*Vs7FN0m-dF5PGIMo4hiASA.gif" /><figcaption>react-simple-animate animates the svg map</figcaption></figure><p>While react simple animation is great it has some pros and cons:</p><p>😍<strong> Pros:</strong></p><ul><li>Simple animation from inline style A to style B</li><li>Declarative for component animation</li><li>Make animation toggle easy</li><li>Support animation sequences</li><li>It’s tiny size</li></ul><p>😑<strong> Cons:</strong></p><ul><li>Does not support sequenced animation</li><li>Vendor prefix for style is not support out of box</li><li>it’s made for simple animation 🤘</li></ul><p>The best way to see how simple it is to try it yourself, which you can do with the <a href="https://react-simple-animate.herokuapp.com/">demo</a>.</p><figure><a href="https://react-simple-animate.herokuapp.com/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NNkqjrKquI6O1swGLlcAFQ.png" /></a><figcaption>React simple animate demo (you can tap on the &lt;&gt; button to see the code 😛)</figcaption></figure><p>Overall, I hope <a href="https://www.npmjs.com/package/react-simple-animate">react-simple-animate</a> will help everyone create more elegant UI with beautiful animation, and of course thanks for your time reading this and trying out the package. 🤘</p><p><em>Lastly, thanks </em><a href="https://medium.com/u/3c95cbc72757"><em>Yusinto Ngadiman</em></a><em>❤️ for contributing to the package and the blog post.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2ff98056659" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jsdownunder/react-ui-animation-made-simple-c2ff98056659">React UI animation made simple</a> was originally published in <a href="https://medium.com/jsdownunder">jsdownunder</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A fast website fast.]]></title>
            <link>https://medium.com/jsdownunder/a-fast-website-fast-8444e815125e?source=rss----b402dfdac7eb---4</link>
            <guid isPermaLink="false">https://medium.com/p/8444e815125e</guid>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[web-performance]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Yusinto Ngadiman]]></dc:creator>
            <pubDate>Mon, 14 Aug 2017 00:30:19 GMT</pubDate>
            <atom:updated>2017-08-15T00:26:31.579Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VYHjfFBPAq_u5g7veMuBJw.jpeg" /><figcaption>Fast website, fast.</figcaption></figure><blockquote>A lazy programmer’s guide to optimise speed with minimal work.</blockquote><p>None of us wants a slow site. But most of us don’t get our hands dirty often enough to speed up our sites. It’s analogous to owning a car. We want a functioning, fast, problem free car; but most of us are not interested to look under the hood to tweak the engine, change the oil, etc.</p><p>I believe I have just successfully described myself and perhaps a few other developers in the world. At least a previous version of myself. I decided to get my hands dirty and look under the hood, and I want to share with you the discoveries I made which you can copy to quickly and easily speed up your website.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-M68_b_G_q1-TLXcyHbsJg.jpeg" /></figure><h4>Chrome Dev Tools</h4><p>Many people use chrome dev tools, but not in depth. I am guilty as well. Do not be afraid. It’s not as hard as you think.</p><ol><li>Open your website in chrome incognito mode. Incognito so extensions are excluded because they can add noise to our stats.</li><li>Open chrome dev tools. In the Network tab:<br>* Check <em>“Disable cache” <br></em>* Set <em>Network throttling</em> to <em>“Fast 3G”</em></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q8p12Kj_xR3lN8Nf_SMq5g.png" /></figure><p>3. In the Performance tab, hit the reload button (not the browser refresh button!) that says <em>“Start profiling and reload page”</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5FT8Jp58EHtW-cNm0okg_A.png" /></figure><h4>Profiler Results</h4><p>You’ll get a pretty graph at the end. For my app, it looked like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7wql4ruTsu24yCJwanfy9A.png" /></figure><p>Let’s see if my primitive mind can make sense of this.</p><ol><li>I use webpack to produce a single js bundle for my app. I set the script to defer, so it shouldn’t block html parsing. <strong><em>GOTCHA</em></strong><em>: </em>deferred scripts don’t block html parsing. They get downloaded asynchronously on separate threads. However they get executed <strong><em>before</em></strong><em> </em><a href="https://developer.mozilla.org/en/docs/Web/Events/DOMContentLoaded">DomContentLoaded</a>. So in my case, the gigantic main bundle takes 15 seconds to download on a fast 3G connection and that delayed DomContentLoaded.</li><li>The browser compiles and executes the bundle once it has finished downloading.</li><li><strong>DomContentLoaded</strong> event is fired. This means that the <em>“HTML document has been completely loaded and parsed, without waiting for stylesheets, images, and subframes to finish loading” — ripped from </em><a href="https://developer.mozilla.org/en/docs/Web/Events/DOMContentLoaded"><em>Mozilla</em></a></li><li><strong>Load</strong> event is fired. This means that the page has fully loaded.</li></ol><p>In my case, it was easy to see that the single gigantic bundle was the bottleneck in performance. A better way is to split the bundle into smaller chunks: an app chunk and a vendor chunk (or maybe even multiple vendor chunks).</p><h3>Conclusion</h3><p>In the next post I will share the results of splitting the app into chunks. I will use webpack’s CommonChunksPlugin to achieve this. There will be blood (and performance gains)! In the meantime, check <a href="http://reactjunkie.com/">reactjunkie.com</a> for my other posts related to dev and javascript.</p><p>I hope I have whet your appetite. Optimising performance to make things go fast is actually very fun and addictive! It’s like modifying a car, fine tuning the engine so it goes faster. It’s exactly like that. Happy tuning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8444e815125e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jsdownunder/a-fast-website-fast-8444e815125e">A fast website fast.</a> was originally published in <a href="https://medium.com/jsdownunder">jsdownunder</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Webpack — Build Performance Pitfall of using SASS with CSS Modules]]></title>
            <link>https://medium.com/jsdownunder/webpack-build-performance-pitfall-of-using-sass-with-css-modules-ba32f89efdcb?source=rss----b402dfdac7eb---4</link>
            <guid isPermaLink="false">https://medium.com/p/ba32f89efdcb</guid>
            <category><![CDATA[sass]]></category>
            <category><![CDATA[slow-build]]></category>
            <category><![CDATA[css-modules]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[webpack]]></category>
            <dc:creator><![CDATA[Will Po]]></dc:creator>
            <pubDate>Tue, 01 Aug 2017 07:29:20 GMT</pubDate>
            <atom:updated>2018-01-26T10:46:43.605Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LZZ9Sr4XL7j2-LjSJ5uq9Q.jpeg" /></figure><p>Many people looking to combine the power of SASS with modularised stylesheets will use <a href="https://github.com/webpack-contrib/css-loader">CSS Modules</a>.</p><p>It’s an obvious choice.</p><p>When using <a href="https://github.com/webpack/webpack">Webpack</a> as your bundler, you’ll likely use <a href="https://github.com/webpack-contrib/sass-loader">sass-loader</a> to transpile the SASS. An example of the Webpack loaders configuration used to do this:</p><pre>{<br>  test: /\.sass$/,<br>  use: [<br>    {<br>      loader: &#39;style-loader&#39;,<br>      options: {<br>        sourceMap: <strong>true</strong>,<br>      },<br>    },<br>    {<br>      loader: &#39;css-loader&#39;,<br>      options: {<br>        sourceMap: <strong>true</strong>,<br>        modules: <strong>true</strong>,<br>        importLoaders: 3,<br>        localIdentName: &#39;[folder]--[local]--[hash:base64:2]&#39;,<br>      }<br>    },<br>    &#39;postcss-loader&#39;,<br>    &#39;resolve-url-loader&#39;,<br>    {<br>      loader: &#39;sass-loader&#39;,<br>      options: {<br>        sourceMap: <strong>true</strong>,<br>        indentedSyntax: <strong>true</strong>,<br>      }<br>    }<br>  ]<br>},</pre><pre>{<br>  test: /\.sass$/,<br>  use: [<br>    {<br>      loader: &#39;style-loader&#39;,<br>      options: {<br>        sourceMap: <strong>true</strong>,<br>      },<br>    },<br>    {<br>      loader: &#39;css-loader&#39;,<br>      options: {<br>        sourceMap: <strong>true</strong>,<br>        modules: <strong>true</strong>,<br>        importLoaders: 3,<br>        localIdentName: &#39;[folder]--[local]--[hash:base64:2]&#39;,<br>      }<br>    },<br>    &#39;postcss-loader&#39;,<br>    &#39;resolve-url-loader&#39;,<br>    {<br>      loader: &#39;sass-loader&#39;,<br>      options: {<br>        sourceMap: <strong>true</strong>,<br>        indentedSyntax: <strong>true</strong>,<br>      }<br>    }<br>  ]<br>},</pre><h3>The Problem — Exponentially Increasing Build Times</h3><p>Part of the problem with <a href="https://github.com/webpack-contrib/sass-loader">sass-loader</a> (<em>which uses node-sass underneath</em>), is that transpiled SASS files are not cached. Also, when sass-loader is used with CSS Modules, every component’s stylesheet is modularised, and <em>so each of these will spawn its own SASS process, </em>and your dual/quad core CPU will try to run all these processes simultaneously with tremendous overhead. Most likely these stylesheets will import some common SASS modules (eg. breakpoints, mixins, variables, colours, etc), and since there’s no cached transpilation, this means these common SASS modules will get transpiled to CSS over and over and over and over…</p><h4>Exponentially Increasing Build Times</h4><p>For our team, this led to exponential increases in the start up time of our Webpack Dev Server from a few seconds when the project was started, to about 3–6 minutes after a few months worth of new components and changes.</p><p>Most of the time, we don’t need to restart our dev server due to the hot-reloading that we’ve configured. But often we’ll have to do one of: switch to another branch which requires <a href="https://github.com/yarnpkg/yarn">yarn</a> to be run, switch to another repo/branch to do a code review, restart the computer or restart the app for some reason…</p><h4>Bad Developer Experience</h4><blockquote>Needless to say, every restart was a massive drain on productivity, momentum, and the developer experience (ie. dev happiness), which further affects productivity! — and so we took drastic action!</blockquote><h3>Our Solution</h3><blockquote>Get rid of SASS!</blockquote><blockquote>Ok — well, what do you use instead?</blockquote><h4>PostCSS / CSSNext.</h4><p>Most of the stuff you want to do in SASS, you can already do with tomorrow’s CSS syntax with the help of <a href="https://github.com/postcss/postcss">PostCSS</a> and <a href="http://cssnext.io/">CSSNext</a>.</p><blockquote>After converting all our component’s stylesheets from SASS to CSS, our build time has pretty much dropped by 50% to about 1.5 minutes.</blockquote><p><strong><em>1.5 minutes!</em></strong> Still much higher than desired, but a massive improvement in productivity for us.</p><h3>Conclusion</h3><p>If you’re starting a new project and looking to use CSS Modules, <em>strongly consider using PostCSS/CSSNext from the start, and don’t use SASS at all. </em>You will save yourself a lot of time down the long run!</p><p>On the other hand, if you are already using CSS Modules with SASS and are experiencing increasing build times, take comfort in knowing that if you take the plunge (and short-term pain) to convert all your SASS to CSS, <em>you can reduce the build time by ~50%!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba32f89efdcb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jsdownunder/webpack-build-performance-pitfall-of-using-sass-with-css-modules-ba32f89efdcb">Webpack — Build Performance Pitfall of using SASS with CSS Modules</a> was originally published in <a href="https://medium.com/jsdownunder">jsdownunder</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>