<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Devin Clark</title>
  <subtitle>JS, Web, and Software Ramblings</subtitle>
  <link href="https://devin-clark.com/feed.xml" rel="self"/>
  <link href="https://devin-clark.com/"/>
  <updated>Tue, 20 Oct 2020 00:00:00 GMT</updated>
  <id>https://devin-clark.com/</id>
  <author>
    <name>Devin Clark</name>
    <email>dclarkdesign@gmail.com</email>
  </author>
  
  <entry>
    <title>200OK Conference Wrap Up</title>
    <link href="https://devin-clark.com/blog/200ok-conference-wrap/"/>
    <updated>Mon, 07 Oct 2013 19:52:36 GMT</updated>
    <id>https://devin-clark.com/blog/200ok-conference-wrap/</id>
    <content type="html">&lt;p&gt;&lt;a href=&quot;http://200ok.us/&quot;&gt;200OK&lt;/a&gt;, Oklahoma&#39;s premier web dev conference, took place in Tulsa, Oklahoma on September 27th 2013. I had the pleasure of attending and I would like to share my experiences. It was an excellent conference, with a rock star (yeah I said it!) lineup of speakers. This was the first time (that I can remember) going to Tulsa. I live about two hours away.&lt;/p&gt;
&lt;h2 id=&quot;firefox-os-and-web-apis&quot;&gt;Firefox OS and Web APIs&lt;/h2&gt;
&lt;p&gt;This talk was given by &lt;a href=&quot;http://davidwalsh.name/&quot;&gt;David Walsh&lt;/a&gt;. The slides are available at &lt;a href=&quot;https://devin-clark.com/blog/200ok-conference-wrap/dwf.tw/200&quot;&gt;dwf.tw/200&lt;/a&gt;. I have followed David&#39;s blog for years and I was excited when I saw he was speaking.&lt;/p&gt;
&lt;h2 id=&quot;mobile-web-at-etsy&quot;&gt;Mobile Web at Etsy&lt;/h2&gt;
&lt;p&gt;This talk was given by &lt;a href=&quot;http://laraswanson.com/&quot;&gt;Lara Swanson&lt;/a&gt;. Lara is an amazing speaker and obviously is a descendant of my personal hero, Ron Swanson. &lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;http://cdnl.complex.com/mp/620/400/80/0/bb/1/ffffff/4ae86e3e1e1068a9d3e866db6a3dfbb4/images_/assets/CHANNEL_IMAGES/POP_CULTURE/2013/04/the-50-funniest-gifs-of-ron-swanson/cvepz_41_563115.gif&quot; alt=&quot;Ron Swanson Bacon and Eggs&quot; /&gt;&lt;/p&gt;
&lt;p&gt;I found this talk to be incredibly interesting because it combines two things that really fascinate me, mobile web development and performance. &lt;/p&gt;
&lt;p&gt;Etsy has an alert set up that notifies the team when a page violates their performance SLA. I think that&#39;s a great idea. &lt;/p&gt;
&lt;p&gt;They have an amazing device lab. You can read about it on &lt;a href=&quot;http://codeascraft.com/2013/08/09/mobile-device-lab/&quot;&gt;Code as Craft&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;a href=&quot;http://laraswanson.com/mobileweb/&quot;&gt;slides and some relevant resources&lt;/a&gt; for this talk, which I highly recommend you go through, are available on Lara&#39;s website.&lt;/p&gt;
&lt;h2 id=&quot;github-culture-and-technology&quot;&gt;Github Culture and Technology&lt;/h2&gt;
&lt;p&gt;This talk was given by &lt;a href=&quot;http://twitter.com/michaelgorsuch&quot;&gt;Michael Gorsuch&lt;/a&gt;. I was surprised to hear we have a Githubber in Oklahoma City. One interesting thing Michale mentioned in the talk is how Github practices README driven development. The idea behind it is to write the blog post before the product and use the blog post to guide the product.&lt;/p&gt;
&lt;p&gt;He recommended a talk &lt;em&gt;&lt;a href=&quot;http://vimeo.com/m/10877889&quot;&gt;Everything I know about Open Source I learned from Indie Hip Hop&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;It was an excellent insight into the work environment of Github and I would definitely recommend you watch the video for this presentation when it becomes available. I will try to do a post or something when they videos from 200OK are available.&lt;/p&gt;
&lt;h2 id=&quot;brackets-edge-code&quot;&gt;Brackets &amp;amp; Edge Code&lt;/h2&gt;
&lt;p&gt;This talk was given by &lt;a href=&quot;https://twitter.com/cfjedimaster&quot;&gt;Raymond Camden&lt;/a&gt;, a hilarious man and Adobe Evangelist. He is the man responsible for the daily Adobe Updates but I do not hold that against him. Raymond revealed the magic of the wonderful code editor, &lt;a href=&quot;http://brackets.io/&quot;&gt;Brackets&lt;/a&gt;. It is certainly something I would consider using instead of Sublime Text for JavaScript editing.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;A common theme between most of the companies who spoke was they use some sort of chat program, whether it is IRC at Etsy or Campfire + Hubot at Github, to effectively communicate between team members.&lt;/p&gt;
&lt;p&gt;I look forward to attending next year!&lt;/p&gt;
&lt;p&gt;Did you attend 200OK and have something you wish to add? Leave a comment.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Star Dates in JavaScript</title>
    <link href="https://devin-clark.com/blog/star-dates-in-javascript/"/>
    <updated>Sun, 29 Dec 2013 19:13:21 GMT</updated>
    <id>https://devin-clark.com/blog/star-dates-in-javascript/</id>
    <content type="html">&lt;p&gt;While on my winter vacation, I began creating problems to solve out of boredom and to keep my JavaScript skills sharp. One evening, after an unknown amount of whiskey, I decided to look into converting dates into Stardates. TREKKIE ALERT! Don&amp;#8217;t let this discourage you from reading. There still is a decent amount of information JavaScript Dates that can be extracted from this article.&lt;/p&gt;
&lt;p&gt;After a bit of research I found that stardates don&amp;#8217;t really exist (yet). That was a bit of a disappointing dead end but I found &lt;a href=&quot;http://en.wikipedia.org/wiki/Julian_day&quot;&gt;Julian Days&lt;/a&gt; to be about the closest equivalent. I assume we will use these in place of stardates in the future. Anyways, I started researching Julian Days, lots of Stack Overflowin&amp;#8217;, and (SPOILER ALERT) I eventually got a working converter build. &lt;/p&gt;
&lt;p&gt;The first hurdle I had to solve was figuring out the OMG MATH aspect of &lt;a href=&quot;http://aa.usno.navy.mil/faq/docs/JD_Formula.php&quot;&gt;the formula I found&lt;/a&gt;. This was solved by finding a different formula that worked with seconds rather than ALL THE UNITS. This new formula also made conversion to UTC easier, because Julian Days are always calculated using UTC time.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;JD&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;EPOC_SECONDS&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;86400000&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;TIMEZONE_OFFSET&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1440&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2440587.5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, we have a working formula. Let&amp;#8217;s plug it in as a JavaScript Date() method. Yes, before you get all up in arms, I am going to use &lt;code&gt;Date.prototype.toStarDate&lt;/code&gt;. The day this causes a collision will be a very happy day for me, should that day ever come.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token class-name&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;prototype&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function-variable function&quot;&gt;toStarDate&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;86400000&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getTimezoneOffset&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1440&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2440587.5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I originally was rounding the result to two decimal places I later realized that would produce an incorrect Julian Day. I am still skeptical whether JavaScript floating point math is an issue here. It would probably be worth integrating something like &lt;a href=&quot;https://github.com/dtrebbien/BigDecimal.js&quot;&gt;BigDecimal.js&lt;/a&gt; but that seems out of scope for a whiskey-fueled &amp;#8220;just for funzies&amp;#8221; project.&lt;/p&gt;
&lt;p&gt;Here is a possibly working &lt;a href=&quot;http://jsfiddle.net/DevinClark/u3u5P/&quot;&gt;demo link&lt;/a&gt;. If you made it this far, I salute you.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Quick Tip: npm CLI Shorthands</title>
    <link href="https://devin-clark.com/blog/quick-tip-npm-cli-shorthands/"/>
    <updated>Wed, 09 Apr 2014 15:28:38 GMT</updated>
    <id>https://devin-clark.com/blog/quick-tip-npm-cli-shorthands/</id>
    <content type="html">&lt;p&gt;If you&#39;re like me, you spend a lot of time daily using npm, the official node package manager. Typing &lt;code&gt;npm install whatever-package --save&lt;/code&gt; or &lt;code&gt;npm install whatever-package --save-dev&lt;/code&gt; is very tedious.&lt;/p&gt;
&lt;p&gt;I recently discovered there are aliases for &lt;code&gt;--save&lt;/code&gt; and &lt;code&gt;--save-dev&lt;/code&gt;. &lt;code&gt;--save&lt;/code&gt; can be replaced with &lt;code&gt;-S&lt;/code&gt; and &lt;code&gt;--save-dev&lt;/code&gt; with &lt;code&gt;-D&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;There are a few others in the source link below but I felt those two are the most commonly used. I hope this speeds up your &lt;code&gt;npm install&lt;/code&gt;-ing like it did mine!&lt;/p&gt;
&lt;p&gt;Also, you can run &lt;code&gt;npm i whatever-package&lt;/code&gt; instead of &lt;code&gt;npm install whatever-package&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.npmjs.org/doc/misc/npm-config.html#Shorthands-and-Other-CLI-Niceties&quot;&gt;Source&lt;/a&gt;&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Browserify: Rockin&#39; the Wizard Hat</title>
    <link href="https://devin-clark.com/blog/okcjs-browserify/"/>
    <updated>Tue, 15 Apr 2014 15:05:52 GMT</updated>
    <id>https://devin-clark.com/blog/okcjs-browserify/</id>
    <content type="html">&lt;p&gt;&lt;a href=&quot;http://twitter.com/jvrousseau&quot;&gt;Jordan Rousseau&lt;/a&gt; recently gave a presentation at &lt;a href=&quot;http://okcjs.org/&quot;&gt;OKC.JS&lt;/a&gt; about &lt;a href=&quot;http://browserify.org/&quot;&gt;Browserify&lt;/a&gt;. Jordan is the fearless leader of the web team, of which I happen to be a member, at &lt;a href=&quot;http://wdtinc.com/&quot;&gt;Weather Decision Technologies&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://devin-clark.com/blog/okcjs-browserify/assets/images/jordan-rousseau-gandalf.jpg&quot; alt=&quot;Jordan Rousseau as Gandalf&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Jordan spends the first 18 slides talking about bad ways to handle loading JavaScript. When I say &amp;quot;bad ways&amp;quot; I mean ways that are difficult to maintain and/or do not scale well. After a lot of investigation, we landed on Browserify.&lt;/p&gt;
&lt;p&gt;Browserify is a utility that builds CommonJS modules into a single bundle browser code with Node.js-style requires. Just like node Browserify allows you to write modules in separate files and use &lt;code&gt;module.exports&lt;/code&gt; to expose external methods and properties. You can also use (some) npm modules!&lt;/p&gt;
&lt;h2 id=&quot;getting-started&quot;&gt;Getting Started &lt;a class=&quot;direct-link&quot; href=&quot;https://devin-clark.com/blog/okcjs-browserify/#getting-started&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;To begin, simply install browserify using npm.&lt;/p&gt;
&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;npm&lt;/span&gt; i browserify &lt;span class=&quot;token parameter variable&quot;&gt;-g&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This installs the CLI for Browserify. It can be a bit annoying to use at times so we use &lt;a href=&quot;https://github.com/jmreidy/grunt-browserify&quot;&gt;grunt-browserify&lt;/a&gt;. If you are dead set on using the CLI, I recommend you look into &lt;a href=&quot;https://github.com/substack/watchify&quot;&gt;watchify&lt;/a&gt;. If you use Gulp, I believe you can use it with Browserify but I have never used Gulp so I can&#39;t speak to it personally.&lt;/p&gt;
&lt;h3 id=&quot;using-with-grunt&quot;&gt;Using with Grunt &lt;a class=&quot;direct-link&quot; href=&quot;https://devin-clark.com/blog/okcjs-browserify/#using-with-grunt&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;npm&lt;/span&gt; i grunt-browserify &lt;span class=&quot;token parameter variable&quot;&gt;-D&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will install the grunt-browserify task and save it in the &lt;code&gt;package.json&lt;/code&gt; file as a &lt;code&gt;devDependency&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token literal-property property&quot;&gt;browserify&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;files&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token string-property property&quot;&gt;&#39;js/bundle.js&#39;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;js/app.js&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token literal-property property&quot;&gt;transform&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;brfs&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;token literal-property property&quot;&gt;alias&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
              &lt;span class=&quot;token string&quot;&gt;&#39;./node_modules/lodash/dist/lodash.underscore:underscore&#39;&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;token literal-property property&quot;&gt;debug&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here is kind of the boilerplate code for the browserify task of our web projects. Nothing super special here. LoDash is being aliased to underscore because Backbone attempts to require Underscore and it will throw an error if we are using LoDash in place of Underscore.&lt;/p&gt;
&lt;p&gt;Jordan has some interesting demos in his slides, available at the bottom of the post. They are definitely worth checking out.&lt;/p&gt;
&lt;h2 id=&quot;transforms&quot;&gt;Transforms &lt;a class=&quot;direct-link&quot; href=&quot;https://devin-clark.com/blog/okcjs-browserify/#transforms&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Transforms in are essentially Browserify middleware that run source transformations on files before they are parsed by Browserify. An example of a transform is &lt;a href=&quot;https://github.com/jaredhanson/deamdify&quot;&gt;deAMDify&lt;/a&gt;, a module that converts AMD modules to CommonJS so they will play nice with Browserify. A few other transforms to check out are &lt;a href=&quot;https://github.com/substack/brfs&quot;&gt;brfs&lt;/a&gt;, &lt;a href=&quot;https://github.com/thlorenz/es6ify&quot;&gt;es6ify&lt;/a&gt;, and &lt;a href=&quot;https://github.com/jnordberg/coffeeify&quot;&gt;coffeeify&lt;/a&gt; (if you are &lt;em&gt;that&lt;/em&gt; kind of person). For a more comprehensive list see &lt;a href=&quot;https://github.com/substack/node-browserify/wiki/list-of-transforms&quot;&gt;the Browserify wiki on transforms&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://devin-clark.com/blog/okcjs-browserify/assets/images/npm-install-all-things.jpg&quot; alt=&quot;NPM INSTALL ALL THE THINGS!&quot; /&gt;&lt;/p&gt;
&lt;h2 id=&quot;resources&quot;&gt;Resources &lt;a class=&quot;direct-link&quot; href=&quot;https://devin-clark.com/blog/okcjs-browserify/#resources&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://benclinkinbeard.com/posts/how-browserify-works/&quot;&gt;How Browserify Works&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://maxogden.com/node-packaged-modules.html&quot;&gt;Introducing RequireBin, Browserify-CDN and npmsearch&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/substack/node-browserify/wiki&quot;&gt;Browserify Wiki&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://browserify.org/&quot;&gt;Browserify.org&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The slides for Jordan&#39;s talk are &lt;a href=&quot;http://rousseau.io/browserify-okcjs/&quot;&gt;available on github&lt;/a&gt;. Hopefully, you now have everything you need to become a Browserify Wizard! Feel free to ask if you have any questions.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Quick Tip: Useful Npm Package Listing</title>
    <link href="https://devin-clark.com/blog/quick-tip-useful-npm-package-listing/"/>
    <updated>Wed, 07 May 2014 16:14:07 GMT</updated>
    <id>https://devin-clark.com/blog/quick-tip-useful-npm-package-listing/</id>
    <content type="html">&lt;p&gt;We&#39;ve all had to suffer through &lt;code&gt;npm ls&lt;/code&gt; and it&#39;s endless trees of dependencies but there is a better way!&lt;/p&gt;
&lt;p&gt;That way is the &lt;code&gt;--depth&lt;/code&gt; flag. That&#39;s right, it was as easy as &lt;code&gt;npm ls --depth=0&lt;/code&gt;. Now you can see the packages you actually installed.&lt;/p&gt;
&lt;p&gt;That was easy... too easy... If you ran that command you probably noticed a bunch of these little buggers at the bottom of the output.&lt;/p&gt;
&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;npm&lt;/span&gt; ERR&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt; max depth reached: express@3.5.2, required by my-project@0.4.18&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let&#39;s fix this. Start by running &lt;code&gt;sudo nano ~/.profile&lt;/code&gt;. If you would rather use vi for this, type &lt;code&gt;alias vi=&#39;nano&#39;; sudo vi ~/.profile&lt;/code&gt;. Then, add this line to the file, save, and reload &lt;code&gt;~/.profile&lt;/code&gt; by running &lt;code&gt;source ~/.profile&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token builtin class-name&quot;&gt;alias&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;npmls0&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;npm ls --depth=0 2&gt;/dev/null&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The key to this is &lt;code&gt;2&amp;gt;/dev/null&lt;/code&gt;. All it does it eat the errors.&lt;/p&gt;
&lt;p&gt;Now you can just run &lt;code&gt;npmls0&lt;/code&gt; and see your npm packages and their associated versions.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.npmjs.org/doc/cli/npm-ls.html#depth&quot;&gt;Source&lt;/a&gt;&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Quick Tip: Don&#39;t use Star (and not for the reason you think)</title>
    <link href="https://devin-clark.com/blog/quick-tip-dont-use-star/"/>
    <updated>Sat, 24 May 2014 14:38:24 GMT</updated>
    <id>https://devin-clark.com/blog/quick-tip-dont-use-star/</id>
    <content type="html">&lt;p&gt;So, here at &lt;a href=&quot;http://wdtinc.com/&quot;&gt;WDT&lt;/a&gt; we do a lot of the JavaScripts and the CSSes. We had an issue in two of our weather mapping applications where users could not type in text boxes in using Safari. We tried to ignore this bug until yesterday when Jordan, our resident code wizard, found the cause of this issue.&lt;/p&gt;
&lt;p&gt;What does this have to do with the wildcard selection operator in CSS? We found that someone (not saying it was me, not saying it wasn&#39;t me) had &lt;code&gt;* {user-select: none; }&lt;/code&gt; in the stylesheet. The intention was to make the app feel like less of a web app and solve issues with dragging. What&#39;s wrong with this? We are making the assumption browsers all have the same interpret the CSS specification in the same way. In this case, user-select on a text input in Safari does not allow users to type in the text input.&lt;/p&gt;
&lt;p&gt;Discovering this issue also let to &lt;a href=&quot;https://twitter.com/jvrousseau/status/469933110096691201&quot;&gt;this awesome passive aggressive tweet&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>What You Might Not Know about Chrome DevTools</title>
    <link href="https://devin-clark.com/blog/what-you-might-not-know-about-chrome-devtools/"/>
    <updated>Wed, 18 Jun 2014 18:28:03 GMT</updated>
    <id>https://devin-clark.com/blog/what-you-might-not-know-about-chrome-devtools/</id>
    <content type="html">&lt;p&gt;Part One? Chrome&#39;s DevTools is a magical and mysterious beast. We can conquer this beast together! Josh Bavari recently gave a &lt;a href=&quot;http://jbavari.github.io/blog/2014/05/20/okcjs-javascript-debugging-techniques/&quot;&gt;Lightning Talk on JS debugging&lt;/a&gt;. You should check it out. He is a great presenter.&lt;/p&gt;
&lt;h2 id=&quot;console-api&quot;&gt;Console API &lt;a class=&quot;direct-link&quot; href=&quot;https://devin-clark.com/blog/what-you-might-not-know-about-chrome-devtools/#console-api&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Let&#39;s start off with the &lt;a href=&quot;https://developer.chrome.com/devtools/docs/console-api&quot;&gt;Console API&lt;/a&gt;. Josh mentions a few in his presentation but there are so much more! The console object contains a lot more than just &lt;code&gt;console.log()&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;count&quot;&gt;Count &lt;a class=&quot;direct-link&quot; href=&quot;https://devin-clark.com/blog/what-you-might-not-know-about-chrome-devtools/#count&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;There&#39;s a good chance you have done something like &lt;code&gt;console.log(i + &amp;quot; Times&amp;quot;)&lt;/code&gt; in a loop to count the number of iterations. Instead you could do &lt;code&gt;console.count(&#39;My Loop Name&#39;)&lt;/code&gt; and you will get an output like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;My Loop Name: 1
My Loop Name: 2
My Other Loop: 1
My Loop Name: 3
My Other Loop: 2
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The number increments each time the function with that label runs. Each label has a counter so go wild creating as many as you need.&lt;/p&gt;
&lt;h3 id=&quot;formatting&quot;&gt;Formatting &lt;a class=&quot;direct-link&quot; href=&quot;https://devin-clark.com/blog/what-you-might-not-know-about-chrome-devtools/#formatting&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;You can also format and even style some* of the console statements. By format I mean a &lt;code&gt;printf&lt;/code&gt; kind of API. If you are familiar with &lt;code&gt;printf&lt;/code&gt; then you are just curious what the format specifiers are.&lt;/p&gt;
&lt;h4 id=&quot;format-specifiers%3A&quot;&gt;Format Specifiers: &lt;a class=&quot;direct-link&quot; href=&quot;https://devin-clark.com/blog/what-you-might-not-know-about-chrome-devtools/#format-specifiers%3A&quot;&gt;#&lt;/a&gt;&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;%s&lt;/code&gt; - String.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;%d&lt;/code&gt; or &lt;code&gt;%i&lt;/code&gt; - Integer.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;%f&lt;/code&gt; - Floating point number.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;%o&lt;/code&gt; - DOM Element.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;%O&lt;/code&gt; - Object.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;%c&lt;/code&gt; - The secret to styling console statements.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;How about an example?&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;My Array Name: %s Contents: %O Length: %i&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;stuff&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; stuff&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; stuff&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This example will output the following in the console: &lt;img src=&quot;https://devin-clark.com/blog/what-you-might-not-know-about-chrome-devtools/assets/images/console-example-1.png&quot; alt=&quot;Console Output&quot; /&gt; If you are wondering why I added &lt;code&gt;stuff.length&lt;/code&gt; to my output string because it is in the &lt;code&gt;%O&lt;/code&gt;, I needed an integer for my example. That is all.&lt;/p&gt;
&lt;p&gt;Now let&#39;s talk about styling a little. I have never used it in a practical application. The styling uses CSS. All you have to do is add the &lt;code&gt;%c&lt;/code&gt; format specifier to the output string and add some CSS as the value. An example would illustrate this better. I am just going to extend the previous example and make it &lt;em&gt;pretty&lt;/em&gt;&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;token string&quot;&gt;&#39;%cMy Array Name: %s Contents: %O Length: %i&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token string&quot;&gt;&#39;color: #663399; font-size: 2em;&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token string&quot;&gt;&#39;stuff&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  stuff&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  stuff&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length
&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This example will output the following in the console: &lt;img src=&quot;https://devin-clark.com/blog/what-you-might-not-know-about-chrome-devtools/assets/images/console-example-2.png&quot; alt=&quot;Console Output&quot; /&gt; Look at that huge purple output. Hard to miss, huh?&lt;/p&gt;
&lt;h3 id=&quot;group&quot;&gt;Group &lt;a class=&quot;direct-link&quot; href=&quot;https://devin-clark.com/blog/what-you-might-not-know-about-chrome-devtools/#group&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;You can also group console statements with methods like &lt;code&gt;console.group()&lt;/code&gt; and &lt;code&gt;console.groupCollapsed()&lt;/code&gt;. These methods will group any log statements between it and a &lt;code&gt;console.groupEnd()&lt;/code&gt; method. This can be helpful if you are logging out a lot of data. A lot of times I will wrap the contents of a function I am debugging to make things easier to read. &lt;strong&gt;It is important to note&lt;/strong&gt; that this does not work if there is an asynchronous call inside the group. It will appear outside of the group.&lt;/p&gt;
&lt;h3 id=&quot;time&quot;&gt;Time &lt;a class=&quot;direct-link&quot; href=&quot;https://devin-clark.com/blog/what-you-might-not-know-about-chrome-devtools/#time&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Need to time something? Look no further than &lt;code&gt;console.time(label)&lt;/code&gt;, &lt;code&gt;console.timeline(label)&lt;/code&gt;, or &lt;code&gt;console.timeStamp([label])&lt;/code&gt;. Time and timeline have similar functionality; timeStamp is a little different. Time and timeline both have &lt;code&gt;*End()&lt;/code&gt; methods. Time will output the time elapsed between the two method calls. Timeline starts the DevTools Timeline for the amount of time between start and end methods.&lt;/p&gt;
&lt;p&gt;TimeStamp will just give you a marker at the current time on the Timeline with the specified label. This allows you to see what happening on the Timeline at that timestamp.&lt;/p&gt;
&lt;p&gt;If you need a high precision time for profiling look into the &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Performance&quot;&gt;Performance API&lt;/a&gt;. Also see this article about &lt;a href=&quot;http://codingjohnson.com/javascript-precision-timing#.U6DygpRdWH8&quot;&gt;JavaScript Precision Timing&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;console-tab&quot;&gt;Console Tab &lt;a class=&quot;direct-link&quot; href=&quot;https://devin-clark.com/blog/what-you-might-not-know-about-chrome-devtools/#console-tab&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Right clicking on the Console section of DevTools to reveal two options. The first option is &amp;quot;Log XMLHttpRequests&amp;quot; and will output the HTTP method and the URL of the request. I can not express how much this has helped me while developing the SPA app that had heavy API integration. I have been working on the past few months.&lt;/p&gt;
&lt;p&gt;The second option is &amp;quot;Preserve Log upon Navigation&amp;quot;. This option allows you to debug issues where a redirect occurs. Recently, I used these on an issue was one of my API calls was throwing a 401 status code and causing a redirection to the login page. It was simple to track down which call using both of these options.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Global npm Install without Sudo</title>
    <link href="https://devin-clark.com/blog/global-npm-install-without-sudo/"/>
    <updated>Mon, 26 Jan 2015 16:16:12 GMT</updated>
    <id>https://devin-clark.com/blog/global-npm-install-without-sudo/</id>
    <content type="html">&lt;p&gt;You should not have install global node modules with root! The default for directory global node modules is usually &lt;code&gt;/usr/local/&lt;/code&gt; when installing from the &lt;a href=&quot;https://www.npmjs.com/&quot;&gt;npmjs.com&lt;/a&gt; binary. This directory is not writable by users (as intended). I would like to preface this with I have only done this on a OS X. The instructions should be the same for Linux. Sorry Windows users, I can&#39;t help here.&lt;/p&gt;
&lt;p&gt;The secret to fixing this problem is to change the directory npm uses to globally install. To do this we will change the &lt;code&gt;prefix&lt;/code&gt; option in npm config. First, we can run &lt;code&gt;npm config get prefix&lt;/code&gt; to see where packages are currently being installed. Next, make a directory where you would like the packages to be installed (and is user writeable). I use &lt;code&gt;~/npm&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Next, we need to tell npm to use the newly created directory by running &lt;code&gt;npm config set prefix ~/npm&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You might think we are done now but now we will need to add &lt;code&gt;~/npm/bin&lt;/code&gt; to &lt;code&gt;$PATH&lt;/code&gt; so we can use the executables. I store &lt;code&gt;$PATH&lt;/code&gt; changes in &lt;code&gt;~/.bashrc&lt;/code&gt;. If you would like to store them in another file, feel free.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;troll type=&amp;quot;fanboy&amp;quot;&amp;gt;&lt;/code&gt;For speed I prefer to use &lt;em&gt;the best command line text editor&lt;/em&gt;, nano. &lt;code&gt;&amp;lt;/troll&amp;gt;&lt;/code&gt; Anyways, just add this to the file then restart your Terminal window.&lt;/p&gt;
&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token assign-left variable&quot;&gt;&lt;span class=&quot;token environment constant&quot;&gt;PATH&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token environment constant&quot;&gt;$PATH&lt;/span&gt;&lt;span class=&quot;token builtin class-name&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token environment constant&quot;&gt;$HOME&lt;/span&gt;/npm/bin&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That&#39;s it! You will need to reinstall any global modules you had previously installed.&lt;/p&gt;
&lt;p&gt;Also, my boss, &lt;a href=&quot;http://twitter.com/jvrousseau&quot;&gt;Jordan&lt;/a&gt; uses this setup with &lt;a href=&quot;https://github.com/creationix/nvm&quot;&gt;nvm&lt;/a&gt;. He had a problem because nvm installs global packages in versioned directories. This would break all his &lt;code&gt;npm link&lt;/code&gt;&#39;s on version updates. &lt;code&gt;npm link&lt;/code&gt; is a big part of our Node development workflow.&lt;/p&gt;
&lt;h3 id=&quot;more-information&quot;&gt;More Information &lt;a class=&quot;direct-link&quot; href=&quot;https://devin-clark.com/blog/global-npm-install-without-sudo/#more-information&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.npmjs.com/cli/config&quot;&gt;npm config&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.nano-editor.org/&quot;&gt;nano&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  
  <entry>
    <title>Nebraska JS Conference 2015</title>
    <link href="https://devin-clark.com/blog/nebraska-js-conference-2015/"/>
    <updated>Thu, 27 Aug 2015 18:27:03 GMT</updated>
    <id>https://devin-clark.com/blog/nebraska-js-conference-2015/</id>
    <content type="html">&lt;script async=&quot;&quot; src=&quot;https://platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
&lt;p&gt;&lt;a href=&quot;http://nejsconf.com/&quot;&gt;NebraskaJS Conf&lt;/a&gt; is a conference I had the pleasure of attending recently. It was held at the Omaha Henry Doorly Zoo, named the #1 Zoo in the World by TripAdvisor.&lt;/p&gt;
&lt;h2 id=&quot;responsive%2C-adaptive%2C-and-responsible-(codepo8)&quot;&gt;Responsive, Adaptive, and Responsible (codepo8) &lt;a class=&quot;direct-link&quot; href=&quot;https://devin-clark.com/blog/nebraska-js-conference-2015/#responsive%2C-adaptive%2C-and-responsible-(codepo8)&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Web design was never meant to be done in pixels&lt;/li&gt;
&lt;li&gt;&amp;quot;Are we OK with building and discarding everything we do over and over again?&amp;quot;&lt;/li&gt;
&lt;li&gt;&amp;quot;Why do we build things we don&#39;t use in production?&amp;quot;&lt;/li&gt;
&lt;li&gt;The environment we work in flows like water, there is a constant need for new ideas.&lt;/li&gt;
&lt;li&gt;&amp;quot;Best practices are found, not defined&amp;quot;.&lt;/li&gt;
&lt;li&gt;-220k +300k LOC&lt;/li&gt;
&lt;li&gt;Every HTTP request is a terrible thing&lt;/li&gt;
&lt;li&gt;&amp;quot;Most speed increases are based on analyzing and fixing developer mistakes/sloppiness&amp;quot;&lt;/li&gt;
&lt;li&gt;&amp;quot;Everything in ES6 is a syntax error in older browsers.&amp;quot;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://featuretests.io/&quot;&gt;http://featuretests.io&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Problems with transpiling:
&lt;ul&gt;
&lt;li&gt;You don&#39;t run or debug the code you write.&lt;/li&gt;
&lt;li&gt;You are at the mercy of the transpiler to create efficient code.&lt;/li&gt;
&lt;li&gt;Browsers that support ES6 will never get any [ES6 code].&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://kpdecker.github.io/six-speed/&quot;&gt;http://kpdecker.github.io/six-speed/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;We can&#39;t use ES6 safely in the browser.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://es6katas.org/&quot;&gt;http://es6katas.org&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;Learn es6 by viewing the ECMAScript unit test code&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Blaming the tool is a sign of a bad craftsman, good craftsmen improve the tools by feeding back to the tool maker.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;streams-(pam-selle)&quot;&gt;Streams (Pam Selle) &lt;a class=&quot;direct-link&quot; href=&quot;https://devin-clark.com/blog/nebraska-js-conference-2015/#streams-(pam-selle)&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://pselle.github.io/omgstreams&quot;&gt;Slides&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Streams are the most awesome data structure you don&#39;t know enough about.&lt;/li&gt;
&lt;li&gt;Comes from Unix&lt;/li&gt;
&lt;li&gt;All glory to pipe&lt;/li&gt;
&lt;li&gt;streams are delayed lists&lt;/li&gt;
&lt;li&gt;Why?
&lt;ul&gt;
&lt;li&gt;Can&#39;t/Don&#39;t want to hold everything in memory.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;INFINITE DATA
&lt;ul&gt;
&lt;li&gt;WIZARDS&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Push and Pull Modes (flavors of streams)&lt;/li&gt;
&lt;li&gt;Timeouts: &#39;Never ever block forever&#39;&lt;/li&gt;
&lt;li&gt;Node streams are push streams.&lt;/li&gt;
&lt;li&gt;Generators!
&lt;ul&gt;
&lt;li&gt;Pull streams&lt;/li&gt;
&lt;li&gt;ask for more when you want more (call next() on the generator)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;BaconJS
&lt;ul&gt;
&lt;li&gt;functional operators on events&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;HighlandJS
&lt;ul&gt;
&lt;li&gt;single interface for many data types.
&lt;ul&gt;
&lt;li&gt;Arrays, Generators, Node streams, Events, Promises.&lt;/li&gt;
&lt;li&gt;functional operations on these data types.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;RxJS - Reactive programming&lt;/li&gt;
&lt;li&gt;Trojan Horse for Reactive Programming.&lt;/li&gt;
&lt;li&gt;PRESENTATION: &lt;a href=&quot;https://www.youtube.com/watch?v=Agu6jipKfYw&quot;&gt;Evan Czaplicki at Strangeloop&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&amp;quot;Once you learn monads, you are unable to explain monads.&amp;quot;&lt;/li&gt;
&lt;li&gt;Intro to Rx by staltz.&lt;/li&gt;
&lt;li&gt;Browser streams standard (worked on by the Node team).&lt;/li&gt;
&lt;li&gt;Observable type proposal for es7
&lt;ul&gt;
&lt;li&gt;Native type&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Turing Incomplete &lt;a href=&quot;http://turing.cool/&quot;&gt;http://turing.cool&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;Pam&#39;s Podcast&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;custom-elements-(mike-macaulay)&quot;&gt;Custom Elements (Mike Macaulay) &lt;a class=&quot;direct-link&quot; href=&quot;https://devin-clark.com/blog/nebraska-js-conference-2015/#custom-elements-(mike-macaulay)&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://michaelmac.org/presentations/custom-elements/#/&quot;&gt;Slides&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;My Laptop died around here so notes became sparse (Phone typing...)&lt;/p&gt;
&lt;h2 id=&quot;architecting-communities-(amanda-harlin)&quot;&gt;Architecting Communities (Amanda Harlin) &lt;a class=&quot;direct-link&quot; href=&quot;https://devin-clark.com/blog/nebraska-js-conference-2015/#architecting-communities-(amanda-harlin)&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.google.com/presentation/d/1Bfe4p0xzQNzqWF9-Mr7_gtstGo41v1lRfF0gUBd-W1U/pub?start=false&amp;amp;loop=false&amp;amp;delayms=60000&amp;amp;slide=id.p&quot;&gt;Slides&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Amanda spoke about the practices and tooling we have put in place to make &lt;a href=&quot;http://techlahoma.org/&quot;&gt;Techlahoma&lt;/a&gt; Community successful.&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote class=&quot;twitter-tweet&quot; lang=&quot;en&quot;&gt;&lt;p lang=&quot;und&quot; dir=&quot;ltr&quot;&gt;&lt;a href=&quot;https://twitter.com/amandaharlin&quot;&gt;@amandaharlin&lt;/a&gt; at &lt;a href=&quot;https://twitter.com/hashtag/nejsconf?src=hash&quot;&gt;#nejsconf&lt;/a&gt; &lt;a href=&quot;http://t.co/1KZs9bNQdi&quot;&gt;pic.twitter.com/1KZs9bNQdi&lt;/a&gt;&lt;/p&gt;&amp;mdash; The Jessinator (@SeeJessicaCode) &lt;a href=&quot;https://twitter.com/SeeJessicaCode/status/629722674390904832&quot;&gt;August 7, 2015&lt;/a&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;twitter-tweet&quot; lang=&quot;en&quot;&gt;&lt;p lang=&quot;und&quot; dir=&quot;ltr&quot;&gt;&lt;a href=&quot;https://twitter.com/hashtag/nejsconf?src=hash&quot;&gt;#nejsconf&lt;/a&gt; &lt;a href=&quot;http://t.co/QXzrIiEAGt&quot;&gt;pic.twitter.com/QXzrIiEAGt&lt;/a&gt;&lt;/p&gt;&amp;mdash; Devin Clark (@iDevinClark) &lt;a href=&quot;https://twitter.com/iDevinClark/status/629725935890100224&quot;&gt;August 7, 2015&lt;/a&gt;&lt;/blockquote&gt;
&lt;h2 id=&quot;high-performance-in-the-critical-rendering-path-(%40ponyfoo)&quot;&gt;High Performance in the Critical Rendering Path (@ponyfoo) &lt;a class=&quot;direct-link&quot; href=&quot;https://devin-clark.com/blog/nebraska-js-conference-2015/#high-performance-in-the-critical-rendering-path-(%40ponyfoo)&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Slides: &lt;a href=&quot;https://speakerdeck.com/bevacqua/high-performance-in-the-critical-path-nejsconf&quot;&gt;High Performance in Critical Rendering Path&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;measuring&quot;&gt;Measuring &lt;a class=&quot;direct-link&quot; href=&quot;https://devin-clark.com/blog/nebraska-js-conference-2015/#measuring&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Devtools Audits&lt;/li&gt;
&lt;li&gt;Measure early; Measure often.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;perf&quot;&gt;Perf &lt;a class=&quot;direct-link&quot; href=&quot;https://devin-clark.com/blog/nebraska-js-conference-2015/#perf&quot;&gt;#&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Optimize tcp&lt;/li&gt;
&lt;li&gt;Gzip all text&lt;/li&gt;
&lt;li&gt;Keep alive&lt;/li&gt;
&lt;li&gt;Use nginx gzip. Everywhere. Now.&lt;/li&gt;
&lt;li&gt;Defer font loading. Check &lt;a href=&quot;https://speakerdeck.com/bevacqua/high-performance-in-the-critical-path-nejsconf?slide=41&quot;&gt;slides for code&lt;/a&gt;. Very cool.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/pocketjoso/penthouse&quot;&gt;Penthouse&lt;/a&gt; for critical path css&lt;/li&gt;
&lt;li&gt;So many more tools in the slides.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;universal-javascript-(bruce-coddington)&quot;&gt;Universal JavaScript (Bruce Coddington) &lt;a class=&quot;direct-link&quot; href=&quot;https://devin-clark.com/blog/nebraska-js-conference-2015/#universal-javascript-(bruce-coddington)&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.slideshare.net/BruceCoddington/reacting-to-the-isomorphic-buzz&quot;&gt;Slides&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/nicknisi/dotfiles/blob/master/vim/vimrc.symlink&quot;&gt;Nick&#39;s vimrc file&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;Still working on making my way through this...&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Server-side React&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote class=&quot;twitter-tweet&quot; lang=&quot;en&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;&amp;quot;I&amp;#39;m going to hurry up and finish my talk before they change things on me.&amp;quot; &lt;a href=&quot;https://twitter.com/BruceCoddington&quot;&gt;@BruceCoddington&lt;/a&gt; &lt;a href=&quot;https://twitter.com/hashtag/nejsconf?src=hash&quot;&gt;#nejsconf&lt;/a&gt;&lt;/p&gt;&amp;mdash; Dave Reid (@davereid) &lt;a href=&quot;https://twitter.com/davereid/status/629714749656272900&quot;&gt;August 7, 2015&lt;/a&gt;&lt;/blockquote&gt;
&lt;h2 id=&quot;lily&quot;&gt;Lily &lt;a class=&quot;direct-link&quot; href=&quot;https://devin-clark.com/blog/nebraska-js-conference-2015/#lily&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Lily is a surprise speaker who spoke about how she is learning to code using &lt;a href=&quot;https://bitsbox.com/&quot;&gt;bitsbox.com&lt;/a&gt;.&lt;/p&gt;
&lt;blockquote class=&quot;twitter-tweet&quot; lang=&quot;en&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;Welcome our youngest speaker, Lily! &lt;a href=&quot;https://twitter.com/LilyNEJSConf&quot;&gt;@LilyNEJSConf&lt;/a&gt; &lt;a href=&quot;http://t.co/V2Q6OPOgvg&quot;&gt;pic.twitter.com/V2Q6OPOgvg&lt;/a&gt;&lt;/p&gt;&amp;mdash; NEJS CONF 2015 (@nejsconf) &lt;a href=&quot;https://twitter.com/nejsconf/status/629728970208972800&quot;&gt;August 7, 2015&lt;/a&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;twitter-tweet&quot; lang=&quot;en&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;8 year old lily showing &lt;a href=&quot;https://twitter.com/hashtag/nejsconf?src=hash&quot;&gt;#nejsconf&lt;/a&gt; the JS game she coded using &lt;a href=&quot;https://twitter.com/BitsboxKids&quot;&gt;@BitsboxKids&lt;/a&gt;. Can&amp;#39;t compete with that. I&amp;#39;m done. &lt;a href=&quot;http://t.co/QPJpotXVGF&quot;&gt;pic.twitter.com/QPJpotXVGF&lt;/a&gt;&lt;/p&gt;&amp;mdash; Christian Heilmann (@codepo8) &lt;a href=&quot;https://twitter.com/codepo8/status/629729132285263872&quot;&gt;August 7, 2015&lt;/a&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;twitter-tweet&quot; lang=&quot;en&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;Next speaker is Lilly who&amp;#39;s going into the third grade. Presenting now on what&amp;#39;s she&amp;#39;s learned with JS. &lt;a href=&quot;https://twitter.com/nejsconf&quot;&gt;@nejsconf&lt;/a&gt; &lt;a href=&quot;http://t.co/3KCUAon30e&quot;&gt;pic.twitter.com/3KCUAon30e&lt;/a&gt;&lt;/p&gt;&amp;mdash; amanda harlin (@amandaharlin) &lt;a href=&quot;https://twitter.com/amandaharlin/status/629728527865098240&quot;&gt;August 7, 2015&lt;/a&gt;&lt;/blockquote&gt;
&lt;h2 id=&quot;final-(read%3A-random)-thoughts&quot;&gt;Final (Read: Random) Thoughts &lt;a class=&quot;direct-link&quot; href=&quot;https://devin-clark.com/blog/nebraska-js-conference-2015/#final-(read%3A-random)-thoughts&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;blockquote class=&quot;twitter-tweet&quot; lang=&quot;en&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;Drone group photo at &lt;a href=&quot;https://twitter.com/hashtag/nejsconf?src=hash&quot;&gt;#nejsconf&lt;/a&gt;! &lt;a href=&quot;https://t.co/4hiwkreB4q&quot;&gt;https://t.co/4hiwkreB4q&lt;/a&gt;&lt;/p&gt;&amp;mdash; Matt Steele (@mattdsteele) &lt;a href=&quot;https://twitter.com/mattdsteele/status/629880500090478593&quot;&gt;August 8, 2015&lt;/a&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;twitter-tweet&quot; lang=&quot;en&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;Wildlife at &lt;a href=&quot;https://twitter.com/hashtag/nejsconf?src=hash&quot;&gt;#nejsconf&lt;/a&gt; &lt;a href=&quot;http://t.co/PJmlSvaw4S&quot;&gt;pic.twitter.com/PJmlSvaw4S&lt;/a&gt;&lt;/p&gt;&amp;mdash; Ryan Stille (@RyanStille) &lt;a href=&quot;https://twitter.com/RyanStille/status/629732235298541568&quot;&gt;August 7, 2015&lt;/a&gt;&lt;/blockquote&gt;
&lt;p&gt;Nope&#39;d the hell out around this time. I did &lt;em&gt;almost&lt;/em&gt; get to touch a shark though. That was pretty cool.&lt;/p&gt;
&lt;blockquote class=&quot;twitter-tweet&quot; lang=&quot;en&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;How many other JS conferences can you pet a shark? Thats right, nowhere but &lt;a href=&quot;https://twitter.com/hashtag/nejsconf?src=hash&quot;&gt;#nejsconf&lt;/a&gt; &lt;a href=&quot;http://t.co/OteamIPnX6&quot;&gt;pic.twitter.com/OteamIPnX6&lt;/a&gt;&lt;/p&gt;&amp;mdash; Justin Baker (@ezbakejustin) &lt;a href=&quot;https://twitter.com/ezbakejustin/status/629681805780611072&quot;&gt;August 7, 2015&lt;/a&gt;&lt;/blockquote&gt;
&lt;p&gt;&lt;a href=&quot;https://thesuperbytes.bandcamp.com/&quot;&gt;The SuperBytes&lt;/a&gt; played at the afterparty. They are really good. 8-bit punk rock band.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Testing React Components with Enzyme</title>
    <link href="https://devin-clark.com/blog/testing-react-components-enzyme/"/>
    <updated>Mon, 28 Mar 2016 21:44:31 GMT</updated>
    <id>https://devin-clark.com/blog/testing-react-components-enzyme/</id>
    <content type="html">&lt;p&gt;We finally boarded the React train and it is great. I looked at &lt;a href=&quot;https://github.com/airbnb/enzyme&quot;&gt;Enzyme&lt;/a&gt; and &lt;a href=&quot;https://facebook.github.io/jest/&quot;&gt;Jest&lt;/a&gt;. Enzyme seems a lot easier to use so I chose it. I am impressed with how it turned out.&lt;/p&gt;
&lt;p&gt;For this workflow, you will need to install these packages.&lt;/p&gt;
&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;npm&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;install&lt;/span&gt; enzyme babel-register babel-preset-react chai mocha react-addons-test-utils --save-dev&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is the relevant part of the &lt;code&gt;package.json&lt;/code&gt; file. The first argument to the &lt;code&gt;mocha&lt;/code&gt; command is a setup file for mocha. The second is a glob for all the test files. I am using an npm script for this but use whatever.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token string-property property&quot;&gt;&quot;scripts&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token string-property property&quot;&gt;&quot;test&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;mocha website/test/.setup.js website/test/**/*-test.js&quot;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here is the &lt;code&gt;.setup.js&lt;/code&gt; file. It adds &lt;code&gt;babel-register&lt;/code&gt; with the react preset. This allows JSX to work in the tests.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;babel-register&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;presets&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;react&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we have a small stateless react component that we are going to test. Stateless React components are pure functions without internal state or lifecycle methods. You should use these anywhere you are not using state or any of the component lifecycle methods. Pure functions are easier to test. Given the same input, a pure function always return the same output.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; React &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;react&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Burrito&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;props&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token string&quot;&gt;&#39;use strict&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div className&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;props&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;name&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;props&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;ingredients &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; props&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;ingredients&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;, &#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

Burrito&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;defaultProps &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;burrito&#39;&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;ingredients&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

Burrito&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;propTypes &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;PropTypes&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;string&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;ingredients&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;PropTypes&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;array
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

module&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;exports &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Burrito&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, let&#39;s test this component. Enzyme allows us to &lt;a href=&quot;http://airbnb.io/enzyme/docs/api/shallow.html&quot;&gt;shallow render a component&lt;/a&gt;, then exposes an API to get and set data on the rendered component. My favorite part is it doesn&#39;t use PhantomJS. We are going to use &lt;code&gt;.text()&lt;/code&gt; and &lt;code&gt;.hasClass(classname)&lt;/code&gt; in this example.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; wrapper &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; enzyme&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;shallow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Burrito &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;expect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;wrapper&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;to&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;equal&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We did it! In this test, we &lt;a href=&quot;http://airbnb.io/enzyme/docs/api/shallow.html&quot;&gt;shallow render&lt;/a&gt; our Burrito component, then we &lt;code&gt;expect&lt;/code&gt; (a &lt;a href=&quot;http://chaijs.com/&quot;&gt;chai&lt;/a&gt; function) the text of the rendered component to be empty.&lt;/p&gt;
&lt;p&gt;We can also do something similar with &lt;code&gt;hasClass&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; wrapper &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; enzyme&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;shallow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Burrito &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;expect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;wrapper&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;hasClass&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;burrito&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;to&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;equal&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here is a full example for testing the Burrito component we created.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; React &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;react&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; expect &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;chai&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;expect&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; enzyme &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;enzyme&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; Burrito &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;../js/components/Burrito&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token function&quot;&gt;describe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;&amp;lt;Burrito /&gt;&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token string&quot;&gt;&#39;use strict&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token function&quot;&gt;describe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;Text: &#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;it&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;renders no text with no props&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; wrapper &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; enzyme&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;shallow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Burrito &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;token function&quot;&gt;expect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;wrapper&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;to&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;equal&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;token function&quot;&gt;it&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;renders no text with no props&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; wrapper &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; enzyme&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;shallow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Burrito ingredients&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;chicken&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;beans&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;token function&quot;&gt;expect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;wrapper&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;to&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;equal&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;chicken, beans&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token function&quot;&gt;describe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;Name: &#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;it&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;is named &#39;burrito&#39; with no props&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; wrapper &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; enzyme&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;shallow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Burrito &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;token function&quot;&gt;expect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;wrapper&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;hasClass&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;burrito&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;to&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;equal&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;token function&quot;&gt;it&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;is named &#39;the-james-mason&#39; with &#39;the-james-mason&#39; passed as name&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; wrapper &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; enzyme&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;shallow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Burrito name&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;the-james-mason&quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;token function&quot;&gt;expect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;wrapper&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;hasClass&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;the-james-mason&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;to&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;equal&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Test coverage is another cool thing I did. I used &lt;a href=&quot;https://github.com/bcoe/nyc&quot;&gt;nyc&lt;/a&gt; to generate a coverage report after the tests run. The coverage report shows you what percentage of each file&#39;s statements, branches, and functions are tested. To run nyc, you can change the mocha npm script to look the code below.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token string-property property&quot;&gt;&quot;scripts&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token string-property property&quot;&gt;&quot;test&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;nyc mocha website/test/.setup.js website/test/**/*-test.js&quot;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It seems a bit magical to me but it did help me uncover missing paths in my tests.&lt;/p&gt;
&lt;p&gt;Writing tests like these for all your components gives an incredible peace of mind. Generating test coverage will help ensure we are testing everything. I may try &lt;a href=&quot;https://github.com/sindresorhus/ava&quot;&gt;Ava&lt;/a&gt; instead of Mocha in the future.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>A Simple Build Process for React and JSX</title>
    <link href="https://devin-clark.com/blog/simple-react-jsx-build-process/"/>
    <updated>Tue, 28 Jun 2016 19:00:39 GMT</updated>
    <id>https://devin-clark.com/blog/simple-react-jsx-build-process/</id>
    <content type="html">&lt;p&gt;Unfortunately, build processes are a big part of JavaScript development. Build processes do not have to be complicated, despite what you may have heard. Let&#39;s jump in with my default for building React and JSX projects. I say &amp;quot;default&amp;quot; because if the project gets complicated I will move to using Gulp. An example of a more complicated project is one with multiple entry points.&lt;/p&gt;
&lt;p&gt;Previously, I used the &lt;a href=&quot;https://github.com/andreypopp/reactify&quot;&gt;reactify transform&lt;/a&gt; but it has been deprecated in favor of &lt;a href=&quot;https://github.com/babel/babelify&quot;&gt;babelify&lt;/a&gt;. We will use babelify.&lt;/p&gt;
&lt;p&gt;First, we install these packages.&lt;/p&gt;
&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;npm&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;install&lt;/span&gt; browserify watchify babelify babel-preset-react --save-dev&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Next, we add some configuration to our &lt;code&gt;package.json&lt;/code&gt; file.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token string-property property&quot;&gt;&quot;browserify&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token string-property property&quot;&gt;&quot;transform&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
      &lt;span class=&quot;token string&quot;&gt;&quot;babelify&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token string-property property&quot;&gt;&quot;presets&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
          &lt;span class=&quot;token string&quot;&gt;&quot;react&quot;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we are configuring browserify to use the &lt;a href=&quot;https://github.com/babel/babelify&quot;&gt;babelify transform&lt;/a&gt; and using &lt;a href=&quot;https://www.npmjs.com/package/babel-preset-react&quot;&gt;babel-preset-react&lt;/a&gt; to handle the JSX part.&lt;/p&gt;
&lt;p&gt;Finally, we need to add some npm scripts so we can run this.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token string-property property&quot;&gt;&quot;scripts&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token string-property property&quot;&gt;&quot;build&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;browserify index.js -o bundle.js&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token string-property property&quot;&gt;&quot;watch&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;watchify index.js -vo bundle.js&quot;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we are able to run &lt;code&gt;npm run watch&lt;/code&gt; and &lt;code&gt;npm run build&lt;/code&gt;. Watch will watch our files and run browserify on change. We use this while working. Build will run browserify. This is really only used by our build server.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Deep Objects in Lodash</title>
    <link href="https://devin-clark.com/blog/deep-objects-lodash/"/>
    <updated>Mon, 17 Oct 2016 00:51:49 GMT</updated>
    <id>https://devin-clark.com/blog/deep-objects-lodash/</id>
    <content type="html">&lt;p&gt;A quick introduction to two Lodash methods I found recently, &lt;code&gt;_.get&lt;/code&gt; and &lt;code&gt;_.set&lt;/code&gt;, to help work with deeply nested objects.&lt;/p&gt;
&lt;p&gt;Let&#39;s say I have this object and I want to get the name.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; a &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token literal-property property&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token literal-property property&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;Arya&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Normally, we would be able to do &lt;code&gt;a.b[0].c.name&lt;/code&gt; but what if one of the values turned out to be null? This is common when we are waiting for data from an HTTP request or another source. We usually solve this by constructing this big mess that checks for falsy values at each step.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; a &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; a&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;b &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; a&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;b&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; a&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;b&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;c &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; a&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;b&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;c&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;name&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// =&gt; &#39;Arya&#39;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let&#39;s clean this up using Lodash&#39;s &lt;code&gt;get&lt;/code&gt; method.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; _&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;b[0].c.name&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// =&gt; &#39;Arya&#39;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We can also provide a default value as the third argument.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; _&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;b[0].c.name&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;A girl has no name&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// =&gt; &#39;Arya&#39;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; _&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;b[1].c.name&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;A girl has no name&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// =&gt; &#39;A girl has no name&#39;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I really like how much this cleans up the code.&lt;/p&gt;
&lt;p&gt;We can also generate the object using &lt;code&gt;_.set&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; a &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

_&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;b[0].c.name&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;Arya&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// =&gt; {b: [{c: {name: &#39;Arya&#39;}}]}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It is important to note that &lt;code&gt;_.set&lt;/code&gt; mutates the passed object. To solve this, I would do something like this.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; a &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; new_a &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; _&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Object&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;assign&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; a&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;b[0].c.name&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;Arya&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// =&gt; {b: [{c: {name: &#39;Arya&#39;}}]}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To read more about these methods, check out the documentation for &lt;a href=&quot;https://lodash.com/docs/4.16.4#get&quot;&gt;get&lt;/a&gt; and &lt;a href=&quot;https://lodash.com/docs/4.16.4#set&quot;&gt;set&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Use Fetch</title>
    <link href="https://devin-clark.com/blog/use-fetch/"/>
    <updated>Wed, 30 Nov 2016 18:36:13 GMT</updated>
    <id>https://devin-clark.com/blog/use-fetch/</id>
    <content type="html">&lt;p&gt;How do &lt;strong&gt;you&lt;/strong&gt; make an HTTP request in JavaScript? Do you pull in jQuery? Write your own XMLHttpRequest? There&#39;s a better way.&lt;/p&gt;
&lt;p&gt;Enter &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API&quot;&gt;fetch&lt;/a&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;toJSON&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; response&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

window
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;http://catfacts-api.appspot.com/api/facts&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;toJSON&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;response&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// =&gt; {facts: [&quot;Cat families usually play best in even numbers. Cats and kittens should be acquired in pairs whenever possible.&quot;], success: &quot;true&quot;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This code will make a GET request to the catfacts API, parse the response as JSON, and log out the response to the console.&lt;/p&gt;
&lt;p&gt;The bad news is support isn&#39;t super amazing with &lt;a href=&quot;http://caniuse.com/#search=fetch&quot;&gt;some browsers&lt;/a&gt; (as of November 2016). The good news is there are a handful of polyfills. &lt;a href=&quot;https://github.com/github/fetch&quot;&gt;whatwg-fetch by Github&lt;/a&gt; is a great one and it is a lot smaller than jQuery (and probably smaller than your XMLHttpRequest wrapper if it is feature-complete).&lt;/p&gt;
&lt;p&gt;You can also use this in Node (and we do at &lt;a href=&quot;http://wdtinc.com/&quot;&gt;WDT&lt;/a&gt;) using &lt;a href=&quot;https://github.com/matthew-andrews/isomorphic-fetch&quot;&gt;isomorphic-fetch&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The things I love about &lt;code&gt;fetch&lt;/code&gt; is that it has the API of a lot of the ajax wrappers out there.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Virtualized Rendering in React</title>
    <link href="https://devin-clark.com/blog/virtualized-rendering-in-react/"/>
    <updated>Mon, 27 Nov 2017 09:32:00 GMT</updated>
    <id>https://devin-clark.com/blog/virtualized-rendering-in-react/</id>
    <content type="html">&lt;p&gt;Virtual rendering (also known as virtualized rendering, windowing, and a number of other terms) is a method of only rendering the elements that need to be rendered to the DOM.&lt;/p&gt;
&lt;p&gt;A common example of this is a list of a million items but only ten are visible at any time. Rendering the entire list would be incredibly inefficient, and slow, but rendering 10 to 15 items at a time and more as you scroll makes things much faster.&lt;/p&gt;
&lt;p&gt;If your growth-driven startup has any chance of scaling, this is very important to consider.&lt;/p&gt;
&lt;p&gt;There are a handful of existing libraries that you can use to render in this way. &lt;a href=&quot;https://github.com/bvaughn/react-virtualized&quot;&gt;React Virtualized&lt;/a&gt; is my favorite. It also includes support for grids, tables, infinite scrolling, and even &#39;masonry-style&#39; layouts.&lt;/p&gt;
&lt;p&gt;If you are a VC-funded growth-driven startup, you probably don&#39;t want to use a library. You have the resources, the drive, and the overwhelming need to invent your own. Using a library is really more for bootstrap growth-driven startups.&lt;/p&gt;
&lt;p&gt;Here is a quick implementation of a list, using React Virtualized. You can view this &lt;a href=&quot;https://codesandbox.io/s/ykmnl65nlz&quot;&gt;demo on Code Sandbox&lt;/a&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; render &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;react-dom&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; React &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;react&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; List &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;react-virtualized&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Generate a big list.&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// Ignore the man behind the curtain.&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; list &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Array&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token literal-property property&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;100000&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;v&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; i&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; i&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Generate each row&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rowRenderer&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; key&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; index&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; style &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;div key&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;key&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; style&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;style&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;
      Disruption Idea #&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;list&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;index&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;div&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Render our list&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;List width&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;220&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; height&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;400&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; rowCount&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;list&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;length&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; rowHeight&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; rowRenderer&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;rowRenderer&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  document&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;root&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In a later post, we are going follow in the footsteps of a VC-funded growth-driven startup and build our own basic version of a virtual list.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Slimmer Code Reviews with Husky</title>
    <link href="https://devin-clark.com/blog/husky-githooks/"/>
    <updated>Thu, 15 Mar 2018 17:53:25 GMT</updated>
    <id>https://devin-clark.com/blog/husky-githooks/</id>
    <content type="html">&lt;p&gt;&lt;a href=&quot;https://github.com/typicode/husky&quot;&gt;Husky&lt;/a&gt; is a simple tool for configuring Git hooks in a project. It really shines when you need to easily configure Git hooks for a project across a team. That is what we are going to do today.&lt;/p&gt;
&lt;p&gt;First, we need to add a script to our &lt;code&gt;package.json&lt;/code&gt; file. We already have an existing command for eslint configured (&lt;code&gt;npm run lint&lt;/code&gt;), so all we need to do to get Husky configured is add a &lt;code&gt;prepush&lt;/code&gt; script that runs the lint script.&lt;/p&gt;
&lt;pre class=&quot;language-json&quot;&gt;&lt;code class=&quot;language-json&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  …
  &lt;span class=&quot;token property&quot;&gt;&quot;scripts&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;&quot;lint&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;gulp lint&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token property&quot;&gt;&quot;prepush&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;npm run lint&quot;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  …
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Next, we can install husky into our project using the following command.&lt;/p&gt;
&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;npm&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;install&lt;/span&gt; husky --save-dev&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It might seem like we should have done this first but Husky itself works by using an &lt;code&gt;npm install&lt;/code&gt; lifecycle hook that fires after &lt;code&gt;npm install&lt;/code&gt; is run. This means the husky setup we just did will take effect now.&lt;/p&gt;
&lt;p&gt;Now you can commit and push these changes. You will see that it runs the linting script before the push runs. If the linting script fails, the push will not happen.&lt;/p&gt;
&lt;p&gt;There is another tool called &lt;a href=&quot;https://github.com/okonet/lint-staged&quot;&gt;lint-staged&lt;/a&gt; that will run a given script only on staged files in Git. This is great if want if you are trying to slowly roll linting into a project and taking things a file at a time. It is not a replacement for Husky. It is really more of an enhancement to Husky. We can go over lint-staged in more detail in a later article.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>JavaScript Styling with Feeling</title>
    <link href="https://devin-clark.com/blog/js-with-feeling/"/>
    <updated>Fri, 11 May 2018 09:32:00 GMT</updated>
    <id>https://devin-clark.com/blog/js-with-feeling/</id>
    <content type="html">&lt;p&gt;This is a quick introduction to how I did CSS-in-JS on a recent project using &lt;a href=&quot;https://emotion.sh/&quot;&gt;Emotion&lt;/a&gt; and &lt;a href=&quot;https://preactjs.com/&quot;&gt;Preact&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To start, I need to install emotion and a Babel plugin. The Babel plugin generates source maps and optimizes style output. Emotion highly recommends this for production use.&lt;/p&gt;
&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;npm&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;--save&lt;/span&gt; emotion
&lt;span class=&quot;token function&quot;&gt;npm&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;install&lt;/span&gt; --save-dev babel-plugin-emotion&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Create a .babelrc file (or add the emotion parts to my existing babelrc file). Source maps will add a lot of weight to my bundle, so I am disabling them in production.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token string-property property&quot;&gt;&quot;env&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token string-property property&quot;&gt;&quot;production&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token string-property property&quot;&gt;&quot;plugins&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;emotion&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token string-property property&quot;&gt;&quot;sourceMap&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token string-property property&quot;&gt;&quot;development&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token string-property property&quot;&gt;&quot;plugins&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;emotion&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token string-property property&quot;&gt;&quot;sourceMap&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, I can start making components. I&#39;ve made a basic component to define a section with padding on the bottom. I prefer defining the styles as objects instead of template tags. It feels more natural in JavaScript to me. I wrap all the styles in a styles object. The individual items in the style object are wrapped in emotion&#39;s css function.&lt;/p&gt;
&lt;pre class=&quot;language-jsx&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; css &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;emotion&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; h &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;preact&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;GRID_UNIT&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;../constants/layout&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; styles &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;container&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;css&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;paddingBottom&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;GRID_UNIT&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Section&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;section&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;styles&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;container&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;props&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;children&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;section&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;GRID_UNIT&lt;/code&gt; is a constant I have defined with a value of 8. I make all my dimensions, margins, and padding a multiple of this number. Because of this I am able to get a very uniform interface without much effort.&lt;/p&gt;
&lt;p&gt;To use the styles, I just pass the style I want to className. If I need to do any kind of composition I can use &lt;code&gt;cx&lt;/code&gt; from emotion and pass an array of styles that are merged together. &lt;code&gt;cx&lt;/code&gt; uses the &lt;a href=&quot;https://github.com/JedWatson/classnames&quot;&gt;classnames API&lt;/a&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-jsx&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; css&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; cx &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;emotion&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; h &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;preact&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;GRID_UNIT&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;../constants/layout&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; styles &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;container&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;css&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;fontSize&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;paddingBottom&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;GRID_UNIT&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;SectionHeading&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;props&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;h2&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;cx&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;styles&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;container&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; props&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;className&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;props&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;children&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;h2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;By passing &lt;code&gt;props.className&lt;/code&gt; to &lt;code&gt;cx&lt;/code&gt; I can override the default styles.&lt;/p&gt;
&lt;pre class=&quot;language-jsx&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; styles &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;specialHeading&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;css&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;fontSize&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;22&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;blue&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;SectionHeading&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;className&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;styles&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;specialHeading&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;Very Special Heading&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;SectionHeading&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Next, I use &lt;code&gt;injectGlobal&lt;/code&gt; to do a simple CSS reset.&lt;/p&gt;
&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; injectGlobal &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;emotion&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token function&quot;&gt;injectGlobal&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token literal-property property&quot;&gt;html&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;boxSizing&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;border-box&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;

  &lt;span class=&quot;token string-property property&quot;&gt;&#39;*&#39;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;boxSizing&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;inherit&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;margin&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token literal-property property&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;

    &lt;span class=&quot;token string-property property&quot;&gt;&#39;:before&#39;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token literal-property property&quot;&gt;boxSizing&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;inherit&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;

    &lt;span class=&quot;token string-property property&quot;&gt;&#39;:after&#39;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token literal-property property&quot;&gt;boxSizing&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39;inherit&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Being able to snapshot test the styles using jest-emotion is a big plus for me too. You can read more about that on the &lt;a href=&quot;https://emotion.sh/docs/jest-emotion&quot;&gt;Emotion docs&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Knex and Postgres</title>
    <link href="https://magistratehq.com/blog/knexjs-postgres/"/>
    <updated>Thu, 02 Jul 2020 00:00:00 GMT</updated>
    <id>https://magistratehq.com/blog/knexjs-postgres/</id>
    <content type="html">An introduction to using Knex.js and Postgres originally appearing on Magistrate&#39;s blog.</content>
  </entry>
  
  <entry>
    <title>Gravatars and Postgres 12 using Generated Columns</title>
    <link href="https://www.magistratehq.com/blog/generated-columns-postgres/"/>
    <updated>Wed, 08 Jul 2020 00:00:00 GMT</updated>
    <id>https://www.magistratehq.com/blog/generated-columns-postgres/</id>
    <content type="html">A quick look at an interesting use case for generated columns in Postgres originally appearing on Magistrate&#39;s blog.</content>
  </entry>
  
  <entry>
    <title>Case-Insensitive Text Columns in Postgres with citext</title>
    <link href="https://www.magistratehq.com/blog/citext-extension/"/>
    <updated>Sat, 15 Aug 2020 00:00:00 GMT</updated>
    <id>https://www.magistratehq.com/blog/citext-extension/</id>
    <content type="html">A dive into Postgres&#39; citext extension originally appearing on Magistrate&#39;s blog.</content>
  </entry>
  
  <entry>
    <title>Storing Timezones in Postgres</title>
    <link href="https://www.magistratehq.com/blog/user-timezones-in-postgres/"/>
    <updated>Thu, 01 Oct 2020 00:00:00 GMT</updated>
    <id>https://www.magistratehq.com/blog/user-timezones-in-postgres/</id>
    <content type="html">A quick tip on storing a user&#39;s timezone in Postgres using build-in utilities originally appearing on Magistrate&#39;s blog.</content>
  </entry>
  
  <entry>
    <title>Set Postgres System Timezone</title>
    <link href="https://www.magistratehq.com/blog/set-postgres-system-timezone/"/>
    <updated>Tue, 20 Oct 2020 00:00:00 GMT</updated>
    <id>https://www.magistratehq.com/blog/set-postgres-system-timezone/</id>
    <content type="html">A quick guide on how to set Postgres system timezone in a way that works across restarts originally appearing on Magistrate&#39;s blog.</content>
  </entry>
</feed>
