<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://www.ryanwill.dev/feed.xml" rel="self" type="application/atom+xml" /><link href="https://www.ryanwill.dev/" rel="alternate" type="text/html" /><updated>2026-04-10T21:51:49+00:00</updated><id>https://www.ryanwill.dev/feed.xml</id><title type="html">RyanWillDev</title><subtitle>Cultivating ideas and software with varying degrees of success</subtitle><author><name>Ryan Will</name></author><entry><title type="html">Interpret the Errors</title><link href="https://www.ryanwill.dev/rants/error-messages" rel="alternate" type="text/html" title="Interpret the Errors" /><published>2018-07-21T00:00:00+00:00</published><updated>2018-07-21T00:00:00+00:00</updated><id>https://www.ryanwill.dev/rants/error-messages</id><content type="html" xml:base="https://www.ryanwill.dev/rants/error-messages"><![CDATA[<div class="image-container">
 <img src="/assets/img/read-errors.png" />
</div>

<p>I was thinking recently about how intimidated I was by error messages when I first began to program.
As soon as red text appeared in the browser console or terminal I would begin to feel a little panicked.
My heart rate would rise in proportion to the length of the stack trace.
But somewhere along the way that intimidation just began to vanish.</p>

<p>The change started when I actually stopped to read and attempted to make sense of the errors instead of blindly trying
things until they went away.
I began to think of the computer more as a non native speaker trying to communicate with only a few rehearsed
phrases at its disposal and less like an evil being whose sole enjoyment in life is giving me unsolvable riddles in
cryptic and impenetrable language.</p>

<p>It’s trying to tell you that something went wrong, but it can only choose from a few pre-programmed messages.
The good news is computers are logical. They will never tell you something is wrong for no reason.
Although sometimes it seems like they do. The bad news is that means it’s always your fault.</p>

<p>It’s true. Undefined <strong>really</strong> isn’t a function.</p>

<p>The next time you see an error message don’t recoil in fear.
Instead, read the error message, follow the stack trace, and try to decipher exactly what it is telling you.
The more you do this the better you’ll become at interpreting what the computer is actually trying to tell you.</p>]]></content><author><name>Ryan Will</name></author><category term="development" /><summary type="html"><![CDATA[The first emotion to seeing an error message or stack trace is usually intimidation. Instead, be curious to find out exactly what the computer is trying to tell you.]]></summary></entry><entry><title type="html">React Calendario</title><link href="https://www.ryanwill.dev/rants/react-calendario" rel="alternate" type="text/html" title="React Calendario" /><published>2018-06-23T00:00:00+00:00</published><updated>2018-06-23T00:00:00+00:00</updated><id>https://www.ryanwill.dev/rants/react-calendario</id><content type="html" xml:base="https://www.ryanwill.dev/rants/react-calendario"><![CDATA[<p>While there are plenty of great solutions for creating a date picker or calendar in React already, most have very limited
options for choosing how and what to render.
I wanted a React component with a simple API for creating internationalized calendars and date pickers,
while allowing complete freedom to structure and style what was rendered by the component.
So, I created and published my first npm package, <a href="https://www.npmjs.com/package/@ryanwilldev/react-calendario">react-calendario</a>.
Below is a very basic example.</p>

<iframe src="https://codesandbox.io/embed/w242rok578?view=preview" style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe>

<h2 id="customization">Customization</h2>

<p>react-calendario takes advantage of the powerful <a href="https://reactjs.org/docs/render-props.html">Render Prop</a> pattern allowing the consumer to customize and style the calendar or date picker however they like.
Unlike passing configuration props to traditional components or the Higher Order Component pattern the Render Prop pattern
allows the consumer of the component to customize and style the JSX returned by a component however they like.</p>

<p>react-calendario expects a function that returns JSX either as a prop named render or as its only child.
react-calendario calls the provided function in its own render method passing to it all the necessary logic to create the
calendar or date picker component as arguments.</p>

<p>You can read more about the arguments passed to the function <a href="https://github.com/RyanWillDev/react-calendario#render-function-props">here</a>.</p>

<h2 id="internationalization">Internationalization</h2>

<p>I am particularly excited about react-calendario’s support for Internationalization.
Using the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat">Intl.DateTimeFormat</a>
API react-calendario can support all the languages supported by a user’s browser.
To configure the language react-calendario will use just pass a supported browser language code as the language prop.
If the language code is invalid or absent, react-calendario will fallback to the browser’s language.</p>

<h2 id="inspiration">Inspiration</h2>

<p>The inspiration for using the Render Prop pattern as well as the layout of react-calendario’s README were inspired
by the awesome work done by Kent C. Dodds and others on <a href="https://github.com/paypal/downshift">downshift</a>.
Keep up the great work!</p>]]></content><author><name>Ryan Will</name></author><category term="react" /><category term="javascript" /><summary type="html"><![CDATA[Developing a flexible and highly customizable React component that provides the base calendar functionality for creating internationalized calendars or date pickers.]]></summary></entry><entry><title type="html">The case for ternaries</title><link href="https://www.ryanwill.dev/rants/case-for-ternaries" rel="alternate" type="text/html" title="The case for ternaries" /><published>2018-02-17T00:00:00+00:00</published><updated>2018-02-17T00:00:00+00:00</updated><id>https://www.ryanwill.dev/rants/case-for-ternaries</id><content type="html" xml:base="https://www.ryanwill.dev/rants/case-for-ternaries"><![CDATA[<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nx">ifTrue</span> <span class="p">?</span> <span class="dl">'</span><span class="s1">I am true</span><span class="dl">'</span> <span class="p">:</span> <span class="dl">'</span><span class="s1">I am false</span><span class="dl">'</span><span class="p">;</span>
</code></pre></div></div>

<p>Umm… what is that?
That, my friend, is the conditional operator, or a ternary.
So named because it is made up of 3 parts.
The three parts are: the condition to be checked, the expression to be returned when the condition is true, and the expression to be returned when the condition
is false.</p>

<p>The ternary is an analog to the if/else statement with the only difference being a ternary is an expression, while an if/else block is a statement.
Okay. What exactly is the difference between an expression and a statement?</p>

<h2 id="expressions-vs-statements">Expressions vs Statements</h2>

<p>An expression is any piece of code that <strong>evaluates to a value</strong>.</p>

<p>A statement is essentially a series of actions for a program to perform that does not evaluate to a value.
Think of an loop or a conditional statement.</p>

<p>The key here is that expressions have to evaluate to a value, while statements never do.</p>

<p>This is clearly illustrated by comparing what happens when setting a variable to the result of a statement vs an expression.
In the following example <code class="language-plaintext highlighter-rouge">num</code> will have the value <code class="language-plaintext highlighter-rouge">2</code> after the expression <code class="language-plaintext highlighter-rouge">1 + 1</code> is evaluated.</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">num</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
</code></pre></div></div>

<p>Whereas the following will throw an error of unexpected token and your editor will most likely alert you that a statement was found where an expression was expected.
This is because an if/else block does not evaluate to a value.</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">a</span> <span class="o">=</span> <span class="k">if</span> <span class="p">(</span><span class="kc">true</span><span class="p">)</span> <span class="mi">1</span> <span class="o">+</span> <span class="mi">1</span>
  <span class="k">else</span> <span class="mi">2</span> <span class="o">+</span> <span class="mi">2</span><span class="p">;</span>
</code></pre></div></div>

<h2 id="setting-variables">Setting variables</h2>

<p>One simple use case for ternaries is setting a variable’s value based on a condition.
Without a ternary you would have to do something like this to conditionally set a variable.</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">num</span><span class="p">;</span>

<span class="k">if</span> <span class="p">(</span><span class="nx">someFlag</span><span class="p">)</span> <span class="p">{</span>
  <span class="nx">num</span> <span class="o">=</span> <span class="mi">4</span><span class="p">;</span>
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
  <span class="nx">num</span> <span class="o">=</span> <span class="mi">42</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>

<p>This could be condensed slightly by removing the curly braces.</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">num</span><span class="p">;</span>

<span class="k">if</span> <span class="p">(</span><span class="nx">someFlag</span><span class="p">)</span> <span class="nx">num</span> <span class="o">=</span> <span class="mi">4</span><span class="p">;</span>
<span class="k">else</span> <span class="nx">num</span> <span class="o">=</span> <span class="mi">42</span><span class="p">;</span>
</code></pre></div></div>

<p>Even that is less than ideal.
Instead we can use a ternary to check the flag and return the number we want from our expression.
That would look something like this.</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">num</span> <span class="o">=</span> <span class="nx">someFlag</span> <span class="p">?</span> <span class="mi">4</span> <span class="p">:</span> <span class="mi">42</span><span class="p">;</span>
</code></pre></div></div>

<h2 id="conditional-function-arguments">Conditional function arguments</h2>

<p>JavaScript does not allow you to write statements inside of the parens of a function call.
In order to pass different arguments to a function depending on some condtition, a similar method to the one used above could be used.
A variable could be set using if/else statements and then passed to the function.</p>

<p>A cleaner, more concise, and easier to follow method would be to use a ternary to pass the argument.</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nx">someFunctionCall</span><span class="p">(</span>
  <span class="nx">someCondition</span> <span class="p">?</span> <span class="mi">4</span> <span class="p">:</span> <span class="mi">42</span>
<span class="p">);</span>
</code></pre></div></div>

<h2 id="returning-expressions-from-functions">Returning expressions from functions</h2>

<p>The most beneficial place to use a ternary is in the return expression of a function.
The reason being that it helps you avoid errors.</p>

<p>What is the potential error in the following example?</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">function</span> <span class="nx">capitalize</span><span class="p">(</span><span class="nx">string</span><span class="p">)</span> <span class="p">{</span>
  <span class="k">if</span> <span class="p">(</span><span class="nx">string</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">return</span> <span class="nx">string</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">toUpperCase</span><span class="p">()</span> <span class="o">+</span> <span class="nx">string</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
  <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<p>It’s subtle and might not seem like a big deal, but if someone were to call the function above with an empty string the function would return <code class="language-plaintext highlighter-rouge">undefined</code>.
Which would really wreck someone’s day if they were chaining this function together with others.</p>

<p>This is because all functions in JavaScript return <code class="language-plaintext highlighter-rouge">undefined</code> unless they have an explicit return.
That is the <code class="language-plaintext highlighter-rouge">return</code> keyword with an expression afterward.</p>

<p>So, the issue here is that there is an if statement but no else case.
This is precisely why a ternary is so handy when conditionally returning a value from a function.</p>

<p>Remember, a ternary is made up of 3 parts.
It needs all of those parts to be a valid expression.
Therefore, when writing a ternary, the developer is forced to deal with the else case.</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">function</span> <span class="nx">capitalize</span><span class="p">(</span><span class="nx">string</span><span class="p">)</span> <span class="p">{</span>
  <span class="k">return</span> <span class="nx">string</span><span class="p">.</span><span class="nx">length</span>
    <span class="p">?</span> <span class="nx">string</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">toUpperCase</span><span class="p">()</span> <span class="o">+</span> <span class="nx">string</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
    <span class="p">:</span> <span class="nx">string</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>

<p>The next time you find yourself wanting to write an if statement to determine what to return from a function, just go ahead and use a ternary instead.</p>]]></content><author><name>Ryan Will</name></author><category term="javascript" /><summary type="html"><![CDATA[The conditional ternary operator can be a little off putting to some, but it is extremely useful. So, what is it and when should it be used?]]></summary></entry><entry><title type="html">The Meaning of Truth</title><link href="https://www.ryanwill.dev/rants/meaning-truth" rel="alternate" type="text/html" title="The Meaning of Truth" /><published>2018-02-10T00:00:00+00:00</published><updated>2018-02-10T00:00:00+00:00</updated><id>https://www.ryanwill.dev/rants/meaning-truth</id><content type="html" xml:base="https://www.ryanwill.dev/rants/meaning-truth"><![CDATA[<p>JavaScript not only has the boolean types <code class="language-plaintext highlighter-rouge">true</code> and <code class="language-plaintext highlighter-rouge">false</code>, but it also has the idea of truthy and falsy values.
That is non-boolean values can be coerced to a boolean value when evaluated in a boolean context.
This can be an unfamiliar idea to new developers or those coming from other languages.</p>

<h2 id="truthy-vs-falsy">Truthy vs Falsy</h2>

<p>In JavaScript all values that are not <code class="language-plaintext highlighter-rouge">""</code>, <code class="language-plaintext highlighter-rouge">undefined</code>,<code class="language-plaintext highlighter-rouge">null</code>,<code class="language-plaintext highlighter-rouge">0</code>,<code class="language-plaintext highlighter-rouge">NaN</code>, and, of course,<code class="language-plaintext highlighter-rouge">false</code>are considered true when evaluated as a boolean, that is placed in an<code class="language-plaintext highlighter-rouge">if</code> conditional.</p>

<p>For example the following will evaluate to true and the statement will be logged to the console.</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">if</span> <span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
  <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="dl">'</span><span class="s1">1 is true.</span><span class="dl">'</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>

<p>So, why is this useful? The idea of truthy and falsy can be taken advantage of to write simpler code.</p>

<p>Let’s say you have the following array.</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">arr</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">];</span>
</code></pre></div></div>

<p>If you wanted to do something with the array only if it has elements inside it, you could use a comparison operator like <code class="language-plaintext highlighter-rouge">&gt;=</code>
to check if the length of the array was greater than or equal to <code class="language-plaintext highlighter-rouge">1</code>.</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">if</span> <span class="p">(</span><span class="nx">arr</span><span class="p">.</span><span class="nx">length</span> <span class="o">&gt;=</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
  <span class="c1">// do stuff</span>
<span class="p">}</span>
</code></pre></div></div>

<p>This works but can be simplified by checking for a truthy or falsy value.
Knowing that any number other than <code class="language-plaintext highlighter-rouge">0</code> is truthy and that if the array is empty it’s length property will be <code class="language-plaintext highlighter-rouge">0</code>, the <code class="language-plaintext highlighter-rouge">if</code> can be
rewritten as the follows.</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">if</span> <span class="p">(</span><span class="nx">arr</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span> <span class="p">{</span>
  <span class="c1">// do stuff</span>
<span class="p">}</span>
</code></pre></div></div>

<h2 id="explicit-boolean-coercion">Explicit Boolean Coercion</h2>

<p>If you every need to convert a truthy or fasly value to a a boolean you can just add a <code class="language-plaintext highlighter-rouge">!!</code> in front of the value.
The first <code class="language-plaintext highlighter-rouge">!</code> will convert the value to the opposite of what it was.
Adding the second <code class="language-plaintext highlighter-rouge">!</code> will convert the value to a boolean of the same logical value as the original value.</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="o">!</span><span class="mi">0</span><span class="p">;</span> <span class="c1">// true</span>
<span class="o">!!</span><span class="mi">0</span><span class="p">;</span> <span class="c1">// false</span>
</code></pre></div></div>]]></content><author><name>Ryan Will</name></author><category term="javascript" /><summary type="html"><![CDATA[How to use the idea of truthy and falsy to write simpler code.]]></summary></entry><entry><title type="html">Putting Service workers to work</title><link href="https://www.ryanwill.dev/rants/working-with-sw" rel="alternate" type="text/html" title="Putting Service workers to work" /><published>2018-01-13T00:00:00+00:00</published><updated>2018-01-13T00:00:00+00:00</updated><id>https://www.ryanwill.dev/rants/working-with-sw</id><content type="html" xml:base="https://www.ryanwill.dev/rants/working-with-sw"><![CDATA[<p>Service workers are event driven JavaScript files that can be registered as background tasks with the browser.</p>

<h2 id="registering-a-service-worker">Registering a service worker</h2>

<p>In order to get a service worker to do your bidding, you must first register it with the browser.</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">if</span> <span class="p">(</span><span class="nb">navigator</span><span class="p">.</span><span class="nx">serviceWorker</span><span class="p">)</span> <span class="p">{</span>
  <span class="nb">navigator</span><span class="p">.</span><span class="nx">serviceWorker</span><span class="p">.</span><span class="nx">register</span><span class="p">(</span><span class="dl">'</span><span class="s1">/serviceWorker.js</span><span class="dl">'</span><span class="p">).</span><span class="nx">then</span><span class="p">(</span><span class="nx">result</span> <span class="o">=&gt;</span> <span class="p">{</span>
    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="dl">'</span><span class="s1">Service Worker registered!</span><span class="dl">'</span><span class="p">,</span> <span class="nx">result</span><span class="p">);</span>
  <span class="p">});</span>
<span class="p">}</span>
</code></pre></div></div>

<p>The check for <code class="language-plaintext highlighter-rouge">navigator.serviceWorker</code> is necessary because some browsers do not yet support service workers.
I’m looking at you Safari.</p>

<p>For up to date info on what browser support check out the service worker page on <a href="https://caniuse.com/#feat=serviceworkers">caniuse.com</a>.</p>

<h2 id="so-service-workers-are-just-js">So, service workers are just JS?</h2>

<p>Well, not exactly. While you do write the service worker in JavaScript, they behave a bit differently than the JavaScript you’re used to.
They run in a separate thread, and they do not have access to the DOM.</p>

<p>Instead, service workers register a series of events to which they want to respond.
These events include lifecycle events (install, activate, and download) for the service worker itself as well as fetch events issued by the browser, among others.
Registering an event in the service worker should look like pretty standard JavaScript.</p>

<p>Here is a very simple example of registering an event to watch for the service worker’s install event which is called every time a new service worker is
downloaded by the browser.
Self in the snippet below references the service worker.</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">self</span><span class="p">.</span><span class="nx">addEventListener</span><span class="p">(</span><span class="dl">'</span><span class="s1">install</span><span class="dl">'</span><span class="p">,</span> <span class="nx">event</span> <span class="o">=&gt;</span> <span class="p">{</span>
  <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="dl">'</span><span class="s1">Service Worker was installed!</span><span class="dl">'</span><span class="p">,</span> <span class="nx">event</span><span class="p">);</span>
<span class="p">});</span>
</code></pre></div></div>

<h2 id="reliable-worker">Reliable worker</h2>

<p>When you register an event listener for fetch events issued by the browser the service worker effectively becomes a proxy server, a middleman, between
the browser and the actually server that hosts the assets you want.</p>

<p>Note that an AJAX request is not the same as a request sent using the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API">Fetch API</a>.
Service workers can only intercept requests made using the Fetch API.</p>

<p>You can choose with each request whether to cache the response, or, perhaps, not send the request to the server at all and respond with a previously
cached response.
You can even load your app without an internet connection by caching the necessary assets when the service worker is installed.
This is a technique known as pre-caching the app shell.</p>

<h2 id="working-in-the-background">Working in the background</h2>

<p>Since service workers run as background tasks separate from the thread your normal JavaScript runs in, they are able to listen and respond to events even when
the browser is not open.</p>

<p>This enables features such as background sync and push notifications, which allow developers to create more resilient and immersive UIs.</p>]]></content><author><name>Ryan Will</name></author><category term="pwa" /><category term="progressive-web-app" /><category term="service-workers" /><summary type="html"><![CDATA[An introduction to Service workers. What they are how they work, and what they can do for you.]]></summary></entry><entry><title type="html">Web Manifest</title><link href="https://www.ryanwill.dev/rants/manifest-json" rel="alternate" type="text/html" title="Web Manifest" /><published>2018-01-04T00:00:00+00:00</published><updated>2018-01-04T00:00:00+00:00</updated><id>https://www.ryanwill.dev/rants/manifest-json</id><content type="html" xml:base="https://www.ryanwill.dev/rants/manifest-json"><![CDATA[<p>The manifest file is one of the basic building blocks of a Progressive Web App (PWA).
It is a simple JSON file stored in the root of your server’s web directory that lists properties of your app, including the name, icons and theme colors, orientation of the app, and much more.</p>

<p>Along with the other technologies, the manifest file allows you to create a web app with performance and experience that rivals that of native apps.
Users will be able to install the app on the device’s home screen directly from the web, use the app when offline, and receive push notifications.
This will allow companies to focus on building a single app that provides a great experience for web and native users.</p>

<h2 id="browser-support">Browser Support</h2>

<p>At the time of writing, <a href="https://caniuse.com/#feat=web-app-manifest">caniuse</a> reports that only Chrome, Chrome for Android, and the Samsung browser support
the Web App Manifest.
Those three browsers alone provide support for 59% of all internet users.</p>

<p>The other top three browsers, Microsoft Edge, FireFox, and Safari (WebKit) are listed as in development.
So, it will only be a matter of time before we see support in those browsers.</p>

<p>As with other features of a Progressive Web App, the lack of browser support is not a deterrent.
These features only enhance the experience of users on supported platforms and do not significantly degrade the experience on platforms without support.</p>]]></content><author><name>Ryan Will</name></author><category term="pwa" /><category term="progressive-web-app" /><summary type="html"><![CDATA[The web manifest file is the first step on the road to a building a Progressive Web App.]]></summary></entry><entry><title type="html">Nuxt Rewrite</title><link href="https://www.ryanwill.dev/rants/nuxt-rewrite" rel="alternate" type="text/html" title="Nuxt Rewrite" /><published>2017-10-31T00:00:00+00:00</published><updated>2017-10-31T00:00:00+00:00</updated><id>https://www.ryanwill.dev/rants/nuxt-rewrite</id><content type="html" xml:base="https://www.ryanwill.dev/rants/nuxt-rewrite"><![CDATA[<p>Recently I converted this site from a single page Vue app to a static site generated with Nuxt.
The decision to do so was motivated by a few factors, but in the end it was the ability to generate a static site that convinced me.
Well, that and every developer’s weakness - curiosity.</p>

<h2 id="what-is-nuxt">What is Nuxt?</h2>

<p><a href="https://nuxtjs.org/guide">Nuxt</a> is a framework for easily creating Universal or Server Rendered apps with <a href="https://vuejs.org/">Vue</a>.
It is inspired by the framework <a href="https://zeit.co/blog/next2">Next</a> from Zeit.</p>

<p>Nuxt also provides the ability to generate a static version of your site.
This feature is similar to <a href="https://jekyllrb.com/">Jekyll</a>, but allows you to use the full power of Vue and related tools like Vuex and Vue Router as well. The static site generated with Nuxt can be hosted on any static hosting provider; I used Github pages for this site.
The Nuxt team uses the same technique to generate their docs.</p>

<h2 id="integrating-nuxt">Integrating Nuxt</h2>

<p>First step to integrating Nuxt was to install it in my app with <code class="language-plaintext highlighter-rouge">npm install nuxt --save</code>. After installing Nuxt, I had to remove some old dependencies installed with Vue app that were now redundant.</p>

<p>Once the dependencies were straightened out, I needed to create the <a href="https://nuxtjs.org/guide/directory-structure">directory structure</a> Nuxt uses to automatically create routes.
This mostly consisted of moving the container component I already had into the layouts directory and moving the components that were acting as pages to the pages directory.
All the other components I moved to a new directory called components and imported them as needed into the components in the Nuxt directories.</p>

<h2 id="configuring-nuxt">Configuring Nuxt</h2>

<p>By default Nuxt is configured to handle many things for you.
Any changes can be added easily by editing the <a href="https://nuxtjs.org/guide/configuration">nuxt.config.js</a>.</p>

<p>I used the router property of the Nuxt config to add a class to my active links.
I also added the following simple middleware that redirects visitors to the about route from the root of the site.</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">export</span> <span class="k">default</span> <span class="kd">function</span><span class="p">({</span> <span class="nx">route</span><span class="p">,</span> <span class="nx">redirect</span> <span class="p">})</span> <span class="p">{</span>
  <span class="k">if</span> <span class="p">(</span><span class="nx">route</span><span class="p">.</span><span class="nx">path</span> <span class="o">===</span> <span class="dl">'</span><span class="s1">/</span><span class="dl">'</span><span class="p">)</span> <span class="nx">redirect</span><span class="p">(</span><span class="dl">'</span><span class="s1">/about</span><span class="dl">'</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Another convenient configuration available in the Nuxt config is the head property.
The head property allows you to define the default meta properties for you app.
This can be used in combination with the head method Nuxt adds to your components to very simply update the meta tags per page.
I use this technique to update the Open Graph meta tags on my journal entries.</p>

<h2 id="static-site-with-nuxt">Static Site with Nuxt</h2>

<p>Generating a static site using Nuxt was pretty straight forward.
I only ran into one relatively small and easy to fix issue.
Navigating to a journal entry once on the site worked fine, but if you refreshed the page you would get a 404 error.
This was because by default Nuxt only generates routes for the root of your static site.
If you want to add dynamic routes or routes with dynamic params you have to add a tiny tweak to the config file.</p>

<p>For my site, I wanted to add a dynamic param for each journal entry.
That is <code class="language-plaintext highlighter-rouge">/journal/:titleOfEntry</code>. Adding the following snippet to my config allowed the desired routes to be generated.</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nx">generate</span><span class="p">:</span> <span class="p">{</span>
  <span class="nx">routes</span><span class="p">()</span> <span class="p">{</span>
    <span class="k">return</span> <span class="k">new</span> <span class="nb">Promise</span><span class="p">(</span><span class="nx">resolve</span> <span class="o">=&gt;</span> <span class="nx">resolve</span><span class="p">(</span><span class="nx">journal</span><span class="p">.</span><span class="nx">map</span><span class="p">(</span><span class="nx">entry</span> <span class="o">=&gt;</span>
      <span class="p">({</span> <span class="na">route</span><span class="p">:</span> <span class="s2">`journal/</span><span class="p">${</span><span class="nx">entry</span><span class="p">.</span><span class="nx">data</span><span class="p">.</span><span class="nx">url</span><span class="p">}</span><span class="s2">`</span><span class="p">,</span> <span class="na">payload</span><span class="p">:</span> <span class="nx">entry</span> <span class="p">}))));</span>
  <span class="p">},</span>
</code></pre></div></div>

<p>The route property in the object above is required and used by Nuxt to generate the dynamic routes.
The payload property is optional and is used to provide data to you components during the generation.
Any data provided in the payload property is passed to the the asyncData method, which Nuxt adds to your page components and is called when the component is rendered server side or during the static site generation.</p>

<p>Async data is also called just before navigating to the route that renders the page component.
Though in this case, it is not provided the payload.
An alternative method for getting the data will need to be provided when payload is false.
Here is the asyncData method from my journalEntry component.</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">async</span> <span class="nx">asyncData</span><span class="p">({</span> <span class="nx">payload</span><span class="p">,</span> <span class="nx">params</span> <span class="p">})</span> <span class="p">{</span>
  <span class="k">return</span> <span class="p">{</span>
    <span class="na">entry</span><span class="p">:</span> <span class="nx">payload</span>
      <span class="o">||</span> <span class="nx">journal</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="nx">entry</span> <span class="o">=&gt;</span> <span class="nx">entry</span><span class="p">.</span><span class="nx">data</span><span class="p">.</span><span class="nx">url</span> <span class="o">===</span> <span class="nx">params</span><span class="p">.</span><span class="nx">journalEntry</span><span class="p">),</span>
  <span class="p">};</span>
<span class="p">},</span>
</code></pre></div></div>

<h2 id="conclusion">Conclusion</h2>

<p>Overall switching to Nuxt was easy and pretty straightforward.
The ability to statically generate your site is very neat feature.
An easy to use, static blog framework is just asking to be built on top of Nuxt.</p>

<p>Hmmm… 🤔 Maybe someday.</p>

<p>In the meantime, if I happen to find myself needing a way to render a future project on the server I will definitely be reaching for Nuxt.</p>]]></content><author><name>Ryan Will</name></author><category term="vue" /><category term="nuxt" /><summary type="html"><![CDATA[A quick write up on how I converted this site from a single page Vue site to a static site with Nuxt.]]></summary></entry><entry><title type="html">Help! I committed to the wrong branch.</title><link href="https://www.ryanwill.dev/rants/commit-wrong-branch" rel="alternate" type="text/html" title="Help! I committed to the wrong branch." /><published>2017-09-30T00:00:00+00:00</published><updated>2017-09-30T00:00:00+00:00</updated><id>https://www.ryanwill.dev/rants/commit-wrong-branch</id><content type="html" xml:base="https://www.ryanwill.dev/rants/commit-wrong-branch"><![CDATA[<p>At <a href="https://metova.com">Metova</a> we use git flow when making changes to our codebase.
That is when adding a feature or fixing a bug, we branch from develop to create a feature or bugfix branch and merge back into develop when our work is complete.
This is probably a familiar process to most of you.</p>

<p>Something else that might be familiar is completing your feature preparing, to push your changes, and realizing your 12 commits were made on develop.
Now, if you’re anything like me git can still be a little intimidating when trying to fix your errors.
Have no fear, though. This particular screw up is very easy to fix.</p>

<p>First, create a feature or bugfix branch from develop. Then, reset develop back to where it should be.</p>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git branch &lt;name-of-new-branch&gt;

<span class="c"># find the sha if you don't already know it.</span>
git log

git reset &lt;SHA-to-go-back-to&gt; <span class="nt">--hard</span>
</code></pre></div></div>

<p>That’s it. Now your new branch will contain the commits you made on develop and develop will be back where you want it.</p>]]></content><author><name>Ryan Will</name></author><category term="git" /><category term="cli" /><summary type="html"><![CDATA[Everyone's made their commits to the wrong branch at least once. Here is a simple fix.]]></summary></entry><entry><title type="html">Elm First Impressions</title><link href="https://www.ryanwill.dev/rants/elm-todo" rel="alternate" type="text/html" title="Elm First Impressions" /><published>2017-07-22T00:00:00+00:00</published><updated>2017-07-22T00:00:00+00:00</updated><id>https://www.ryanwill.dev/rants/elm-todo</id><content type="html" xml:base="https://www.ryanwill.dev/rants/elm-todo"><![CDATA[<p>I have been interested in functional programming languages, particularly Elm,
for a while but have been hesitant to take the plunge and build something with one.
After listening to quite a few episodes of <a href="https://elmtown.github.io/">Elm Town</a> and watching some talks on Elm,
I decided to make the customary To Do application.
I know. You can’t get much more cliche than your first application with a new language being a To Do app,
but it allows you to test out the language relatively quickly.
You can find my code <a href="https://github.com/RyanWillDev/elm-todo">here</a>.</p>

<h2 id="the-development-experience">The Development Experience</h2>

<p>When writing Elm code I spent quite a lot of time trying to appease the compiler.
I would make a change to the code and the compiler would tell me I did something wrong.
I’d make another change and the compiler would become angry again.</p>

<p>It was a vicious cycle.</p>

<p>You may think this would slow your development down tremendously. Well… You’re right. It does, but the pay off is worth it.
After I won my first major battle with the compiler and my app finally rendered in the browser,
the first thing I did was open the dev tools and start clicking around.
I did not believe the compiler when it told me everything was fine.</p>

<p>Coming from the JavaScript world, I was sure there was a runtime exception waiting to be thrown.
I just needed to find it.
But after a few minutes of adding and completing to do’s I could not break my app.
The compiler was right.</p>

<p>With Elm you have a pretty strong guarantee that if your code compiles it will run without error.
This guarantee is made possible by Elm’s type system and compiler working together to minimize the number of
mistakes you make while building your application.</p>

<h2 id="the-type-system">The Type System</h2>

<p>The type system was one of the main reasons I was interested in Elm and other functional languages.
The ability to describe and model your data in a more meaningful way was very appealing.
It is like being able to communicate with your application on a deeper level by describing exactly what you want
the shape of your data to be.</p>

<p>For instance, in my to do application I define a to do as such:</p>

<div class="language-elm highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">type</span> <span class="k">alias</span> <span class="kt">Todo</span> <span class="o">=</span>
  <span class="p">{</span> <span class="n">title</span> <span class="p">:</span> <span class="kt">String</span>
  <span class="o">,</span> <span class="n">completed</span> <span class="p">:</span> <span class="kt">Bool</span>
  <span class="o">,</span> <span class="n">id</span> <span class="p">:</span> <span class="kt">Int</span>
  <span class="p">}</span>
</code></pre></div></div>

<p>Comparing that to JavaScript, all we would have to work with is an object with default values.</p>

<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">const</span> <span class="nx">todoModel</span> <span class="o">=</span> <span class="p">{</span>
  <span class="na">title</span><span class="p">:</span> <span class="dl">''</span><span class="p">,</span>
  <span class="na">completed</span><span class="p">:</span> <span class="kc">false</span><span class="p">,</span>
  <span class="na">id</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
<span class="p">};</span>
</code></pre></div></div>

<p>The type alias above does not seem particularly special at first, but the power becomes evident once you begin to leverage
that definition throughout the application.</p>

<p>One example is how the Todo type is used inside the model’s type definition.</p>

<div class="language-elm highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">type</span> <span class="k">alias</span> <span class="kt">Model</span> <span class="o">=</span>
  <span class="p">{</span> <span class="n">newTodoTitle</span> <span class="p">:</span> <span class="kt">String</span>
  <span class="o">,</span> <span class="n">todoList</span> <span class="p">:</span> <span class="kt">List</span> <span class="kt">Todo</span>
  <span class="o">,</span> <span class="n">currentFilter</span> <span class="p">:</span> <span class="kt">Filter</span>
  <span class="o">,</span> <span class="n">prevId</span> <span class="p">:</span> <span class="kt">Int</span>
  <span class="p">}</span>
</code></pre></div></div>

<p>As you can see above, I was able to tell the Elm program that the todoList was not only a list but that the list was
to contain only Todo’s. Now Elm knows exactly what I want my list to contain.</p>

<p>Having never worked with a statically typed language before Elm’s syntax and features took a little getting used to.
Fortunately the Elm community and Evan Czaplicki, the creator of Elm, are focused on making Elm easy to use.
This means that while there is a slight learning curve to Elm it is not as drastic as other languages.</p>

<p>One of the biggest benefits of Elm’s type system is it encourages you to spend time up front determining the
structure of your application.
As developer’s, we tend to want to get our hands on the keyboard and start building something as quickly as possible, which
can cause us to neglect forethought and planning.
It is nice to have something to remind you that those things are necessary.</p>

<h2 id="the-elm-architecture">The Elm Architecture</h2>

<p>Elm web applications have a preferred structure known as the Elm Architecture.
It consists of a series of functions (model, view, and update) that describe your app and the way it can change.</p>

<p>A <strong>very</strong> brief explanation of the Elm Architecture is the model holds the data/state of your application,
the view function describes to the Elm virtual DOM what to render,
and the update function receives messages from the view and returns a new model describing the updated state of your application.</p>

<p>Having used Redux before and knowing it was inspired by the Elm Architecture, I had a basic understanding of what was going on.
Unlike with Redux, you do not have to wire together the Elm Architecture. The language takes care of that for you.
Honestly, this bothered me a little when starting on my app. I wanted to understand what was going on behind the scenes.
Once I accepted that Elm would take care of connecting things, working with the Elm Architecture was very pleasant.</p>

<h2 id="the-tooling">The Tooling</h2>

<p>I want to start by saying the tooling around Elm is pretty great.
The packages for the Atom editor add a lot of cool features for working with Elm.
I really enjoyed the inline compiler errors provided by the <a href="https://atom.io/packages/linter-elm-make">Elm Linter</a>,
the autocompletion provided by <a href="https://atom.io/packages/elmjutsu">Elmjutsu</a>,
but by far my favorite was <a href="https://atom.io/packages/elm-format">Elm Format</a>.</p>

<p>Coming from a JavaScript background the formatting of Elm was a little strange at first.
The ability to just throw some Elm code on the page hit cmd-s and have Elm Format take care of the formatting
was great. It allowed me to maintain focus on trying to solve the current problem instead of getting caught up with formatting.</p>

<p>I also found <a href="https://github.com/elm-lang/elm-reactor">Elm Reactor</a> to be an invaluable tool while working with Elm.
To have your code compiled on the fly and see your changes reflected in the browser made developing with Elm
almost as easy as modern JS development.</p>]]></content><author><name>Ryan Will</name></author><category term="elm" /><category term="functional-programming" /><summary type="html"><![CDATA[My impressions of Elm while building the customary To Do application.]]></summary></entry><entry><title type="html">Hello World</title><link href="https://www.ryanwill.dev/rants/hello-world" rel="alternate" type="text/html" title="Hello World" /><published>2017-03-06T00:00:00+00:00</published><updated>2017-03-06T00:00:00+00:00</updated><id>https://www.ryanwill.dev/rants/hello-world</id><content type="html" xml:base="https://www.ryanwill.dev/rants/hello-world"><![CDATA[<p>Like most developers’ personal sites, this has been my playground and has gone through many rewrites.
I wanted an excuse to try out <a href="https://vuejs.org/">Vue</a>, so I decided to rewrite this site from React.
I really enjoyed working with Vue and learning some new tricks and techniques to make a “blog” without a database.</p>

<p>I am already itching to do another rewrite, though. This time with Elm =)
I guess that is the developer’s eternal struggle.</p>

<h2 id="vue">Vue</h2>

<p>Overall working with Vue was very pleasant. The <a href="https://vuejs.org/v2/guide/single-file-components.html">.vue</a>
files are a very cool way to organize your code on a component level.
You can combine all the HTML, CSS, and JavaScript that make up your component into a single file.
This allows you to seamlessly create reusable components.</p>

<p>Like many of the modern frontend frameworks and libraries Vue has the <a href="https://github.com/vuejs/vue-cli">vue-cli</a>
which makes setting up your build and dev environments trivially easy. It does the heavy lifting of setting up the
Webpack configs including hot reloading and production build file.</p>

<h2 id="my-journal">My Journal</h2>

<p>I wanted a way to write a “blog” without having to store the entries on a server. Of course, I could have used a static site
generator like <a href="https://jekyllrb.com/">Jekyll</a>, but I wanted to try out Vue.</p>

<p>The solution I came up with was to write the entries in markdown and use Node to compile the markdown to HTML using <a href="http://showdownjs.github.io/demo/">Showdown.js</a>.
Once I have the HTML, I generate a JSON object made up of the markdown and some metadata about the post.
I then import the JSON file into my Vue app so it is available to display.</p>

<p>To add syntax highlighting for the code in the journal entries I used <a href="https://highlightjs.org/">Highlight.js</a>.
When a JournalEntry component loads it finds all the code elements and uses highlightjs to add syntax highlighting.</p>

<p>Building the Journal this way gave me some of the same benefits of using a static site generator like the posts being version controlled
and not needing a server or database, but it also allowed me to give Vue a try. It also allowed me to get some practice in
with manipulating files and directories using Node.</p>]]></content><author><name>Ryan Will</name></author><category term="vue" /><category term="showdownjs" /><category term="highlightjs" /><category term="node" /><category term="javascript" /><summary type="html"><![CDATA[The first entry in my journal gives a brief rundown of the technologies used to build this site.]]></summary></entry></feed>