<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Peter Browne on Medium]]></title>
        <description><![CDATA[Stories by Peter Browne on Medium]]></description>
        <link>https://medium.com/@petebrowne?source=rss-79553ee9f56c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5BnNIl4qvxAr2JYFvaFdzA.jpeg</url>
            <title>Stories by Peter Browne on Medium</title>
            <link>https://medium.com/@petebrowne?source=rss-79553ee9f56c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 03:59:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@petebrowne/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[SVG Pie Chart using React and D3]]></title>
            <link>https://medium.com/localmed-engineering/svg-pie-chart-using-react-and-d3-43a381ce7246?source=rss-79553ee9f56c------2</link>
            <guid isPermaLink="false">https://medium.com/p/43a381ce7246</guid>
            <category><![CDATA[svg]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[3d]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Peter Browne]]></dc:creator>
            <pubDate>Fri, 17 Jun 2016 19:12:14 GMT</pubDate>
            <atom:updated>2016-06-17T19:12:14.246Z</atom:updated>
            <content:encoded><![CDATA[<p>Combining D3’s modular API and React’s declarative interface for composing SVGs makes creating interactive charts easy as pie.</p><p><em>These examples assume familiarity with:</em></p><ul><li><a href="https://babeljs.io/docs/learn-es2015/">ES2015 Syntax</a></li><li><a href="https://facebook.github.io/react/">React</a> &amp; <a href="https://facebook.github.io/react/docs/reusable-components.html#es6-classes">ES2015 Class Components</a></li></ul><p><em>By the way, if you need to just ship something, there are quite a few great libraries for using D3 with React:</em></p><ul><li><a href="https://github.com/esbullington/react-d3">react-d3</a></li><li><a href="https://github.com/FormidableLabs/victory">Victory</a></li></ul><h3>Example 1: A Simple Pie Chart</h3><p>Repeat after me: “Don’t touch the DOM when using React.” Basically, if you’ve used D3 before, you should forget the entire <a href="https://github.com/d3/d3/wiki/Selections">Selections API</a>. Luckily D3 is incredibly modular. All the examples below are on <a href="http://codepen.io/collection/XKkkQR/">Codepen</a>, but if you’re using Browserify or Webpack here’s all you’ll need:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db6e77ec18b5f4236eefcea25d5125fa/href">https://medium.com/media/db6e77ec18b5f4236eefcea25d5125fa/href</a></iframe><p>Our application will consist of three components, which we’ll use throughout the examples. Here’s a quick overview:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*olJnzt0JHEVtCkOqeJEr0g.jpeg" /></figure><h4>&lt;App&gt; Component</h4><p>The App component mainly calculates the position and <em>radius</em> of the pie chart so that it fits neatly into the center of the window. This does not update with window resize events, but you could easily add something like <a href="https://github.com/digidem/react-dimensions">react-dimensions</a> in a real world scenario.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98edd290bc1423d459467aa58878db17/href">https://medium.com/media/98edd290bc1423d459467aa58878db17/href</a></iframe><h4>&lt;Pie&gt; Component</h4><p>The Pie component has two jobs at this point:</p><ol><li>Create a <a href="https://github.com/d3/d3/wiki/Ordinal-Scales#category10">color scale</a> for generating colors for each slice. This isn’t necessary if each slice has a predetermined fill color.</li><li>Create a <a href="https://github.com/d3/d3/wiki/Pie-Layout">pie layout generator</a>. For each value in the <em>data</em> array, we call the pie generator function and render a Slice with the returned value.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2ce9441e4540a2866013edb3153d444/href">https://medium.com/media/c2ce9441e4540a2866013edb3153d444/href</a></iframe><h4>&lt;Slice&gt; Component</h4><p>Using the <a href="https://github.com/d3/d3/wiki/SVG-Shapes#arc">arc generator</a> and the value generated by the Pie component, the Slice component renders the pie slice path.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23f2f44dd5f3f9444b96e966b9cdd888/href">https://medium.com/media/23f2f44dd5f3f9444b96e966b9cdd888/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fpetebrowne%2Fembed%2Fpreview%2FjrWeZN%3Fheight%3D600%26amp%3Bslug-hash%3DjrWeZN%26amp%3Bdefault-tabs%3Djs%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fpetebrowne%2Fpen%2FjrWeZN&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F142255.jrWeZN.small.b5fda205-7919-43c4-979a-2343d9aff65e.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/87b4953c04414993cae518238d4f015a/href">https://medium.com/media/87b4953c04414993cae518238d4f015a/href</a></iframe><h4>Putting it all together</h4><p>The key is to use D3’s shape layout and path generators to calculate the SVG element properties. React is responsible for building the DOM and SVG elements. Later, we’ll also use React for some basic interactivity. But first, let’s look at how we can add some labels to the pie chart.</p><h3>Example 2: Adding Labels</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fpetebrowne%2Fembed%2Fpreview%2FezJPag%3Fheight%3D600%26amp%3Bslug-hash%3DezJPag%26amp%3Bdefault-tabs%3Djs%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fpetebrowne%2Fpen%2FezJPag&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F142255.ezJPag.small.7c91236b-c5f8-4621-b4f4-df44deb56e9b.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/f1a55ad3de7027a9799bba4cabcb555f/href">https://medium.com/media/f1a55ad3de7027a9799bba4cabcb555f/href</a></iframe><h4>Updating the &lt;Pie&gt; Component</h4><p>To start, we’ll use the <em>data</em> property of the <em>value</em> object as the label. This will be the original number we passed into the App component. We’ll add support for the <em>label</em> property next.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9bb76c0ead0ea7a94d77ce85179a016f/href">https://medium.com/media/9bb76c0ead0ea7a94d77ce85179a016f/href</a></iframe><h4>Updating the &lt;Slice&gt; Component</h4><p>The Slice component does the heavy lifting for adding labels. We’ll add a new <em>&lt;text&gt;</em> element that’s transformed into the correct position by using the <a href="https://github.com/d3/d3/wiki/SVG-Shapes#arc_centroid">arc.centroid</a> function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/89b02d8a0413eaf8641c65951438e019/href">https://medium.com/media/89b02d8a0413eaf8641c65951438e019/href</a></iframe><h3>Example 3: Turn a Pie into a Donut</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fpetebrowne%2Fembed%2Fpreview%2FezJQmW%3Fheight%3D600%26amp%3Bslug-hash%3DezJQmW%26amp%3Bdefault-tabs%3Djs%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fpetebrowne%2Fpen%2FezJQmW&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F142255.ezJQmW.small.4ddc1fdf-8f18-43b7-91e5-fb2f64269de7.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/b40082ebc515e93a7de8ddc8bb3cb96d/href">https://medium.com/media/b40082ebc515e93a7de8ddc8bb3cb96d/href</a></iframe><h4>Updating the &lt;App&gt; Component</h4><p>We’re going to add a few more arc properties from D3 to turn our pie into a donut. We’ve already setup the <em>innerRadius</em> property for the Pie and Slice components, so we’ll set it to a fraction of the <em>outerRadius</em> and call it done. The other properties, <a href="https://github.com/d3/d3/wiki/SVG-Shapes#arc_cornerRadius"><em>cornerRadius</em></a> and <a href="https://github.com/d3/d3/wiki/SVG-Shapes#arc_padRadius"><em>pieAngle</em></a>, will be handled by D3.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2cde6b30d41fcf3982641535e8fb3b92/href">https://medium.com/media/2cde6b30d41fcf3982641535e8fb3b92/href</a></iframe><h4>Updating the &lt;Pie&gt; Component</h4><p>Here we simply pass the new pie chart properties to the Slice components.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0752324d114763ff0eb2043fcbd0bf08/href">https://medium.com/media/0752324d114763ff0eb2043fcbd0bf08/href</a></iframe><h4>Updating the &lt;Slice&gt; Component</h4><p>The properties are now used in the arc generator methods. The rest of the component is unchanged.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d396142dd3b90f49ef1bd9cd9539338/href">https://medium.com/media/0d396142dd3b90f49ef1bd9cd9539338/href</a></iframe><h3>Example 4: Basic Interactivity</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fpetebrowne%2Fembed%2Fpreview%2FNrxEGq%3Fheight%3D600%26amp%3Bslug-hash%3DNrxEGq%26amp%3Bdefault-tabs%3Djs%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fpetebrowne%2Fpen%2FNrxEGq&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F142255.NrxEGq.small.e372870b-653e-4eee-bb53-4ac50a4138cc.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d99a47ab463757fab60896e201a6769/href">https://medium.com/media/6d99a47ab463757fab60896e201a6769/href</a></iframe><p>At this point, adding some interactivity is is pretty straightfoward. We’ll listen for <em>onMouseOver</em> and <em>onMouseOut</em> events, and toggle the state of <em>isHovered</em>. When the slice is hovered, we’ll expand the <em>outerRadius</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f83c0268c262debc320b4543a4ea0cfc/href">https://medium.com/media/f83c0268c262debc320b4543a4ea0cfc/href</a></iframe><p>Now we have an interactive Pie chart. We’ve built a reusable component with support for labels, inner and outer radius, and basic hover effects. If you really want to make this pop, checkout <a href="http://react-motion/">react-motion</a>. It will make it super simple to animate the hover effect.</p><p>Thanks for reading! If you enjoyed this, you may want to read some of our other posts from <a href="https://medium.com/localmed-engineering">LocalMed Engineering</a>:</p><ul><li><a href="https://medium.com/localmed-engineering/offline-first-an-intro-to-service-workers-ae0c57f8f27d">Offline First: An Intro to Service Workers</a></li><li><a href="https://medium.com/localmed-engineering/localmed-toolbelt-f12aa3782132">LocalMed Toolbelt</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43a381ce7246" width="1" height="1" alt=""><hr><p><a href="https://medium.com/localmed-engineering/svg-pie-chart-using-react-and-d3-43a381ce7246">SVG Pie Chart using React and D3</a> was originally published in <a href="https://medium.com/localmed-engineering">LocalMed Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LocalMed Toolbelt]]></title>
            <link>https://medium.com/localmed-engineering/localmed-toolbelt-f12aa3782132?source=rss-79553ee9f56c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f12aa3782132</guid>
            <category><![CDATA[command-line]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Peter Browne]]></dc:creator>
            <pubDate>Fri, 11 Mar 2016 21:25:41 GMT</pubDate>
            <atom:updated>2016-03-11T21:25:41.407Z</atom:updated>
            <content:encoded><![CDATA[<h4>A command line interface for developing localmed.com</h4><p>In the first few months of our product development we created a great tool for everyday development: <a href="https://github.com/localmed/git-jira-flow">git-jira-flow</a>. The premise was to create some simple git extensions, inspired by <a href="https://github.com/nvie/gitflow">git-flow</a>, and update the status of our JIRA issues.</p><p>Fast forward two years. We have migrated away from JIRA to TargetProcess for issue tracking. Our development workflow now incorporates services for continuous integration (Bamboo), deployment reporting (New Relic), code review (BitBucket), and static file deployment (AWS S3).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*D0143klhU9B4ke21MgJ40w.jpeg" /><figcaption>localmed-toolbelt</figcaption></figure><p>This time we decided to make our very own purpose built CLI. Since many of the new commands wouldn’t even use git, the bash extensions didn’t make sense as a starting point. Also, while bash scripting can be fun in the look-at-my-hacking-skills kind of way, we wanted to use a proper scripting language. We built the new version using <a href="http://click.pocoo.org/5/">python click</a>, which has a great declarative API without too much magic.</p><p>The toolbelt needed to be agnostic as well, not only to the different project types, but also with all our different service integrations. Switching to another service shouldn’t and doesn’t affect the general development workflow.</p><p>Here are some of the highlights:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*JuGsruYZFL7jFc_JpG9yLQ.jpeg" /><figcaption>work:start</figcaption></figure><h4>Start</h4><p>This starts work on a task or bug. We use a branch naming scheme enforced by the toolbelt. If the work is part of a larger release, this will start from a release branch.</p><ol><li>Sets the task as “In Progress” in our issue tracker</li><li>Creates a branch for making changes</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*fH6qzdfTPpKyyNnOEMIMWg.gif" /><figcaption>work:review</figcaption></figure><h4>Push for Review</h4><ol><li>Sets the task as “In Review” in our issue tracker</li><li>Logs time spent on the task</li><li>Creates a pull request with the description of the task</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*A5O-4oXMdEFT9DdwHIDFNQ.gif" /><figcaption>work:finish</figcaption></figure><h4>Finish &amp; Merge</h4><ol><li>Sets the task as “Done” in our issue tracker</li><li>Logs any additional time spent after review</li><li>Merges the pull request</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hEM9tWguer9mmTCZwdXTOA.jpeg" /><figcaption>build:status</figcaption></figure><h4>Build Status</h4><p>Who needs to hop out to a web browser to check the build status? We can do it right from the command line.</p><h4>Roadmap</h4><p>Looking ahead, we’ve got some interesting ideas for the toolbelt:</p><ul><li>Github pull request support</li><li>Create simple bug reports</li><li>Not sure what to work on next? Search for open tasks/bugs</li><li>Print metrics of production applications</li></ul><p>I think the benefits of abstracting your development process into a tool are pretty clear. There are many tedious steps surrounding the actual work of software development and automating the process makes everyone’s lives easier.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f12aa3782132" width="1" height="1" alt=""><hr><p><a href="https://medium.com/localmed-engineering/localmed-toolbelt-f12aa3782132">LocalMed Toolbelt</a> was originally published in <a href="https://medium.com/localmed-engineering">LocalMed Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Offline First: An Intro to Service Workers]]></title>
            <link>https://medium.com/localmed-engineering/offline-first-an-intro-to-service-workers-ae0c57f8f27d?source=rss-79553ee9f56c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae0c57f8f27d</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[offline-first]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Peter Browne]]></dc:creator>
            <pubDate>Fri, 26 Feb 2016 16:16:01 GMT</pubDate>
            <atom:updated>2016-02-26T16:16:01.228Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Let’s assume our users will always have a fast, reliable internet connection.<br>– No One Ever</blockquote><p>It seems ridiculous to say it out loud, but that’s how we’ve built websites and applications in the past. The goal of an “offline first” strategy is to assume the opposite: our users have a slow, unreliable internet connection. Why? Because <a href="http://blog.invisionapp.com/ux-design-tips-for-your-app/">network awareness is a good user experience in any context</a>.</p><p>Unfortunately there is no magic bullet – if your application needs content from the server, at some point it will require a connection. But what happens when your user’s connection drops?</p><p>Enter the service worker…</p><h3>What’s a Service Worker?</h3><blockquote>A generic entry point for persistent event-driven background processing in the Web Platform.<br>– Paraphrased from the <a href="https://www.w3.org/TR/service-workers/">W3C Spec</a></blockquote><p>A service worker is essentially a background script for controlling web pages. This provides application authors the low-level control over the request lifecycle required to deliver a great user experience with low connectivity.</p><h4>Service Worker Features</h4><ul><li>Intercept network requests</li><li>Requests caching</li><li>Push notifications</li><li>Background sync (proposed)</li><li>Geo-fencing (proposed)</li></ul><p>Of which, intercepting and caching network requests are the essential building blocks an offline first application. Let’s look at how it works:</p><h3>Service Worker Demos</h3><p><em>These examples assume familiarity with:</em></p><ul><li><a href="https://babeljs.io/docs/learn-es2015/">Es2015 Syntax</a></li><li><a href="http://www.html5rocks.com/en/tutorials/es6/promises/"><em>Promises</em></a></li><li><a href="https://davidwalsh.name/fetch"><em>Fetch API</em></a></li></ul><h4>Example 1: Service Worker Lifecycle</h4><p><a href="https://github.com/localmed/service-workers-demo/tree/master/example-1">Demo on Github</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cbd6bf84e944bbaa165b228d680d79c0/href">https://medium.com/media/cbd6bf84e944bbaa165b228d680d79c0/href</a></iframe><p>Registering a service worker loads the script in the background and executes the initial lifecycle events. Notice the <strong>register</strong> method returns a <strong>Promise</strong>, and we can access a <a href="https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration">registration object</a> for unregistering the worker.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b27019724ba2733149267ac8279efb73/href">https://medium.com/media/b27019724ba2733149267ac8279efb73/href</a></iframe><p>A basic service worker script is mainly comprised of event handlers. We’ll load this in Chrome and inspect the console:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*a43CKMb8KbpLPL-1yVkSpw.png" /><figcaption>Log output on first load</figcaption></figure><p>First impressions:</p><ul><li><strong>self</strong> is an instance of <a href="https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope">ServiceWorkerGlobalScope</a>. There is no <strong>window</strong> object.</li><li><strong>event</strong> is an instance of <a href="https://developer.mozilla.org/en-US/docs/Web/API/ExtendableEvent">ExtendableEvent</a>, which contain new APIs for controlling the service worker lifecycle.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*E5KAY1A-LredE_akBXhjkA.png" /><figcaption>Log output on second load</figcaption></figure><p>Notice this time we see the <strong>fetch </strong>events, including URLs from another domain. The <strong>request </strong>object on fetch events is an instance of the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Request/Request">Fetch Request</a> class, with contains useful properties and methods for inspecting the outgoing request.</p><p><em>We also see stale logs from the previous load &amp; an error, which can be very confusing. At this point, debugging service workers is difficult, and I think this is actually a bug in Chrome.</em></p><h4>Example 2: Fetching</h4><p><a href="https://github.com/localmed/service-workers-demo/tree/master/example-2">Demo on Github</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d90de4adef8243b44a562d1d9570c6c6/href">https://medium.com/media/d90de4adef8243b44a562d1d9570c6c6/href</a></iframe><p>Using the <strong>fetch</strong> event you can intercept the request and return a custom response. To do this, we pass a <a href="https://developer.mozilla.org/en-US/docs/Web/API/Response">Response</a> object to the <strong>respondWith</strong> method of the event.</p><p>When omitting a custom response, the default behavior is to fetch and return the original response. It’s exactly the same as explicitly calling <strong>event.respondWith(fetch(event.request))</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/285/1*Liil6_RD7BsX2PmD5-lXcw.png" /><figcaption>Please don’t do this…</figcaption></figure><h4>Example 3: Prefetching &amp; Caching</h4><p><a href="https://github.com/localmed/service-workers-demo/tree/master/example-3">Demo on Github</a></p><p>In this example we will prefetch our assets and cache them for later requests.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62750b233b65d7b5a26a76c9834fca3e/href">https://medium.com/media/62750b233b65d7b5a26a76c9834fca3e/href</a></iframe><p>First off, there’s a global <a href="https://developer.mozilla.org/en-US/docs/Web/API/CacheStorage">caches</a> object which contains many <a href="https://developer.mozilla.org/en-US/docs/Web/API/Cache">Cache</a> instances, keyed by unique cache names. The <strong>addAll</strong> convenience method handles fetching and storing the responses in the cache. We use this to prefetch the assets from <strong>CACHE_URLS</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*926OKmAo6VYBz_fvVu0zFQ.png" /><figcaption>Prefetching Network Log</figcaption></figure><p>In the network panel, we’ll see the requests for the assets occur in the service worker, which is indicated by the gear icon. This happens in the background and does not affect initial page load time.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b0d0712f51d36f51945428f1487dd63/href">https://medium.com/media/7b0d0712f51d36f51945428f1487dd63/href</a></iframe><p>Next, in the <strong>fetch </strong>event we use a cache first strategy of:</p><ol><li>Attempt to get response from the cache, by matching the request.</li><li>If there is no response, fallback to the default behavior of fetching.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*1xqOAB7CHW1n7SYo7AnQ7A.png" /><figcaption>Loading Assets From The Cache</figcaption></figure><p>When we load the next page, we’ll see the assets are loaded from the cache, indicated by the “(from ServiceWorker)” message.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca87733422a808f93d93ca3edf104178/href">https://medium.com/media/ca87733422a808f93d93ca3edf104178/href</a></iframe><p>And finally we’ll use the <strong>activate</strong> event to delete stale caches. We use the convention of incrementing the <strong>CACHE_VERSION</strong> for cache invalidation. This deletes any caches that do not match the current cache name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*4rxrWr8DMH004lRPlxENGg.png" /><figcaption>Invalidating Stale Cache</figcaption></figure><h4>Example 4: Offline Page</h4><p><a href="https://github.com/localmed/service-workers-demo/tree/master/example-4">View Full Demo on Github</a></p><p>Now, let’s combine these techniques to create an offline page, which will indicate to users we’ve lost the connection.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18c9cac4e4478888b68107a17f86eb15/href">https://medium.com/media/18c9cac4e4478888b68107a17f86eb15/href</a></iframe><p>We’ll use the same prefetching technique from Example 3 to cache the offline page on initial load.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7df03d93204af94babd91cba1461638/href">https://medium.com/media/d7df03d93204af94babd91cba1461638/href</a></iframe><p>This time, in the <strong>fetch</strong> event, we’ll use a fetch first strategy and fallback to a cached offline page. To be on the safe side, we check the request to ensure it’s a GET request for HTML content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/232/1*XEbuPYJqQemGgtEp2_ZuQg.png" /><figcaption>Our Offline Page In-action</figcaption></figure><p>It may not seem like much, but this is a great foundation for custom handling of the offline user experience. Here’s what we’ve accomplished:</p><ul><li>Prefetched static assets, for faster subsequent page loads.</li><li>Added a fallback offline page when the user loses their connection.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae0c57f8f27d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/localmed-engineering/offline-first-an-intro-to-service-workers-ae0c57f8f27d">Offline First: An Intro to Service Workers</a> was originally published in <a href="https://medium.com/localmed-engineering">LocalMed Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Is React.js and Why Should I Use It?]]></title>
            <link>https://medium.com/localmed-engineering/what-is-react-js-and-why-should-i-use-it-c017cc5e382a?source=rss-79553ee9f56c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c017cc5e382a</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Peter Browne]]></dc:creator>
            <pubDate>Tue, 30 Dec 2014 18:21:09 GMT</pubDate>
            <atom:updated>2016-02-23T01:47:11.552Z</atom:updated>
            <content:encoded><![CDATA[<p>Our chief concern at LocalMed is to help patients find the most convenient dental appointment. We recently had the opportunity to redesign our openings calendar and decided to build the final UI component using <a href="http://facebook.github.io/react/">React.js</a>.</p><p>I thought it would be interesting to share <em>why</em> we decided to use it in the first place. This was not a trivial decision. Even though we’re still a small team, we consider the impact of our decisions as our product and team grows.</p><p>Below are slides from the internal tech talk I gave about React, explaining what it is and why we should use it:</p><p><a href="http://slides.com/petebrowne/react">React.js by Peter Browne</a></p><p>Many of the talking points were taken from the excellent <a href="https://www.youtube.com/watch?v=x7cQ3mrcKaY">Rethinking Best Practices</a> talk by Pete Hunt. I recommend watching to hear it directly from the horse’s mouth.</p><p><em>Originally published at </em><a href="http://engineering.localmed.com/react-js/"><em>engineering.localmed.com</em></a><em> on December 30, 2014.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c017cc5e382a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/localmed-engineering/what-is-react-js-and-why-should-i-use-it-c017cc5e382a">What Is React.js and Why Should I Use It?</a> was originally published in <a href="https://medium.com/localmed-engineering">LocalMed Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>