<?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 Bryan Fillmer on Medium]]></title>
        <description><![CDATA[Stories by Bryan Fillmer on Medium]]></description>
        <link>https://medium.com/@bryanfillmer?source=rss-7e8a50ebe597------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jwDB1eVjRFF01mU_R1-ZAw.jpeg</url>
            <title>Stories by Bryan Fillmer on Medium</title>
            <link>https://medium.com/@bryanfillmer?source=rss-7e8a50ebe597------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 21:44:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bryanfillmer/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[Static Success with Hugo: Part II]]></title>
            <link>https://medium.com/@bryanfillmer/static-success-with-hugo-part-ii-56f0dda33efd?source=rss-7e8a50ebe597------2</link>
            <guid isPermaLink="false">https://medium.com/p/56f0dda33efd</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[techonology]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[tech]]></category>
            <dc:creator><![CDATA[Bryan Fillmer]]></dc:creator>
            <pubDate>Mon, 13 Jul 2020 14:38:45 GMT</pubDate>
            <atom:updated>2020-07-13T14:38:45.174Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Su_uqZVJh8_DufNEo8wVTA.jpeg" /></figure><h3>This one simple trick…</h3><p>Continuing on from our previous article, we enjoyed building our new website with <a href="http://gohugo.io/">Hugo</a>, but we ran into some interesting challenges during setup and customization. One area that took a bit of digging to figure out was the mapping of single-use screens, such as our <a href="https://fillmerinnovationgroup.com/get-started">Get Started</a> screen, to the appropriate content.</p><h3>Mapping content to pages</h3><p>Our solution involved creating a pages directory within the layouts directory. Inside we made a single template file, get-started.html, whose name maps <strong>exactly</strong> to a directory created within the content directory. The directory structure mapped out:</p><pre>...<br>content/<br>  get-started/<br>    index.md<br>...<br>layouts/<br>  pages/<br>    get-started.html<br>...</pre><p>The final piece of this puzzle was to make sure the contents of the index.md file in the content/ directory were correctly defined to pull the get-started.html template, which contains our custom code for our contact form:</p><pre>---<br>title: &quot;Get Started&quot;<br>type: pages<br>layout: get-started<br>---</pre><p>With this done, and our header navigation updated with the correct link, we were able to build out our custom contact form within the get-started.html file. A simple solution, but not immediately intuitive when coming into the Hugo ecosystem from the outside.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56f0dda33efd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Static Success with Hugo: Part I]]></title>
            <link>https://medium.com/@bryanfillmer/static-success-with-hugo-part-i-2cb02369627a?source=rss-7e8a50ebe597------2</link>
            <guid isPermaLink="false">https://medium.com/p/2cb02369627a</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[tech]]></category>
            <dc:creator><![CDATA[Bryan Fillmer]]></dc:creator>
            <pubDate>Mon, 13 Jul 2020 14:34:38 GMT</pubDate>
            <atom:updated>2020-07-15T19:54:27.905Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d4KEoK3koY5UuA0QjpxPDg.jpeg" /></figure><p><em>Original story published at </em><a href="https://fillmerinnovationgroup.com/"><em>Fillmer Innovation Group</em></a></p><p>When it came time to do our recent rebuild of the FIG website, we were faced with the decision of deciding what tech stack to use to manage our content. The temptation was to use something like <a href="https://flamelink.io/">Flamelink</a>, which we love (more on this in a future article), or any other CMS solution. There came a time in the initial discussion where the <a href="https://en.wikipedia.org/wiki/You_aren%27t_gonna_need_it">YAGNI</a> principle was broached, and that maybe a full CMS was overkill for our needs. It was agreed that a static site generator would be the way to go.</p><p>Once we made the choice to reduce the complexity of our project we jumped at the chance to use something that we had never used before to get the job done. Enter <a href="http://gohugo.io/">Hugo</a>. In the past we had used the <a href="https://www.gatsbyjs.org/">usual</a> <a href="http://wintersmith.io/">suspects</a> of Javascript static site generators, the chance to play around with <a href="https://golang.org/">Go</a> instead definitely appealed to our eternally curious developer side.</p><p>Hugo’s claim to fame is speed, and it is certainly fast. A build of this site averages <strong>3ms</strong> at the time of this writing, which is fantastic, and a great perk of using the framework. It was also very quick to get up and running. This redesign of our site took about three billable days worth of work, only the first of which was getting Hugo up and running. The rest of that time was spent endlessly tweaking CSS until everything was just right.</p><p>However, not everything went smoothly. Hugo’s documentation can be somewhat confusing, and the terminology for concepts was fairly specific and opaque coming from outside the community. A fair amount of that initial setup time was spent digging through Stack Overflow posts and doing some trial and error until we got things working the way we wanted. Over the next few articles we will explore some of the <strong>gotchas</strong> we ran into, and the solutions that we found.</p><p><em>*If you liked what you read and want more information about our company please visit </em><a href="https://fillmerinnovationgroup.com/"><em>Fillmer Innovation Group</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2cb02369627a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Boys & Bluegills]]></title>
            <link>https://medium.com/@bryanfillmer/boys-bluegills-29c5b621fb5?source=rss-7e8a50ebe597------2</link>
            <guid isPermaLink="false">https://medium.com/p/29c5b621fb5</guid>
            <category><![CDATA[family]]></category>
            <category><![CDATA[fly-fishing]]></category>
            <category><![CDATA[fishing]]></category>
            <category><![CDATA[children]]></category>
            <dc:creator><![CDATA[Bryan Fillmer]]></dc:creator>
            <pubDate>Tue, 07 May 2019 12:43:25 GMT</pubDate>
            <atom:updated>2019-05-07T12:43:25.941Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vK902ASN07K24SUJZapWlA.jpeg" /></figure><p>It was hot, but it had been a long winter and we were more grateful than annoyed.</p><blockquote>“Dad, this is like an obstacle course!”</blockquote><p>It is possible the boy has seen too many ninja warrior videos, likening our winding path through the cottonwoods to an athletic competition. It was a long winter; trapped inside, forgetting what it is like to find your own way to hidden water.</p><blockquote>“Dad, isn’t this just like an obstacle course?”</blockquote><p>Of course it is also possible that getting skunked so far has led the boy to enjoy clambering over trees and the winding route of the trail more than the fishing. It was a long winter and our casts look more like arcs than lines, and the fish seem to have noticed.</p><blockquote>“Dad, can I fish your spot?”</blockquote><p>At the end of the trail, which really was more of an obstacle course, a shimmering pond and a promising inlet. After a few casts the spot is relinquished. It was a long winter and it is enough to be fishing, catching can come later.</p><blockquote>“Dad, I got one! It’s huge! I caught the fish of the day!”</blockquote><blockquote>“Yes you did son, yes you did.”</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29c5b621fb5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[New Context API & View Logic]]></title>
            <link>https://medium.com/@bryanfillmer/new-context-api-view-logic-c41eb63bd8d3?source=rss-7e8a50ebe597------2</link>
            <guid isPermaLink="false">https://medium.com/p/c41eb63bd8d3</guid>
            <category><![CDATA[context]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[jsx]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Bryan Fillmer]]></dc:creator>
            <pubDate>Wed, 23 May 2018 00:24:50 GMT</pubDate>
            <atom:updated>2018-05-23T00:24:50.965Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ghBSLV7iidu2hZmCH4Hfjw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/IVHzN57dnuM?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Ali Morshedlou</a> on <a href="https://unsplash.com/search/photos/loading?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>The new Context API introduced in <a href="https://github.com/facebook/react/blob/master/CHANGELOG.md#1630-march-29-2018">React 16.3</a> has made quite a stir in the React community. Some are underwhelmed, some are claiming the upcoming death of Redux. Regardless, I prefer to focus on useful applications of the new pattern.</p><p>As I have begun using the new Context API I have found that I turn to it more and more to perform small, contained, <strong>view logic </strong>tasks. Some simple reusable patterns, such as <em>tabs</em> &amp; <em>modals</em>, lend themselves very well to the Context pattern.</p><h4>The Problem</h4><p>As is common in an administrative UI there are many screens that are lists of data. In a recent project our list views could be in any of <em>three</em> states: loading, loaded with no data, or loaded with data. Using basic control structures in our JSX we end up with quite a few views that contain some variation on the following:</p><pre>// Data is falsy, show Loading.<br>// Data is an empty array show &lt;NoData /&gt;.<br>// Data is array of actual items, show &lt;List /&gt;.<br>function IRecieveData ({data}) {<br>  return (<br>    &lt;Section&gt;<br>      {!data &amp;&amp; &lt;Loading /&gt;}<br>      {(data &amp;&amp; data.length === 0) &amp;&amp; &lt;NoData /&gt;}<br>      {(data &amp;&amp; data.length &gt;= 1) &amp;&amp; &lt;List data={data} /&gt;}<br>    &lt;/Section&gt;<br>  )<br>}</pre><p>Nothing too crazy here, and it is simple and readable. However when we began copy and pasting multiple times throughout our application we knew it was time to generalize it and create a pattern. In our particular use-case we knew that all data coming from Redux would either be null, an empty array, or an array of items.</p><h4>The Solution</h4><pre>function IRecieveData ({data}) {<br>  return (<br>    &lt;Section&gt;<br>      &lt;Switch data={data}&gt;<br>        &lt;Switch.Loading render={Loading} /&gt;<br>        &lt;Switch.NoData render={NoData} /&gt;<br>        &lt;Switch.Data render={List} /&gt;<br>      &lt;/Switch&gt;<br>    &lt;/Section&gt;<br>  )<br>}</pre><p>We have essentially taken our basic Javascript control structures, wrapped them with JSX; and leveraged the Context API to avoid passing data along to each component via props. What have we gained?</p><ol><li>Consistency in reuse. When leveraging this pattern in a new view simply making sure that data is mapped correctly is all that is necessary.</li><li><em>It’s all JSX. </em>JSX is readable, and React developers are used to reading it. This adds clarity to our code at a glance, without needing to understand the underlying data shape.</li></ol><h4>Etc.</h4><p>An implementation of this pattern can be found on Github at <a href="https://github.com/bfillmer/loading-view-logic">https://github.com/bfillmer/loading-view-logic</a>.</p><p>As with most patterns in the React eco-system, this is not appropriate for every use-case, there is no one-size fits all pattern for handling this type of repetitive pattern.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c41eb63bd8d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reducer Snapshots for Rapid Development]]></title>
            <link>https://medium.com/@bryanfillmer/reducer-snapshots-for-rapid-development-2ede745b8c40?source=rss-7e8a50ebe597------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ede745b8c40</guid>
            <category><![CDATA[jest]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[redux]]></category>
            <dc:creator><![CDATA[Bryan Fillmer]]></dc:creator>
            <pubDate>Mon, 18 Sep 2017 12:25:48 GMT</pubDate>
            <atom:updated>2017-09-18T12:27:32.988Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OqpCleIhSb1U9LyT-eY8hQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/wunVFNvqhfE?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Sabri Tuzcu</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Test Driven Design (TDD) is a great way to ensure that you are getting the expected behavior from any given piece of code.</p><p>When writing tests I follow Eric Elliott’s advice in <a href="https://medium.com/javascript-scene/tdd-the-rite-way-53c9b46f45e3">TDD the Rite Way</a> and favor equality tests as much as possible. A test written this way, with explicit expected results, is easier to reason about, reduces edge cases, and documents the codebase.</p><p>Redux reducers lend themselves well to this development pattern. As our reducers are pure functions we can simply define inputs and outputs and run our function. An example, written using <a href="https://facebook.github.io/jest/">Jest</a>:</p><pre>/* global describe, test, expect */</pre><pre>import {action, initialState, reducer} from &#39;state&#39;<br></pre><pre>describe(&#39;reducer&#39;, () =&gt; {<br>  test(&#39;handles ACTION_TYPE correctly&#39;, () =&gt; {</pre><pre>    const name = &#39;A Name&#39;</pre><pre>    const expected = {<br>      name,<br>      description: &#39;Some data that should not change.&#39;<br>    }</pre><pre>    const actual = reducer(initialState, action(name))</pre><pre>    expect(actual).toEqual(expected)<br>  })<br>})</pre><p>Simple and readable, we know exactly what the reducer should return when running the action mapped to ourACTION_TYPE.</p><p>There is a downside to this, specially when iterating quickly through a prototype or MVP: writing out the full expected shape for any given part of our application state can take some time.</p><p>The example above has state that is rather trivial and thus the test is not particularly lengthy. When leveraging Redux in production, and in particular when attempting to keep our state normalized and as flat as possible, the opposite quickly becomes the case.</p><h4>Jest Snapshots to the Rescue</h4><p>Jest comes with a handy feature called <a href="https://facebook.github.io/jest/docs/en/snapshot-testing.html">Snapshot Testing</a>. Essentially what snapshots do are create a JSON schema representation of whatever you pass in and do future comparisons against that representation.</p><p>Although commonly demonstrated as a clever way to test React components they also happen to be useful for testing reducers. First, the above test written with snapshots:</p><pre>/* global describe, test, expect */</pre><pre>import {action, initialState, reducer} from &#39;state&#39;</pre><pre>describe(&#39;reducer&#39;, () =&gt; {<br>  test(&#39;handles ACTION_TYPE correctly&#39;, () =&gt; {</pre><pre>    const actual = reducer(initialState, action(&#39;A Name&#39;))</pre><pre>    expect(actual).toMatchSnapshot()<br>  })<br>})</pre><p>Given the brevity of our reducer this does not seem like much of a gain, at least in lines of code. Lines of code savings do start to accumulate over time, however the big gain here is in maintainability and speed of development.</p><p>Setting up the test in this manner lets us get back to creating our reducer quickly. Tabbing over to the terminal, where we naturally have Jest running in watch-mode, allows us to watch the snapshot changes as we iterate on the logic contained within reducer.</p><p>Once the state shown in the snapshot reflects what we expect to see we simply update the snapshot and now have a baseline from which to compare any future changes.</p><p>A more complete example of using this pattern can be found at <a href="https://github.com/bfillmer/todo-and-tonic/blob/master/src/state/reducers/todos.spec.js">todo-and-tonic/todos.spec.js</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ede745b8c40" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Try Again: More Redux Saga Patterns]]></title>
            <link>https://codeburst.io/try-again-more-redux-saga-patterns-bfbc3ffcdc?source=rss-7e8a50ebe597------2</link>
            <guid isPermaLink="false">https://medium.com/p/bfbc3ffcdc</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[redux-saga]]></category>
            <dc:creator><![CDATA[Bryan Fillmer]]></dc:creator>
            <pubDate>Thu, 31 Aug 2017 13:45:26 GMT</pubDate>
            <atom:updated>2017-09-02T12:52:35.026Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oG-nKHXAHsXGlhuylKgE6A.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/hsztMXLuC6s?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Tim Arterbury</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>In my previous article <a href="https://medium.com/@bryanfillmer/keep-trying-redux-saga-style-b273882b9ec">Keep Trying: Redux Saga Style</a> we focused on the ability to have a saga cleanly handle errors and continue to attempt an API call in the event of failure. Although useful, there are other extensions of this pattern that provide a bit more value; let’s take a look at a few.</p><h4>Max Tries</h4><p>There is one major issue with the autoRestart concept: in the case that an API is completely down you will still attempt to reconnect infinitely:</p><pre>const <strong>autoRestart</strong> = (generator, handleError) =&gt; {<br>  return function * <strong>autoRestarting</strong> (...args) {<br>    while (true) {<br>      try {<br>        yield <strong>call</strong>(generator, ...args)<br>        break<br>      } catch (e) {<br>        yield <strong>handleError</strong>(e)<br>      }<br>    }<br>  }<br>}</pre><p>Leveraging the above to wrap potential problem areas and prevent them from crashing your entire application is still useful, but for an API call we may want to do something more like the following:</p><pre>const <strong>log</strong> = function () { ... }</pre><pre>const <strong>multipleAttempts</strong> = (generator, handleError, maxTries) =&gt; {<br>  return function * <strong>multipleAttempts</strong> (...args) {<br>    let n = 0<br>    while (n &lt;= maxTries) {<br>      try {<br>        yield <strong>call</strong>(generator, ...args)<br>        break<br>      } catch (e) {<br>        // Log errors here until maxTries has been hit, to prevent<br>        // spamming the user with messages.<br>        if (n &lt; maxTries) {<br>          yield <strong>log</strong>(e)<br>        } else {<br>          yield <strong>handleError</strong>(e)<br>        }<br>      }<br>    }<br>  }<br>}</pre><p>In this case we simply pass along the number of times we want to attempt to connect to the API. In the event that we were unable to connect handleError is invoked, in which we setup our UI state to display the appropriate information to the user.</p><h4>Time Based Attempts</h4><p>I particularly like this pattern because it elegantly handles a slow connection or a user that is offline. We attempt to connect however many times we can in a given time period, then in the event that a successful connection never occurred we can treat our application as offline and handle it appropriately.</p><p>Rather than wrap an individual API call we will have this particular piece of code handle all of our API calls for this particular application.</p><pre>import {<br>  hydrateUserData, hydrateListData, setApplicationToOffline<br>} from &#39;actions&#39;</pre><pre>// 30 seconds max load<br>const maxLoadTime = 1800</pre><pre>// Fetch the data our application needs and store it in local state.<br>function * <strong>fetchData</strong> () {<br>  const {userData, listData} = yield <strong>all</strong>({<br>    userData: <strong>call</strong>(getUserData),<br>    listData: <strong>call</strong>(getListData)<br>  })<br>  // Store or retrieved data in our Redux state.<br>  yield [<br>    <strong>put</strong>(<strong>hydrateUserData</strong>(userData)),<br>    <strong>put</strong>(<strong>hydrateListData</strong>(listData))<br>  ]<br>  return true<br>}</pre><pre>// If our application is offline set some state that will disable<br>// UI features and notify the user.<br>function * <strong>setOfflineState</strong> () {<br>  yield put(<strong>setApplicationToOffline</strong>())<br>}</pre><pre>// Attempt to load our application data in a fixed amount of<br>// time, otherwise default to offline mode.<br>function * <strong>loadApplication </strong>(loadTime, fetchData, setOfflineState) {<br>  const {offline, online} = yield <strong>race</strong>({<br>    offline: <strong>delay</strong>(loadTime, true),<br>    online: <strong>call</strong>(fetchData)<br>  })<br>  // Time won our race, thus fetchData never resolved in our<br>  // required time and we should treat the application as offline.<br>  if (offline) {<br>    yield <strong>call</strong>(setOfflineState)<br>  }<br>}</pre><p>There is a lot going on here, so let’s break it down:</p><ol><li>First we establish a function to handle our data needs. In this case, two API calls need to be made to get our user data and some generic list data. Once said data is retrieved we store it in our Redux state and return true.</li><li>We also have a small generator to set whatever necessary state our UI requires to render in offline mode.</li><li>Finally we define our logic for loading the application. We leverage redux-saga’s race effect to run our two generators. The delay helper simply returns a promise at the end of the time passed to it. The winner of the race will be available immediately after the race yields. In this instance we are not performing any additional work if online wins, but if offline wins we definitely want to put the application in offline mode.</li></ol><p>Being able to present the user with a pared down version of your application is just plain good UX. Your offline version of the application can then contain messaging regarding the minimal state as well as the ability for the user to fire loadApplication to effectively go online.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bfbc3ffcdc" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/try-again-more-redux-saga-patterns-bfbc3ffcdc">Try Again: More Redux Saga Patterns</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Keep Trying: Redux Saga Style]]></title>
            <link>https://medium.com/@bryanfillmer/keep-trying-redux-saga-style-b273882b9ec?source=rss-7e8a50ebe597------2</link>
            <guid isPermaLink="false">https://medium.com/p/b273882b9ec</guid>
            <category><![CDATA[redux-saga]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Bryan Fillmer]]></dc:creator>
            <pubDate>Sat, 26 Aug 2017 20:16:05 GMT</pubDate>
            <atom:updated>2018-01-26T16:03:58.072Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uBAQdHEdDICMJPJULT00lw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/2DmONVWZeaE?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Quino Al</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>With <a href="https://redux-saga.js.org/">redux-saga</a> we are able to create what are effectively imperative threads in our front-end applications that control user flow and generally handle our side-effects. Since side-effects are often a point of failure in front-end applications it is not uncommon to see the use of try/catch blocks like so:</p><pre>function* fetchProducts() {<br>  try {<br>    const products = yield call(Api.fetch, &#39;/products&#39;)<br>    yield put({ type: &#39;PRODUCTS_RECEIVED&#39;, products })<br>  }<br>  catch(error) {<br>    yield put({ type: &#39;PRODUCTS_REQUEST_FAILED&#39;, error })<br>  }<br>}</pre><p>Although the above is a great pattern, and allows us to build an intelligent UI that can display to the user that something went wrong, the fact remains that the user is sitting on an empty products page.</p><p>What if we wanted to keep trying to acquire products? Essentially, what if we wanted to automatically restart this particular part of our codebase in the event that something has gone wrong?</p><p>Let us also assume that this is a pattern we will want to reuse. Wrapping potential trouble areas in our codebase to prevent the codebase from becoming unresponsive is a handy thing.</p><p>Enter our autoRestart higher-order function:</p><pre>// Pass in our generator we want to restart, and some function<br>// to handle potential errors thrown within said generator.<br>const autoRestart = (generator, handleError) =&gt; {<br>  return function * autoRestarting (...args) {<br>    while (true) {<br>      try {<br>        yield call(generator, ...args)<br>        break<br>      } catch (e) {<br>        yield handleError(e)<br>      }<br>    }<br>  }<br>}</pre><p>Using this with our fetchProducts saga above is easy enough, with one modification to have our fetchProducts throw an error when failing:</p><pre>const fetchProducts = autoRestart(<br>  function * fetchProducts () {<br>    try {<br>      const products = yield call(Api.fetch, &#39;/products&#39;)<br>      yield put({ type: &#39;PRODUCTS_RECEIVED&#39;, products })<br>    }<br>    catch(error) {<br>      throw new Error(error)<br>    }<br>  },<br>  function * handleError (e) {<br>    yield put({ type: &#39;PRODUCTS_REQUEST_FAILED&#39;, e })<br>  }<br>)</pre><p>In essence this will continue to attempt to reconnect to the API to get our products until it is successful. The beauty of redux-saga is definitely in the ability to control user flow, both the <em>“happy path”</em> that we hope the user experiences, and in the event of a failure of any part of the system.</p><p>Although outside the scope of this article, we could have our Api.fetch return a server error that is handled as well, or create scenarios where we want to break out of our restarting loop depending on the error type.</p><p>A simple running example of this pattern can be found at <a href="https://github.com/bfillmer/saga-restart">bfillmer/saga-restart</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b273882b9ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Power of Now]]></title>
            <link>https://medium.com/@bryanfillmer/the-power-of-now-fc541d209fc6?source=rss-7e8a50ebe597------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc541d209fc6</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[zeit]]></category>
            <category><![CDATA[static-site]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Bryan Fillmer]]></dc:creator>
            <pubDate>Fri, 18 Aug 2017 21:27:53 GMT</pubDate>
            <atom:updated>2017-08-18T21:27:53.555Z</atom:updated>
            <content:encoded><![CDATA[<p>As a developer I need to iterate quickly on a project. Over time the community has come up with many ways to improve and speed up the development experience. Linters, IDEs, type-checking, and auto-reloading development servers are a few examples.</p><p>But why is deploying my current work-in-progress, let alone a new version of my application, so tedious?</p><p>Apparently the team at <a href="http://zeit.co/">ZEIT</a> felt the same, and did something about it. <a href="https://zeit.co/now"><strong>Now</strong></a> is a simple command-line tool for rapid deployment. Need to show a client progress on a new feature you have been working on? You can quite literally do that in one line.</p><p><strong>Now</strong> has dramatically improved my process for working with clients and providing transparency into the ongoing work being done. It also happens to be pretty amazing for deploying new versions of applications, or rolling back when something goes wrong. Which never happens, obviously.</p><p>So what does this look like in practice? Let’s take a look.</p><h4>Setting the Stage</h4><p>For this we’ll be updating my personal site, <a href="http://bryanfillmer.com/">bryanfillmer.com</a> to include a link to Twitter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WkzuCWkCtVmQBD6CBrtwDw.png" /><figcaption>Pre-Twitter</figcaption></figure><p>Naturally, this being a developer’s website, it’s more complicated than it should be. Currently it is a React application when it has no business being more than a static site. I regret nothing.</p><p>Since this is about leveraging <strong>Now</strong> for quick and easy deployments we will skip over the actual code changes made. Suffice it to say that the code has been changed and a link to Twitter added. (The codebase for my personal site is available at <a href="https://github.com/bfillmer/bryanfillmer.com">bfillmer/bryanfillmer.com</a>.</p><h4>Deploy, Verify, and Beyond</h4><p><strong>Now</strong> has a simple command to check the current deployments I have, so let’s do that first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NWSCR-pMCH9xDrokfy5u6Q.png" /><figcaption>Six whole days since I last updated.</figcaption></figure><p>As we can see I have one existing deployment, which happens to be the live site currently aliased to <a href="http://bryanfillmer.com/">bryanfillmer.com</a>. As I am ready to deploy a new instance I simply type the command now from my project directory and watch the magic happen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pxw7Bc9ucpEhSA77G9GhdA.png" /><figcaption>create-react-app ftw</figcaption></figure><p>After the build another quick check of my active deployments:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wD4sVm1o_kqV73AffRLA0g.png" /></figure><p>Now we see a second deployment with a randomly generated URL. In a pleasant twist of good UX the URL for the new deployment was copied to the clipboard automatically. We go to the URL to verify that the site looks as it should:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1iF0BWNPWEtqKym7PpMM-w.png" /><figcaption>Complex site is complex.</figcaption></figure><p>Looks like everything went great. At this point we have spent about two minutes deploying what is effectively a staging environment, verified that the changes made to the application are what we expected, and we are ready to go live. <strong>Now</strong> makes that easy as well, simply running the now alias command we point our domain name to the new deployment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dhp16pwEm3Esodk_7Zz_5Q.png" /><figcaption>Shipped.</figcaption></figure><p>After about 30 seconds our new deployment is now the production environment and we can shutdown our previous deployment.</p><h4>In Closing</h4><p>Being able to easily spin up a new deployment at any time from the command line is a great addition to the developer experience. Oh, and <strong>Now</strong> is <a href="https://github.com/zeit/now-cli">open source too</a>, which is pretty sweet. In the end I have found Now to be an indispensable addition to my development workflow.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc541d209fc6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Redux First Router Saga]]></title>
            <link>https://medium.com/@bryanfillmer/a-redux-first-router-saga-67c2cda9252e?source=rss-7e8a50ebe597------2</link>
            <guid isPermaLink="false">https://medium.com/p/67c2cda9252e</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[redux-first-router]]></category>
            <category><![CDATA[redux-saga]]></category>
            <dc:creator><![CDATA[Bryan Fillmer]]></dc:creator>
            <pubDate>Wed, 09 Aug 2017 01:25:52 GMT</pubDate>
            <atom:updated>2018-01-26T16:04:19.965Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nq0grwPQXlQu0A7ZKlGjMQ.png" /><figcaption>Photo by <a href="https://unsplash.com/photos/8peGuud5cEw?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Martin Sattler</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Routing in React never sat well with me. Any solution that has you declare your routing with React components is asking React to manage concerns that are not related to the view layer.</p><p>I firmly believe that routes are simply state; that the fact that they usually map to browser URLs is simply a side-effect, and as such they should not be managed within our React code. With this in mind I set out to create a solution that matches this way of thinking.</p><p>At first I used a hand-rolled <a href="https://github.com/redux-saga/redux-saga">redux-saga</a> system to manage all routing with sagas. This achieves the desired effect of allowing complete control over showing loaders, loading data, and then loading our views. Ultimately this more tightly coupled the view layer to my sagas than I would have liked.</p><p>Then along came <a href="https://github.com/faceyspacey/redux-first-router">redux-first-router</a>, and a better way of doing things. The end-goal is simple: have views be aware of how they map to a particular route, have sagas be aware of how they map to a particular route, then simply define the routes as state. Something like this:</p><pre>src/<br>|- state/<br>|  |_ sagas/<br>|  |  |_ routes.js // Our routes to sagas mapping.<br>|  |<br>|  |_ routes.js    // Our routes to state definitions.<br>|<br>|_ view/<br>   |_ Routes.js    // Our routes to views mapping.</pre><p>When defining our system this way we gain a few things:</p><ul><li>Decoupling our views and side-effects from each other.</li><li>The ability to have routes that have no UI, such as an authentication callback, and logically not have the view layer be aware that such a route exists.</li><li>We can change our actual URLs by updating a simple map inside state/routes.js without having to manipulate our sagas or React components.</li></ul><h3>In Practice</h3><p>Let’s start with the library wiring. For the purposes of this tutorial we will assume that you have the necessary dependencies installed. All the code used in this article can be found on Github at <a href="https://github.com/bfillmer/redux-routing-and-more"><em>bfillmer/redux-routing-and-more</em></a><em>,</em> and can be played with at <a href="https://codesandbox.io/s/Y6v89MErM">https://codesandbox.io/s/Y6v89MErM</a><em>.</em></p><h4>Wiring</h4><p>src/state/routes.js</p><pre>import {connectRoutes} from &#39;redux-first-router&#39;<br>import createHistory from &#39;history/createBrowserHistory&#39;<br><br>const {ROUTE_HOME, ROUTE_ABOUT} from &#39;types&#39;<br><br>const routesMap = {<br>  [ROUTE_HOME]: &#39;/&#39;,<br>  [ROUTE_ABOUT]: &#39;/about&#39;<br>}<br><br>const history = createHistory()<br><br>export const {<br>  reducer,<br>  middleware,<br>  enhancer<br>} = connectRoutes(history, routesMap)</pre><p>We would like to work in a type-based system, so we define some types that represent our routes. These will be used later by our sagas and views to load the appropriate parts of our application. After this we create and export our reducer, middleware, and enhancers from redux-first-router. We won’t go into why all three are created or how they are connected to the store, that information can be found in the redux-first-router <a href="https://github.com/faceyspacey/redux-first-router/blob/master/docs/connectRoutes.md">documentation</a>.</p><h4>React Visuals</h4><p>src/view/Routes.js</p><pre>import React from &#39;react&#39;<br>import {connect} from &#39;react-redux&#39;<br>import {NOT_FOUND} from &#39;redux-first-router&#39;<br><br>import {routeType} from &#39;selectors&#39;<br>import {ROUTE_HOME, ROUTE_ABOUT} from &#39;types&#39;</pre><pre>// View Components<br>import {About} from &#39;view/About&#39;<br>import {Home} from &#39;view/Home&#39;<br><br>const routesMap = {<br>  [ROUTE_HOME]: Home,<br>  [ROUTE_ABOUT]: About,<br>  [NOT_FOUND]: Home<br>}<br><br>const mapStateToProps = state =&gt; ({<br>  route: state =&gt; state.location.type<br>})<br><br>const Container = ({route}) =&gt; {<br>  const Route = routesMap[route]<br>    ? routesMap[route]<br>    : routesMap[NOT_FOUND]</pre><pre>  return (<br>    &lt;Route /&gt;<br>  )<br>}<br><br>export const Routes = connect(mapStateToProps)(Container)</pre><p>Now we map our view components to our types. We use the special NOT_FOUND type from redux-first-router so we always have some UI to show regardless of our current application state. Add some Redux wiring to get the current state type and we are done. Our App.js file simply loads our &lt;Routes /&gt;:</p><p>src/view/App.js</p><pre>import React from &#39;react&#39;<br><br>import {Routes} from &#39;view/Routes&#39;<br><br>export const App = () =&gt; (<br>  &lt;Routes /&gt;<br>)</pre><p>In the case that we might have multiple areas of our UI respond to route changes differently, say a primary content area and a sidebar, we simply create multiple maps of types to views and easily gain independently updating UI areas.</p><p>At this point routing is viable in our application, booting up and going to our two routes, / and /about will render our Home and About components as expected. Quite often our applications are not quite that simple, and we need to perform some type of data loading or other state management either before or concurrently with loading our view.</p><h4>Sagas</h4><p>src/state/sagas/routes.js</p><pre>import {spawn, takeEvery} from &#39;redux-saga/effects&#39;<br><br>import {ROUTE_HOME} from &#39;types&#39;<br><br>// Route Sagas<br>import {loadHome} from &#39;state/sagas/home&#39;</pre><pre>// Routes that require side effects on load are mapped here.<br>const routesMap = {<br>  [ROUTE_HOME]: loadHome<br>}<br><br>// Spawn the saga associated with the route type.<br>function * handleRouteChange ({type}) {<br>  yield spawn(routesMap[type])<br>}<br><br>// Watch for all actions dispatched that have an action type in<br>// our routesMap.<br>export function * routes () {<br>  yield takeEvery(Object.keys(routesMap), handleRouteChange)<br>}</pre><p>This saga watches for any actions that are dispatched to Redux that match an action type mapped in our routeMap. If one exists it creates a non-blocking thread (of sorts) and then resumes watching for the next action type. The beauty of this system is that we can now pick and choose what routes we need to have side-effects for and instantiate them by coupling to the correct route type. No touching our view layer, or binding directly to the url we happen to be using at the time.</p><p>src/state/sagas/home.js</p><pre>import {delay} from &#39;redux-saga&#39;</pre><pre>// Here we would do checks for existing data and load whatever<br>// we need for this view. Also manage generic tasks such as <br>// showing/hiding loaders based on UI needs.<br>export function * loadHome () {<br>  yield delay(1000)<br>  yield console.log(&#39;Just Finished a Super Long API Call&#39;)<br>}</pre><p>Finally the loadHome saga takes over and is fully in charge of what should happen in order to retrieve whatever data we require when the ROUTE_HOME action has fired. This could include triggering a state change that displays a loader, checking if some data exists, loading said data if it doesn’t, and hiding the loader.</p><h4>In Closing</h4><p>This pattern is the best way I have found so far to handle routing, side-effects, and cleanly coupling the various pieces involved in routing with a React-based application. Many thanks to <a href="https://medium.com/u/a4a87902fa2d">James Gillmore</a> for creating <a href="https://github.com/faceyspacey/redux-first-router">redux-first-router</a>.</p><p>All the code for this tutorial can be found on Github at <a href="https://github.com/bfillmer/redux-routing-and-more">bfillmer/redux-routing-and-more</a> and played with at<em> </em><a href="https://codesandbox.io/s/Y6v89MErM">https://codesandbox.io/s/Y6v89MErM</a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67c2cda9252e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>