<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Matthew Johnson on Medium]]></title>
        <description><![CDATA[Stories by Matthew Johnson on Medium]]></description>
        <link>https://medium.com/@matthew.johnson?source=rss-6812e3ca2e51------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*r7QzqrR1z_y8Ajlo.</url>
            <title>Stories by Matthew Johnson on Medium</title>
            <link>https://medium.com/@matthew.johnson?source=rss-6812e3ca2e51------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 18:44:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@matthew.johnson/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A bit of development with bit.dev]]></title>
            <link>https://medium.com/@matthew.johnson/a-bit-of-development-with-bit-dev-2cb0c767fdbd?source=rss-6812e3ca2e51------2</link>
            <guid isPermaLink="false">https://medium.com/p/2cb0c767fdbd</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[components]]></category>
            <category><![CDATA[bit]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Matthew Johnson]]></dc:creator>
            <pubDate>Fri, 09 Aug 2019 21:35:09 GMT</pubDate>
            <atom:updated>2019-08-09T21:35:09.998Z</atom:updated>
            <content:encoded><![CDATA[<p>A quick dive into sharing components on bit.dev</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jbxmx-Q4xiaQbLSyMcGA7Q.jpeg" /><figcaption>A picture of a computer…’cause this is article is computer related…</figcaption></figure><p>I recently came across <a href="https://bit.dev/">bit.dev</a>, a component sharing platform for developers. The entire concept was intriguing to me. Bit.dev allows you to view the components in action, see the code behind it, tweak the example, <em>and</em> it can serve as a registry for the components you find there. It even has a fairly generous free tier. They’ve got my interest, what’s the catch? Maybe it’s horrible to work with? It was time to find out!</p><h3>Getting a Component to Share</h3><p>I wanted to play with Bit, not get tangled in actually building out new things. So, I took some shortcuts. I already had something ready-made to be a component hanging out in CodePen, a simple loading animation:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fmathieujonson%2Fembed%2Fpreview%2FmVQmbL%3Fheight%3D600%26slug-hash%3DmVQmbL%26default-tabs%3Dcss%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;url=https%3A%2F%2Fcodepen.io%2Fmathieujonson%2Fpen%2FmVQmbL&amp;image=https%3A%2F%2Fscreenshot.codepen.io%2F335492.mVQmbL.small.4f8acb5e-d39c-4c29-9b7a-edcefcdcb7a4.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6b2b49cb18c05af397f743798db3547/href">https://medium.com/media/c6b2b49cb18c05af397f743798db3547/href</a></iframe><p><strong>BOOM!</strong> All the creative stuff was <em>DONE!</em> It wasn’t a ready-made component, though, so there was still some work to be done before I could actually start playing with my shiny new toy. I used <a href="https://github.com/facebook/create-react-app">create-react-app</a> to get a cheap dev environment, and moved my CodePen work in. I added a components directory to the project, and added the ‘pen under a component named Waiter. The structure ended up looking like:</p><pre>/src<br>  /components<br>    /Waiter<br>      Waiter.js<br>      waiter.css</pre><h3>Diving Into Bit</h3><p>Finally, I got to play with Bit! The initial start wasn’t at all bad. I ran the required npm install bit-bin -g to get bit on my box, and bit init from inside the project. From there, it was just a matter of telling Bit to track my components: bit add src/components/*. The similarities between Git and Bit are <em>not</em> lost on me. I’ve typed git init and git add enough that the familiarity between the two was oddly comforting.</p><p>Following their <a href="https://docs.bit.dev/">docs</a>, setting up a compiler was next on the list. As dreadful as <em>that</em> sounds, it was yet another one-liner:</p><p>bit import bit.envs/compilers/react -c</p><p>Painless! It also opened up my eyes a <em>bit</em> to the power of the platform. They have a <a href="https://bit.dev/bit/envs">whole collection</a> of ready-made compilers and environments. React? Vue? Angular? Yeah, they’ve got it handled already. Another point for Bit!</p><p>My Waiter component is about as simple as things get. But, I’ve got big plans! I want to be able to pass in colors to use. I want to pass in a size, so my loading graphic can be as big or small as I need. Maybe different shapes? Who knows?! <em>The sky is the limit!</em> Fortunately, Bit even handles versioning. And much like everything else, it’s a simple one-liner:</p><p>bit tag waiter 0.0.1</p><p>According to the docs, there was only one step left in my journey. Another one-liner, bit export mathieujonson.components, and my component would be shared with the world! Or so I thought. My first hiccup. Though I created an account with bit.dev through Github, that command kept asking for a username and password. I had none!</p><p>Fortunately, I didn’t get stuck for long. It turns out, Bit also allows you to <a href="https://docs.bit.dev/docs/setup-authentication.html">set up SSH keys</a>, eliminating the need for usernames and passwords altogether. Another <em>huge</em> plus for Bit…plus, I was back in business!</p><p>Running the export command a second time, it was smooth sailing. And just like that, my component was out in the world, ready to be viewed and used by millions of people across the web. Ok, so, maybe just ready to be viewed by the people that read this article. But still, it <em>could</em> be ready for use by millions, just sayin’. You can check it out by viewing <a href="https://bit.dev/mathieujonson/">my profile</a>. While you’re there, click that little “follow” button. Maybe I’ll add some more stuffs!</p><p>So how does the sharing work, exactly? Some poor unfortunate soul finds my component, and decides they want to use it. How much of a lift is it to get my component out of Bit, and into their project? You guessed it! Another one liner:</p><p>npm i @bit/mathieujonson.components.waiter</p><p>Bit even goes so far as to make that one-liner a click-to-copy button. And if npm isn’t your thing? Maybe you prefer yarn? They have a button for that, too. They’ve gone to great lengths to make this a simple-to-use platform, and they’ve done a good job of hitting that goal.</p><h3>Final Thoughts</h3><p>My only real complaint, so far, is that the preview of the component doesn’t display like the other previews on the site. I’m sure it’s something I’ve done wrong, but that fact that it doesn’t just automagically work makes me ding the rating a bit. I give this thing a 4.9 stars out of 5. The tool itself is simple, intuitive, and can make sharing work between projects and teams a breeze. The bit.dev website is sleek and appealing, and easy to navigate. I’ll be keeping an eye on them, and I hope you do as well!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2cb0c767fdbd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Safari is the new IE, but this time they got it right]]></title>
            <link>https://medium.com/@matthew.johnson/safari-is-the-new-ie-but-this-time-they-got-it-right-ef2c66a04ecf?source=rss-6812e3ca2e51------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef2c66a04ecf</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[chrome]]></category>
            <category><![CDATA[safari]]></category>
            <dc:creator><![CDATA[Matthew Johnson]]></dc:creator>
            <pubDate>Mon, 19 Feb 2018 20:03:53 GMT</pubDate>
            <atom:updated>2018-02-19T20:03:53.013Z</atom:updated>
            <content:encoded><![CDATA[<p>Full disclosure, I <em>hate</em> Safari. I can’t count the times I’ve gotten my code working as expected, only to find it failing in Safari. I no longer dread opening my work in Edge, it’s Safari that has me holding my breath. So, when my friend opened my latest work in Safari, and it looked jacked?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AARWxElCL9N2y_FqHhdCNw.png" /></figure><p>Time to investigate! First of all, the backstory. When appropriate, I like to add some surprise and delight to my work in the form of Easter Eggs. For my latest project, I hid my beautiful face behind some hidden inputs. Desktop, type a certain string. Mobile, tap an ungodly amount of times. Satisfy either condition, and voilà!<em> </em>There’s me!</p><p>My original code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49e0329e8705282acac0d97610588775/href">https://medium.com/media/49e0329e8705282acac0d97610588775/href</a></iframe><p>There’s a bit going on in that snippet. To summarize, if someone taps 30 times, the egg gets added to the body. Likewise if they type mathieu.</p><p>In Chrome, this worked like a charm. I was ready to ship! When I went to demo to my friend, who viewed it in Safari, it looked broken. The image was left aligned, and the text wasn’t wrapped below. I was FURIOUS! Once again, Safari had bitten me. I started to dig.</p><p>In Chrome, when I inspected the .egg , I saw the inline styles I expected to see. In Safari? Nada. Stupid Safari.</p><p>What <em>should</em> be happening? I went to the <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style">docs</a>. Apparently, you shouldn’t be messing directly with the style attribute:</p><blockquote>Styles should not be set by assigning a string directly to the style property (as in elt.style = &quot;color: blue;&quot;), since it is considered read-only, as the style attribute returns a <a href="https://developer.mozilla.org/en-US/docs/DOM/CSSStyleDeclaration">CSSStyleDeclaration</a> object which is also read-only.</blockquote><p>Woah. This one <em>isn’t</em> on Safari, it’s on me. My code works fine in Chrome, but <em>should</em> it? It’s neat that Chrome can read my mind. I wrote some bad code, and Chrome knew what I <em>actually</em> meant, and rendered it “correctly”. The problem is, when a browser (Safari) <em>didn’t</em> read my mind, the code is broken.</p><p>To me, this isn’t a Safari problem. It did exactly what it was supposed to do. I actually fault Chrome. While it’s cool that it interpreted what I was trying to do, it shouldn’t “fix” my code for me behind the scenes. That leaves it broken elsewhere, and me none the wiser. Had Chrome left it broken, I would have known right away that something was up.</p><p>So, what’s the fix? The simplest fix is to use cssText, so that the offending line looks something like:</p><pre>egg.style.cssText = &#39;display:flex;justify-content:center;align-items:center;flex-direction:column;width:100%;margin-bottom:2em&#39;</pre><p>While that works well in my situation, it actually isn’t the safest fix. If you’re setting the cssText directly, it will override anything that’s already there. It actually says so right in the docs:</p><blockquote>For adding specific styles to an element without altering other style values, it is preferred to use the individual properties of style (as in elt.style.color = &#39;...&#39;) as using elt.style.cssText = &#39;...&#39;or elt.setAttribute(&#39;style&#39;, &#39;...&#39;) sets the complete inline style for the element by overriding the existing inline styles.</blockquote><p>It also gives a callout to how the property names are different in JS. For example, it isn’t font-size, it’s fontSize. With all of the gotchas accounted for, the actual code should really look something more like:</p><pre>egg.className = &#39;egg&#39;<br>egg.style.display = &#39;flex&#39;<br>egg.style.justifyContent = &#39;center&#39;<br>egg.style.alignItems = &#39;center&#39;<br>egg.style.flexDirection = &#39;column&#39;<br>egg.style.width = &#39;100%&#39;<br>egg.style.marginBottom = &#39;2em&#39;</pre><p>To see the bug, view this in Chrome <em>and</em> Safari:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fmathieujonson%2Fembed%2Fpreview%2FJppVRv%3Fheight%3D600%26slug-hash%3DJppVRv%26default-tabs%3Djs%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io%26embed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fmathieujonson%2Fpen%2FJppVRv&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fm.cdpn.io%2Fscreenshot-coming-soon-small.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/08f8f7e86d8e386411f771023e76edaf/href">https://medium.com/media/08f8f7e86d8e386411f771023e76edaf/href</a></iframe><p>For a working demo:</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fcodepen.io%2Fmathieujonson%2Fpen%2FoEEOzP&amp;src=https%3A%2F%2Fcodepen.io%2Fmathieujonson%2Fembed%2Fpreview%2FoEEOzP%3Fheight%3D600%26slug-hash%3DoEEOzP%26default-tabs%3Djs%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io%26embed-version%3D2&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ecce5c65981e172860881dac0fa6ab0/href">https://medium.com/media/6ecce5c65981e172860881dac0fa6ab0/href</a></iframe><p>I’d take Chrome over Safari any day, but in this <strong><em>one</em></strong> instance, I prefer Safari’s behavior. So, as much as it pains me to say it, kudos to Safari. It didn’t read my mind, but it let me know something was wrong. Shame on Chrome though. It allowed me to be absolutely wrong but still see things “correctly”, keeping me ignorant of my mistakes. And shame on me, for not testing my code in all the major browsers…oops!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef2c66a04ecf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Localization in JavaScript…Quelle?]]></title>
            <link>https://medium.com/@matthew.johnson/localization-in-javascript-quelle-6580abb92a0c?source=rss-6812e3ca2e51------2</link>
            <guid isPermaLink="false">https://medium.com/p/6580abb92a0c</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[localization]]></category>
            <dc:creator><![CDATA[Matthew Johnson]]></dc:creator>
            <pubDate>Wed, 20 Dec 2017 21:24:41 GMT</pubDate>
            <atom:updated>2017-12-20T21:24:41.689Z</atom:updated>
            <content:encoded><![CDATA[<p>We recently rebranded one of our bilingual e-commerce sites. The default language was English, but we had a language toggle so users could switch to French. Clicking the toggle would either add or remove a GET parameter of lang=fr-CA, letting the server know which language to offer up. Most of the content on the site was rendered server-side, so there wasn’t a <em>huge</em> need for a robust solution for handling translations in JavaScript. For the few instances where we were throwing things up via JS, we usually did something simple:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56cbc58724ac6cc6517c366a058fb97a/href">https://medium.com/media/56cbc58724ac6cc6517c366a058fb97a/href</a></iframe><p>It wasn’t the most ideal solution, to say the least, but it worked. Besides, deadlines…am I right? We’re currently in the process of porting an existing site to a Canadian domain, though, and this one has a <em>ton</em> of content that’s generated via JS. Populating the various states of a single modal had tons of hard coded English. Yikes. For a preview of what I was getting into, here’s a sample:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0a7cb372b6f21337577d79ccfcb4759/href">https://medium.com/media/a0a7cb372b6f21337577d79ccfcb4759/href</a></iframe><p>Clearly, throwing in a ton of ternary operators into that mess wasn’t going to cut it. We needed a way to keep the translations maintainable, and keep the templates object somewhat clean. What we wanted was a function that we could pass a key to, and get the correct text back. But what to name it? I came up with a ton of super clever, awesome names. Unfortunately, I went to sleep before writing any of them down. What I ended up with was a decent getVerbiage(). It’s not sexy, but seeing how the definition of “verbiage” is “the way in which something is expressed; wording or diction”, it seemed somewhat fitting. It ended up looking something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/25c92323a496dd148e231d66054c7977/href">https://medium.com/media/25c92323a496dd148e231d66054c7977/href</a></iframe><p>Plugging that function call into the templates gets us nice, pretty translations for all that hard coded english. Updating the templates object left us looking something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9fe63724ee75165c453add8a4ddca8c6/href">https://medium.com/media/9fe63724ee75165c453add8a4ddca8c6/href</a></iframe><p>BOOM! Done. Story is <em>over. </em>You wanted localization in JavaScript, and that’s the best I could give you. Pack it up, and go home. Catch y’all on the flip side.</p><p>Except, <em>jeez</em> that’s an ugly function to return some markup, and error prone to boot. Forget a \ at the end, error. Forget a + somewhere, error. Forget an &#39;, error. You get the idea. Lots of little ways that could break. Using ES6, and <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals">template literals</a>, we can clean that up a bit. <em>That</em> would look something like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b4ade615638935a94bb624f5f2eeca9/href">https://medium.com/media/6b4ade615638935a94bb624f5f2eeca9/href</a></iframe><p><em>Much</em> cleaner, and <em>much</em> less prone to error. We’re no longer trying to concat a bunch of strings, we’re not trying to escape new lines, it’s just…more simple.</p><p>At any rate, that’s how we’re handling translations on the client where I work. We have something similar in one of our React apps, but the concept is the same. Got alternate ways of handling it? Or ways to improve what we’ve got? Drop me a line, and Happy Coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6580abb92a0c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Error checking…it’s kinda important]]></title>
            <link>https://medium.com/@matthew.johnson/error-checking-its-kinda-important-8eef08983600?source=rss-6812e3ca2e51------2</link>
            <guid isPermaLink="false">https://medium.com/p/8eef08983600</guid>
            <category><![CDATA[error-handling]]></category>
            <category><![CDATA[js]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Matthew Johnson]]></dc:creator>
            <pubDate>Wed, 23 Aug 2017 15:30:22 GMT</pubDate>
            <atom:updated>2017-08-23T15:30:22.217Z</atom:updated>
            <content:encoded><![CDATA[<p>We recently had a dev meeting at my company, and we discussed the quality of our code. It seems as though with our rush to always push code out the door, our quality was slipping. We talked about taking ownership of our code (always important), more rigorous code reviews, and more thorough testing. I came out of it feeling fine, after all, <em>my</em> code is flawless. I continued to feel fine until about 5:30, when I found that the pagination on our mobile site was broken. Since I was on the team that put out the latest mobile version, I was less than thrilled.</p><p>Lo and behold, the error was from the back end team. <strong><em>I’M STILL FLAWLESS!</em></strong> All we had to do is roll back the back end changes, and we’d be back in business! That is, until I realized that a roll back might break <em>my</em> changes. Time to investigate!</p><p>Part of the deploy’s changes were to add color “swatches” under the products we sell. The server sent data to the React front end, which was then parsed and displayed. The relevant code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7fad697f3fe649f05ae17e75e709ab71/href">https://medium.com/media/7fad697f3fe649f05ae17e75e709ab71/href</a></iframe><p>Beautiful, right? We’re taking the <strong>siblings</strong> passed down from the server, and using <strong>map()</strong> to loop through. If we already have four, we’re doing nothing, and for the first four we’re returning the JSX with the appropriate classes tacked on. Simple right? Tested. Passed. Even QA thought it was snazzy. But what happens when the back end rolls back their changes, and <strong>siblings</strong> no longer exists?</p><p>Looking back, I realize my fatal mistake. I sometimes overlook the importance of error checking. <em>My</em> code may work in a perfect world, but the world isn’t always perfect. A partial roll back isn’t an option now, because doing <strong>map()</strong> on an undefined variable throws an error and crashes the app. Unfortunate.</p><p>A better approach would be to throw some sanity checks in there, so that a mistake elsewhere doesn’t bring the whole house down:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f44ab148117dd6b4d84947a0ca47287/href">https://medium.com/media/1f44ab148117dd6b4d84947a0ca47287/href</a></iframe><p>That one if statement at the top? That right there would save the app from crashing. We could even take it a step further and check to make sure it was an array. If I had taken the time to <em>check</em> the data coming in we could have rolled back the server changes and been on our merry way. As it is? Well, to be honest it wasn’t all that bad. They pushed out a hot fix to correct the pagination, so no roll back was needed anyway. But still, it showed me a fragile spot in the code. One that could easily be avoided if I had taken the time to add some simple error checking. So for today’s lesson I learned: don’t just write code that isn’t broken, <em>write code that can’t be broken</em>. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8eef08983600" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>