<?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 Grant Glidewell on Medium]]></title>
        <description><![CDATA[Stories by Grant Glidewell on Medium]]></description>
        <link>https://medium.com/@grant.glidewell?source=rss-d290ccb13d56------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*BoFK5gDNjHN8K2t7ZHQTbA.jpeg</url>
            <title>Stories by Grant Glidewell on Medium</title>
            <link>https://medium.com/@grant.glidewell?source=rss-d290ccb13d56------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 10:27:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@grant.glidewell/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[Blazing Speed Without the Pain Points: Try the New BigCommerce, Gatsby, and Netlify CMS Starter]]></title>
            <link>https://medium.com/bigcommerce-developer-blog/blazing-speed-without-the-pain-points-try-the-new-bigcommerce-gatsby-and-netlify-cms-starter-d8a343608637?source=rss-d290ccb13d56------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8a343608637</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[product]]></category>
            <category><![CDATA[ecommerce]]></category>
            <category><![CDATA[gatsbyjs]]></category>
            <category><![CDATA[bigcommerce]]></category>
            <dc:creator><![CDATA[Grant Glidewell]]></dc:creator>
            <pubDate>Wed, 20 Nov 2019 17:51:19 GMT</pubDate>
            <atom:updated>2019-11-20T17:51:19.460Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CSebqcjy5T-86Y75L-p1bw.png" /></figure><p>At <a href="https://www.thirdandgrove.com/">Third and Grove</a>, we can’t help but blend the best technologies in an effort to create modern web front ends. Luckily for us, BigCommerce also likes to push the envelope. So far we have partnered with BigCommerce on projects like <a href="https://github.com/acquia/acf">Drupal’s ACF reference architecture</a> and the <a href="https://www.gatsbyjs.org/packages/gatsby-source-bigcommerce/">Gatsby source plugin</a> which supports the game-changing Gatsby preview.</p><p>Our latest challenge arose from conversations leading up to <a href="https://jamstackconf.com/sf/">JAMStack Conference SF</a>. We kicked ideas around what it would take to eliminate pain points when building an ecomm site. Especially pain points keeping people from using JAMStack. Server rendering makes for a very fast site and we know that’s important because, <a href="https://www.shopify.com/enterprise/site-performance-page-speed-ecommerce">for every second delay in load time, you’re losing 7% in conversions</a> But getting that performance can often be an uphill battle when trying to build a brand-driven experience.</p><p>I’m proud to announce that here’s the answer we landed on: The <a href="https://github.com/bigcommerce/gatsby-bigcommerce-netlify-cms-starter">Gatsby + BigCommerce + Netlify CMS Starter</a> which I’ve been working on for the last few months is ready for production!</p><p>Right out of the box, we have a really great user experience and blazing-fast performance that only a Gatsby site can deliver! You’ll find data is fresh and accurate, and a persistent cart with access to the data in any component throughout the app. Let’s dive into how this starter solves major headaches by being built on solid best practices.</p><h3>Prices you can trust</h3><p>As a customer, the worst experience is to see prices, availability, and other product data change in front of my eyes. Nothing makes me lose faith faster in a store than to see a product with one price listed on the product details page, and then another price appears when I add it to my cart.</p><p>There is a somewhat well-known term in front end development called ‘flash of unstyled content’ (FOUC). This happens when a static page loads its styles/fonts/scripts impacting the overall style of the page after the first render. The result of this is that the user sees unstyled text in a flash, and then it all changes when those other things load. This is generally seen as undesirable, and there are things developers do to avoid this behavior.</p><p>In ecommerce, there are potentially more damaging flashes of content. I call it ‘flash of inaccurate values’ (FOIV). This is the experience I described before. It can take on many forms but in SSR applications there are specific steps to take to avoid this. One approach that worked well in the BigCommerce Starter is to not render any prices at build time. All of that data is fetched on the client. This could be heavy though. Depending on how its implemented, this could fire off a bunch of requests for each item as the user navigates around a store.</p><p>Using a global state implementation became critical. Each product’s price is rendered by a React component called <a href="https://github.com/bigcommerce/gatsby-bigcommerce-netlify-cms-starter/blob/master/src/components/bigcommerce/ProductPrices.js">Product Prices</a> that looks the price up in the global store. The global store is implemented with React’s Context API, but it could easily happen in Redux or any other global state solution. Our <a href="https://github.com/bigcommerce/gatsby-bigcommerce-netlify-cms-starter/blob/master/src/context/PriceProvider.js">Price Provider component</a> makes one call through the BigCommerce cloud function to get pricing and availability for the whole store. This avoids some possible issues with deciding which prices to fetch based on what the user is viewing.</p><p>By not statically rendering price and other data, this allows for some other concerns to be handled by the client. Localizing and personalizing the product data that is skipped in the static rendering process opens up a world of possibilities. BigCommerce is going to support exactly this process via the V3 Pricing and GraphQL Storefront APIs. So your store will be capable of meeting a lot broader range of customer’s needs without changing anything on the front end or having to build multiple versions of the site.</p><h3>A secure cart by default</h3><p>Another concern we needed to address was cart behavior. BigCommerce’s cart API handles a lot right out of the box. But we needed a secure way to connect to this API. Netlify makes it simple to create <a href="https://www.netlify.com/products/functions/">lambdas</a> that hide API keys. That’s exactly what the <a href="https://github.com/bigcommerce/gatsby-bigcommerce-netlify-cms-starter/blob/master/src/lambda/bigcommerce.js">BigCommerce Netlify Lambda</a> accomplishes.</p><p>With the details of security abstracted away, we were able to adapt the BigCommerce cart component logic into a <a href="https://github.com/bigcommerce/gatsby-bigcommerce-netlify-cms-starter/blob/master/src/context/CartProvider.js">Cart Context Provider</a>. This way all of the cart data stays in sync across the application. The cart addresses session persistence as well through the Cart API’s cookies. These <a href="https://developer.bigcommerce.com/api-docs/cart-and-checkout/working-sf-apis#storefront-cart">can be omitted</a> if you want to use another method of cart persistence.</p><h3>How to get started</h3><p>Check out the <a href="https://github.com/bigcommerce/gatsby-bigcommerce-netlify-cms-starter">repository</a> and it would probably be useful to learn more about <a href="https://www.gatsbyjs.org/docs/quick-start/">Gatsby</a>. You should be able to get up and going in no time! You can even <a href="https://app.netlify.com/start/deploy?repository=https://github.com/bigcommerce/gatsby-bigcommerce-netlify-cms-starter">one-click deploy</a> a clone to Netlify! I hope you enjoy and if you have any questions or issues, keep us in the loop!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8a343608637" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bigcommerce-developer-blog/blazing-speed-without-the-pain-points-try-the-new-bigcommerce-gatsby-and-netlify-cms-starter-d8a343608637">Blazing Speed Without the Pain Points: Try the New BigCommerce, Gatsby, and Netlify CMS Starter</a> was originally published in <a href="https://medium.com/bigcommerce-developer-blog">BigCommerce Developer Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I wrote a web scraper in four different languages.]]></title>
            <link>https://javascript.plainenglish.io/4-languages-1-app-cf7d209d700d?source=rss-d290ccb13d56------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf7d209d700d</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Grant Glidewell]]></dc:creator>
            <pubDate>Wed, 05 Dec 2018 04:11:48 GMT</pubDate>
            <atom:updated>2018-12-06T18:55:15.417Z</atom:updated>
            <content:encoded><![CDATA[<h4>A rebuke of “hello world”, in Node, Go, Python, and Rust.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kYdNaQgGYowXLEKw" /><figcaption>Photo by <a href="https://unsplash.com/@jonnysplsh?utm_source=medium&amp;utm_medium=referral">Jonny Caspari</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*hR7qvk_PRLLoHW5bkAYPNg.png" /><figcaption>hello world in Rust</figcaption></figure><p>We’ve all written this at one point or another, and honestly this patronizing exercise needs to stop. I get it, you learn how to set up a project, whatever tooling is necessary, and maybe some basic syntax. However it’s far from an ‘introduction’.</p><p>With a front end framework one might make a ‘todo’ app. This gives a rounded view of state, user input, crud interactions, and layout. But what if I don’t care about front end interactions?</p><p>Some questions I have asked myself in each of these scenarios: How do I import methods I may need to use? How do I interact with the filesystem? How can I get a resource remotely (http request)? Once I have that resource how can I interact with it? A project that covers all of these concepts would be a simple web scraper.</p><blockquote>caveat — web scraping is a point of contention, some say it’s unethical, bordering on illegal. While I don’t agree with that opinion I would advocate that you exercise caution if you plan on making and using a tool to collect data from web sources. Done incorrectly this can be destructive, be careful.</blockquote><p>I have some experience with web scraping. I find it enjoyable to tinker with in my spare time, and I have worked professionally on projects that involve some fairly comprehensive setups. For this experiment, I want to use standard package methods. This way we get the benefit of gaining some familiarity with the language, rather than learning the API of a particular package.</p><blockquote>Requirements —</blockquote><blockquote>make an http request for a page</blockquote><blockquote>store that page locally on the filesystem (making sure that we do not overwrite a previous scrape)</blockquote><blockquote>read that file from the disk</blockquote><blockquote>use native methods to find a search term</blockquote><p>Attaining these four goals involves a much deeper understanding of each language than printing some<a href="https://www.youtube.com/watch?v=pLf3Gb5TcXs"> Tiger Woods quote</a> (😝, <a href="https://en.wikipedia.org/wiki/%22Hello,_World!%22_program">I‘m aware it’s from C</a>). We will learn how each language handles asynchronous behavior, how it reads and writes files, and deals with primitives. Not to mention we will also be printing something meaningful to the console.</p><h4>-<a href="https://nodejs.org/"> NodeJS </a>-</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zC-4fc1SRFRkwp-D" /><figcaption>Photo by <a href="https://unsplash.com/@mariogogh?utm_source=medium&amp;utm_medium=referral">Mario Gogh</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I work daily in JavaScript, this will set the bar for what I want to replicate in other languages. Keeping as much as possible native and simple. I came up with this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/28aa6b1ed335b1ed975e3604833f21f5/href">https://medium.com/media/28aa6b1ed335b1ed975e3604833f21f5/href</a></iframe><p>We have imported three native methods, get which will fetch our page, and then readFileSync and writeFileSync functions that are blocking (they behave synchronously). When we call checkPageForText it takes a URL and a term. It first makes an http request for the resource (url), when the data stream comes in chunks it builds a data string out of those chunks.</p><p>Once the stream ends, it takes that string and writes it synchronously to the disk. Here is where a timestamp is important so that we aren’t constantly overwriting scraped data. It’s possible this way to reference historical data if the page contains a search term we can do further parsing of that file. Using a simple if check we read the file which we just wrote, then use the native javascript includes String method to find our term.</p><p>JavaScript is asynchronous, and we use callbacks in this case to handle a response returning from a request and access data when it is completely transferred. Callbacks can get messy if over-used and can create a ‘pyramid of doom’.</p><p>Another solution would involve promises, and could even involve async and await keywords. For this application using callbacks works fine and is fairly easy to follow. Some describe JavaScript as ‘expressive’, in this case there are a number of approaches that would achieve the same outcome.</p><p>Overall we have a basic scrape of a page and can find a search string and report that back to the user. This could be much more robust, however making a comparison between languages becomes harder, and less meaningful the more complex the application.</p><h4>-<a href="https://golang.org/"> Go-lang </a>-</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aotYU_QyueM0dCYL" /><figcaption>Photo by <a href="https://unsplash.com/@sirbusorin?utm_source=medium&amp;utm_medium=referral">Sorin Sîrbu</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Here we follow the same steps as in the Node implementation. scrape takes u for a URL, and t for term or search term. The convention for single character variables in Go is exactly contrary to how I learned to write readable code. It is, however, their conventions so I must abide.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8bb7105a7f1e8887f84f50d7f1ffb77e/href">https://medium.com/media/8bb7105a7f1e8887f84f50d7f1ffb77e/href</a></iframe><p>Error checking is a known pain point in working with Go. You can see the successive error checking with each possible fail point. On one hand this is repetitive, however it does make it easier to debug.</p><p>A huge difference in moving from a dynamic language like JavaScript to Go is that we have to define our types and when appropriate cast our byte slice into a string (line 49). This has clear advantages in type safety, also in thinking through exactly what your function needs in order to return the correct type.</p><p>After some collaboration with someone more familiar with Go, I was able to streamline some ugly string concatenation (using Sprintf instead of +) and better understand the naming conventions in Go. When passing variables to a function use one or two letters, otherwise something like filename or body is fine. Go stands out in this list as an accessible strongly typed language.</p><h4>-<a href="https://www.python.org/"> Python </a>-</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Q4baI1k4h2abxwCl" /><figcaption>Photo by <a href="https://unsplash.com/@hiteshchoudhary?utm_source=medium&amp;utm_medium=referral">Hitesh Choudhary</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Straightforward is how I would describe writing Python. It is no wonder this is a first language choice for many new programmers. Python’s user base is massive, and support is ubiquitous.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0461f4c94f15abc0cbd36f23e282d2c9/href">https://medium.com/media/0461f4c94f15abc0cbd36f23e282d2c9/href</a></iframe><p>Here we make the same scrape program with the same url and term parameters. The code is so simple and easy to follow along I almost don’t think it requires explanation.</p><p>One issue I will point out here is that Python, rather than having clear syntax using curly braces to visually show a block, relies on whitespace. I don’t prefer this, though I do see the elegance.</p><p>I understand that this quality of Python is what makes it accessible and why so many people use it. I love the ability here to simply write if term in s.read() without having to invoke a method to search a string. Python strikes me as utilitarian, and to that point an extremely powerful general purpose language.</p><h4>-<a href="https://www.rust-lang.org/"> Rust </a>-</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aUZ_VdI1jQsecFMp" /><figcaption>Photo by <a href="https://unsplash.com/@ross_sokolovski?utm_source=medium&amp;utm_medium=referral">Ross Sokolovski</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Right off the bat Rust is a totally different animal to the previous languages in this article. One amazing thing about Rust is that it’s compiler errors are actually human readable and very helpful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*keCEi6T3f1UInGEiv3RdrA.png" /></figure><p>I think they’ve really gone above and beyond here trying to take the pain out of something that could easily have become less important while developing the tooling for Rust. After coding for significantly more time than the other languages in this article, this is the Rust scraper:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ce65b832a086819d2301e8cf3fe5eba/href">https://medium.com/media/1ce65b832a086819d2301e8cf3fe5eba/href</a></iframe><p>I had a hard time finding a straightforward way to make an http request with the standard library and wound up using an external crate (package/library) called reqwest.</p><p>A concept that was required to write this program in Rust was that of <a href="https://doc.rust-lang.org/book/second-edition/ch04-02-references-and-borrowing.html">‘borrowing’</a>. Borrowed variables are their own type in Rust, they’re a reference back to the place in memory where the variable is stored (sounds like a pointer to me, I don’t understand this enough to differentiate). Memory management is something many programmers using higher level languages don’t deal with as explicitly.</p><p>I mentioned earlier that one pain point in Go was error checking. Rust does not have this problem, in fact the programmer in Rust is given options in how and when to handle errors depending on how information is being accessed or generated. You can see this in the difference between get_timestamp and read_file.</p><p>When reading a file we have used the .expect() syntax to handle an exception, while the timestamp generation uses a <a href="https://doc.rust-lang.org/book/2018-edition/ch09-02-recoverable-errors-with-result.html">Result enum</a> to handle the error. I like options, and surprisingly despite my struggles with it I really like Rust. I wouldn’t be comfortable reaching for it to quickly prototype an idea, but my interest has grown.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MwV6SJNL8fJOmeoQ" /><figcaption>Photo by <a href="https://unsplash.com/@kobuagency?utm_source=medium&amp;utm_medium=referral">Kobu Agency</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Each of these languages has a different purpose, they solve different problems. A couple of these languages (Python and JavaScript) seem to have solutions for every problem. But as such they lack efficiencies and safety that Go and Rust excel in.</p><p>Some with more experience in these languages are sure to find better/different ways to achieve the simple scraper and I am looking forward to seeing how some might implement it. Or if you have a different program that you like to write when getting acquainted with a new language, please share it.</p><p>As far as “hello world” is concerned, a simple scraper is much more involved. I want to demonstrate that an introduction to a programming language can be so much more in depth and show off its features, syntax, strengths, and weaknesses. By no means is this a solution to a real problem, just something I wanted to explore. I hope you find this useful and decide to contribute your own scraper or something better.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf7d209d700d" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/4-languages-1-app-cf7d209d700d">I wrote a web scraper in four different languages.</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making Decisions in our React/Redux app]]></title>
            <link>https://javascript.plainenglish.io/making-decisions-in-our-react-redux-app-a1ad7d01a62c?source=rss-d290ccb13d56------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1ad7d01a62c</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Grant Glidewell]]></dc:creator>
            <pubDate>Mon, 01 Oct 2018 21:04:23 GMT</pubDate>
            <atom:updated>2018-10-06T22:17:25.098Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9_i-37S-JpOm9BNq" /><figcaption>Photo by <a href="https://unsplash.com/@_everaldo?utm_source=medium&amp;utm_medium=referral">Everaldo Coelho</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This will serve as both an announcement and an explanation. An announcement that our <a href="https://github.com/zesty-io/accounts-ui">Accounts-UI react/redux app</a> will be open to the public.</p><p>We are looking forward to having this work open for developers to view, learn from, and even inform us on places where we could make improvements. In the process of this build we have made decisions, many in fact that deserve a walk through.</p><p>There are about 25000 lines of code in this app, so we can only cover <em>some</em> ideas in this article. Our largest decisions center around using React, managing our <a href="https://github.com/reduxjs/react-redux">Redux</a> state, and I’ll introduce our <a href="https://github.com/zesty-io/design-system">component library/design system</a>.</p><p>Before we get into details it would probably be useful for you to have a bit of background on <a href="https://www.zesty.io/">Zesty.io</a> and what this app is responsible for. Zesty.io is a SaaS model WCMS (Web Content Management System).</p><p>We are focused on small to medium enterprise customers who need to get their content to every corner of the internet through websites, native apps, IoT devices, and more. The app we are discussing is not a content management portal, but an account app.</p><p>Our users use it as a gateway to spin up instances, manage collaborators as well as details related to the instance. You could think of it as the gateway to managing your content across many instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FlylgvkY2C7iTpAL" /><figcaption>Photo by <a href="https://unsplash.com/@maxwbender?utm_source=medium&amp;utm_medium=referral">Max Bender</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Developers often articulate in snorts and grunts that Redux and it’s boilerplate is overkill for most cases, that isn’t wrong. It does take a bit of doing to get it set up. However those are just trees, and I’m here to show the forest. Our problem is one of data, persistence, and organization. Anyone who has passed props to a react component knows that if you need data more than a couple layers deep it can become, I’ll say-</p><blockquote>‘mind numbingly repetitive to continually pass this information along the chain of components to the data’s final destination’. — Grant Glidewell</blockquote><p>Now this could be solved a few ways. For data that is not small and is needed in multiple places across the app or comes from multiple different resources from our API, it can be a bit tricky.</p><p>In the case of a new user on Zesty, they create an account, confirm their email address, and log in. Once a user creates an instance, and picks a blueprint (these are templates with corresponding data structures for content ready to use) the instance overview opens and allows the user to edit multiple aspects of the instance. Our Redux store looks like this-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*tVbF6WtI9SS-YJukVL5VLw.png" /></figure><p>As you can see this is quite a bit of data. We have a user, blueprints, teams that this user may belong to, instances this user has access to, related data for each of those and more ancillary items to make rendering decisions. The stores data are keyed to a unique ID. When the request comes back from the database sometimes our reducer is simple.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YOKKjtMsdVVtbVrjtPf1FQ.png" /></figure><p>Other times, like in the case of removing data from a store it gets a bit less straightforward but still manageable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OTzVJ0BsoP930MsYJtTkJQ.png" /></figure><p>In mapStateToProps we can make sure we are passing along only the relevant information to each component. This closely follows the suggestions of the redux documentation, as we have normalized our data across each store so referencing can be done easily.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n3W_wn0aH9mWIveMAMQmGQ.png" /></figure><p>Across our entire app we use this key reference method. It is sometimes cumbersome to map through, however if I need to check a user’s role in relation to an instance anywhere in the app I know exactly where that information lives.</p><p>This pattern also further abstracts our views from the data layer. Speaking of views, let’s get into how our components are structured.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qRGGC-MKW43I5aFw" /><figcaption>“A local interchange with purple lights and city buildings in the background” by <a href="https://unsplash.com/@dnevozhai?utm_source=medium&amp;utm_medium=referral">Denys Nevozhai</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Our app is wrapped in validation. Our public routes are always available, but the core app isn’t rendered at all until a user has a validated session. Sub-apps are segmented into the individual use case of each app, in this case they break down into tabs in the main app. Our teams sub app has a few aspects that may be of interest and illustrates our approach clearly.</p><p>Only a single view is necessary in this sub app. The main view is responsible for making the initial data fetch for the teams this user belongs to or has invites for. These are called in componentDidMount using promise.all, since our main TeamsGrid element is wrapped in ourWithLoader component we can condition it’s render on those calls coming back from the API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*agwfFGSHBtxaAx45qtiTNw.png" /></figure><p>Handling the data up front allows us to make some cleaner components that are unencumbered by the initial API calls and data structure changes that may have to happen.</p><p>Our TeamsGrid component renders out three other components- CreateTeam which is responsible for team creation, InviteCard which renders teams a user does not have access to yet but is invited to, and TeamCard showing what other users are on a team and what instances the team is assigned to.</p><p>Each of these components deals only with a thin slice of the state, and only use actions pertaining to that slice. The segmentation helps keep the development process simple, these concerns have been decoupled and therefore are autonomous pieces.</p><p>For a moment let’s look at how this might work in a tightly coupled scenario. I am a user, I have a team that I am working with. I go to see who has accepted their team invitations and see that ‘George’ has joined my Developer team for a project I am very excited about.</p><p>At this point the App has fetched my team members for this team, and also the instances we are assigned to work on. I click through to one of the instances my team is assigned to sending me over to the Instances sub-app. I am brought to the instance overview for that instance which also has to make API calls.</p><p>This component does not know that I’ve just come through from the Teams sub-app and that I already have the team data, and so it waits for that information to come back from the API to render.</p><p>This is a waste of network resources as we have now made duplicate calls in rapid succession. We have also wasted precious milliseconds waiting on information that could easily be referenced from another place in the global state. Not only is there the practical advantage here of having a global state to call upon, but this is an asset for a mental model as well.</p><p>In working on this app we were able to build out components, with concern for how they will work with each other, not having to concern ourselves with the data flow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sNGK8b2ai33O7Imw" /><figcaption>“Wooden pier pathway with white wooden railing” by <a href="https://unsplash.com/@pixelatelier?utm_source=medium&amp;utm_medium=referral">Christian Holzinger</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>All of this component talk has me itching to discuss a fun by-product of this process. In the spirit of ‘re-usability’ and explicit, declarative, functional, more buzzwordy development; we have started to build out our <a href="https://github.com/zesty-io/design-system">design system</a>.</p><p>Our needs are fairly simple. We need styled wrappers over inputs to match our general theme, as well as some more specific elements for our layout. We follow ‘<a href="http://bradfrost.com/blog/post/atomic-web-design/">atomic design</a>’ principals put forth by <a href="http://bradfrost.com/">Brad Frost</a>.</p><p>As our needs and team grows this project will become more integral in our future work. Having a repository full of standardized components to pull from will make adding features quite a bit quicker. It also serves the dual purpose of making updates to our UI possible from a single place.</p><p>The overarching theme with all of this is decoupling. As we have decoupled data from actions, actions from views, views from UI elements. The freedom this allows is significant and feels smooth and seamless in the end result.</p><p>The initial investment in architecture is continuing to pay off. As we progress we plan to make more of our work open to the public.</p><p>We look forward to input from the community and hope that some of our decisions help some developers out there with the hard problems.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1ad7d01a62c" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/making-decisions-in-our-react-redux-app-a1ad7d01a62c">Making Decisions in our React/Redux app</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use Recursion in JavaScript (from Mr Meeseeks)]]></title>
            <link>https://javascript.plainenglish.io/learn-recursion-from-mr-meeseeks-27048164aeb0?source=rss-d290ccb13d56------2</link>
            <guid isPermaLink="false">https://medium.com/p/27048164aeb0</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[recursion]]></category>
            <dc:creator><![CDATA[Grant Glidewell]]></dc:creator>
            <pubDate>Fri, 31 Aug 2018 12:01:01 GMT</pubDate>
            <atom:updated>2019-02-07T16:09:08.987Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*aZB4dwe_JRcp1uMHiGYf8g.jpeg" /></figure><p>Recursion is a concept that can be hard to grasp at first. So I’ve asked Mr Meeseeks to help me out. If you’re aware of this lovely character from the cartoon Rick and Morty, you may know where I’m going. If not, Mr Meeseeks is a magical character that is able to grant wishes. If you can, take a look at the episode. If not here’s a synopsis from wikipedia:</p><blockquote>When the rest of the Smith family asks Rick for solutions to several mundane problems, he gives the family a Meeseeks Box, a gadget capable of causing helpful beings named “Mr. Meeseeks” to materialize each time its button is pushed. These identical and short-lived creatures exist only to execute the first order they are given; once it is completed, they vanish. Rick warns the family to keep their tasks simple. — <a href="https://en.wikipedia.org/wiki/Meeseeks_and_Destroy">https://en.wikipedia.org/wiki/Meeseeks_and_Destroy</a></blockquote><p>ill be referencing this repo in the article:</p><p><a href="https://github.com/grantglidewell/mrmeeseeks">grantglidewell/mrmeeseeks</a></p><p>Consider for a moment, that functions are really just in existence for the brief time they are run and, like a Meeseeks, they die after they have served their purpose. If a Meeseeks is able to simply accomplish the request given to him, he is rewarded with a short life. However if the task is too complicated for one Meeseeks to complete, he can call another Meeseeks for backup. This is excellent! however, two Meeseeks isnt always better than one, and this can get out of control very quickly if handled improperly. Remember, Meeseeks arent Gods, just simple problem solvers.</p><p>When a Meeseeks needs another Meeseeks to help him, this is recursion. The function is set up to call itself under certain conditions. In the Rick and Morty episode first featuring this magical creature he calls himself to deal with a complex problem. The problem he faces is taking two strokes off of Jerry’s golf game. This is not a simple task in the slightest. In order to accomplish this an entire recursive colony of Meeseeks are called to help with this task. While only one Meeseeks is sufficient to accomplish other simpler tasks.</p><p>The key here is conditioning, lets leave the analogy for a bit here. When you need recursion to solve a problem in programming, you’re essentially creating a tree structure. This means that you have to handle a base case. The base is the input to the function for which it will not recurse. You can think of these cases as the end of a branch. In the case of my example code, if the desire sent to Mr Meeseeks is less than three words long, he will handle it himself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*ufBA7xFn9qkORjLpoYmAIA.png" /></figure><p>However, if recursion is necessary to continue processing the request, you must change the request (moving it towards the base case) before handing it back to the recursive function. Why? because we dont want to create an infinite loop. Back to Meeseeks.</p><p>In the episode, Jerry is hopeless at golf, and the Meeseeks called upon to help become despondent. Calling new after new after new Meeseeks to give assistance, but without really clearly defining <em>new</em> tasks for them to solve. This is an infinite loop. If you dont change the ‘state’ passed to the recursive function, you will never reach the base case and the program is an infinite loop. In this example, the desire passed into the function is split into two smaller desires and handed to two new Meeseeks.</p><p>This is where the function calls itself, it is actually ‘recursing’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*bu2j1v7qxok1SZ4MR4yMxw.png" /></figure><p>Essentially what happens here is that the function will run again, but with only half of the request. This will happen repeatedly (recursively) until the base case is reached.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*mJh4hWvg2S7_zj5RCWPF7A.png" /></figure><p>What we see here is the Meeseeks taking the desire, splitting it up into small enough segments (less than three words) and then fulfilling those requests.</p><p>You can see the Meeseeks spawn into existence until the chunks are small enough to start fulfilling the requests. then you see them poof out of existence. Don’t worry, they prefer it that way. Meeseeks don’t like existing for too long, it’s a sign that there might be an infinite loop.</p><p>And just like that, Mr Meeseeks has taught us about recursion! If you found this useful, be sure to leave lots of claps <em>(hint: you can leave up to 50 claps!)</em> and share this amongst all of your Rick and Morty-loving JS fans 🤓</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=27048164aeb0" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/learn-recursion-from-mr-meeseeks-27048164aeb0">How to use Recursion in JavaScript (from Mr Meeseeks)</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[It's time for you to learn Webpack]]></title>
            <link>https://javascript.plainenglish.io/its-time-for-you-to-learn-webpack-45d2b08ae754?source=rss-d290ccb13d56------2</link>
            <guid isPermaLink="false">https://medium.com/p/45d2b08ae754</guid>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Grant Glidewell]]></dc:creator>
            <pubDate>Sun, 05 Aug 2018 18:06:25 GMT</pubDate>
            <atom:updated>2018-10-27T03:09:00.754Z</atom:updated>
            <content:encoded><![CDATA[<h3>It’s time for you to learn Webpack.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LifSlFHGUENILm8K" /><figcaption>Photo by <a href="https://unsplash.com/@minkmingle?utm_source=medium&amp;utm_medium=referral">Mink Mingle</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I use <strong>Webpack</strong>.</p><p>I have used it in <strong>create-react-app (CRA) </strong>through <strong>react-scripts</strong>, and in other projects that have custom configs set up before I lay a finger on them. But I don’t really know how it works. I look at the configs, I understand some of the ideas behind it, but I’ve never written a <strong>Webpack</strong> config, or tried to set my own up. That is what this article will be about. Going from no config, to a basic functioning setup that will bundle <strong>HTML</strong>, <strong>CSS</strong>, and <strong>Javascript</strong>.</p><p>My goal is to demystify as much of the process as possible, so that <strong>Webpack</strong> can be more accessible and friendly to newer developers.</p><p>If you’re working in <strong>React</strong> or another library or framework that needs a build process and you want to break your reliance on <strong>CRA</strong> or just get more comfortable with what magic is going on, we’ll dive right in to creating a project. Since I am writing this in parallel with the project I’ll go step by step and explain along the way how I tackle each problem and research mysteries.</p><p>Feel free to follow along or use the <a href="https://github.com/grantglidewell/webpack-in-plain-english">github repo</a> I’ve set up. If you choose to follow along, I have specifically used images of certain files so they can’t just be copy pasted. Typing these things out will help get you comfortable with making mistakes, seeing them, and fixing them.</p><p>First up, get the project laid out-</p><pre>mkdir webpack-in-plain-english<br>cd webpack-in-plain-english<br>npm init -y<br>mkdir src<br>touch src/index.js<br>mkdir src/components<br>touch src/components/App.js<br>npm i react react-dom</pre><p>Now we need a few dev dependencies to make this all work. For me, this is where things can get confusing because a lot of the functionality of these start to blur together. We need <strong>Webpack</strong>, and its friends the <strong>CLI</strong> and<strong> dev server</strong>. To make this work in the browser we need to <strong>transpile</strong> the<strong> es6</strong> and later parts of our code into<strong> es5</strong> standards. <strong>Webpack</strong> does not <strong>transpile</strong>, that’s the job of <strong>babel</strong> and the <strong>loader</strong> and <strong>preset</strong> packages.</p><pre>npm i -D webpack webpack-cli webpack-dev-server html-webpack-plugin</pre><pre>npm i -D babel-core babel-loader@7 babel-preset-env babel-preset-react</pre><p><strong>Webpack</strong> itself as a package we will not touch directly, it does the work but only through the <strong>webpack-cli </strong>package that we’ve installed so that we can interface and configure <strong>Webpack</strong>. The <strong>Webpack</strong> <strong>dev server</strong> package is a nifty tool that will run our build process, and serve it to a browser. As for the <strong>Babel</strong> items, they really deserve their own writeup and I’ll likely write a continuation of this to get more into how these work and the different configurations possible.</p><p>Everything we have just installed needs some configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q8jehU52f2EuqX6HyZ7CVA.png" /><figcaption>webpack.config.js</figcaption></figure><p>Entry is where <strong>Webpack</strong> starts crawling the files. Essentially it loads in <strong>index.js</strong>, looks at what it consists of, and if it sees that <strong>index.js</strong> is importing other files, it deals with those according to the configuration it has.</p><p>Output lets us define where we want our bundled js file to go. In this case we will use the <strong>node.js</strong> ‘<strong>path</strong>’ module to define our path. The second key in the object is simply the filename.</p><p>Module is where we define how to handle each file that <strong>Webpack</strong> encounters. The <strong>‘rules’</strong> array contains objects that define filetypes and how to handle them. For each rule you specify what the extension should look like, any folders or files to exclude, and what to use when preparing these files. In this instance we are telling <strong>Webpack</strong> that it needs to look for <strong>.js</strong> file extensions, exclude any that are in the <strong>node_modules </strong>folder, and use babel-preset as its loader.</p><p>Config is done, for now. We need to add some scripts to our <strong>package.json</strong> so we have actually make use of this config and the power of <strong>Webpack</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zMqK_XGAaZHyJSVDpBVzMA.png" /><figcaption>package.json</figcaption></figure><p>Our start script will run the <strong>Webpack</strong> dev server, which serves a build of our project, but doesn’t write it to disk, it does this in memory. We have also specified that we are in development mode, we want a browser to be opened when we run this command, and that we want <strong>Webpack</strong> to watch our files and <strong>‘hot’ reload</strong> them when there are changes.</p><blockquote>Note: For those unaware, <strong>hot reload </strong>refers to the ability for the code to automatically recompile and reload the page in the browser whenever a change is made.</blockquote><p>The build command will write the project to disk and because we are using the production flag it will be optimized for end user consumption.</p><p>Since we defined our js loader as ‘<strong>babel-loader</strong>’ we need to give it a configuration of it’s own. Using presets makes it this simple to tell babel how to deal with the <strong>Javascript</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*aMFLBNFnGT3Vqap-jUW-4w.png" /><figcaption>.babelrc</figcaption></figure><p>Since this is about webpack, and not actually about building an app, the <strong>index.js</strong> and <strong>App.js</strong> files respectively should look like this:</p><p><strong>index.js</strong></p><pre>import React from &#39;react&#39;</pre><pre>import ReactDOM from &#39;react-dom&#39;</pre><pre>import { App } from &#39;./components/App&#39;</pre><pre>ReactDOM.render(&lt;App /&gt;, document.getElementById(&#39;root&#39;))</pre><p><strong>App.js</strong></p><pre>import React, { Component } from &#39;react&#39;</pre><pre>export class App extends Component {</pre><pre> render() {</pre><pre>  return &lt;p&gt;Hi, I&#39;ve been packed, and transpiled&lt;/p&gt;</pre><pre> }</pre><pre>}</pre><p>it was brought to my attention by <a href="https://medium.com/@m.chernyavska?source=responses---------0-3--------------------">Maryna Cherniavska</a> that I omitted the index.html file. Here it is, thank Maryna.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt; <br> &lt;head&gt;  <br>  &lt;meta charset=&quot;UTF-8&quot;&gt;  <br>  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-  scale=1.0&quot;&gt;  <br>  &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;ie=edge&quot;&gt;     &lt;title&gt;Webpack React&lt;/title&gt;<br>&lt;/head&gt; <br>&lt;body&gt;  <br>  &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;<br>&lt;/body&gt; <br>&lt;/html&gt;</pre><p>Simple enough to see whether or not our scripts and configs are working. At this point if you run <strong>npm start</strong> you should have a browser pop open in short order and show you the results of what <strong>Webpack</strong> has put together with this config. Let’s look at how <strong>Webpack</strong> has dealt with <strong>index.js</strong> (the entry we defined).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bne1if8GW9qh8vRYYXg0wQ.png" /><figcaption>index.js webpack entry</figcaption></figure><p>The first line is importing <strong>React</strong>, that’s in <strong>node_modules</strong> and falls under our exclusion and <strong>Webpack</strong> knows not to do anything with that import, same with the second line. Upon the import of <strong>App</strong>, <strong>Webpack</strong> will go ahead and crawl through that file as well. Adding it’s contents to the bundle, and progressively through the app until all code is accounted for in the bundle.</p><p>What we have now is a working basic <strong>Webpack</strong> configuration. But wait, this doesn’t include styles. Go ahead and make a <strong>styles.css</strong> in the components folder and import your modifications to the ‘<strong>p</strong>’ tag into <strong>App.js</strong> like this:</p><p>import &#39;./styles.css&#39;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8MMUe1OKL-7QAN2ffPM0ZQ.png" /></figure><p>Alright, now it’s broken. Great. All this setup and I can only display un-styled garbage!</p><p>This brings us to the most important part of <strong>Webpack</strong> usage. Researching loaders and finding how to resolve problems. This problem is an easy one to solve because it’s one that a lot of people have dealt with. A simple google search will guide you to an <strong>npm</strong> package called ‘<strong>css-loader</strong>’ or ‘<strong>style-loader</strong>’. You’ll see that you have to install them through <strong>npm</strong> and then modify your <strong>Webpack</strong> config with another test to include css files and tell it how to deal with them. These loaders let us set another rule, this time for css. This is not going to output a css file with your styles, but add them into your Javascript like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YSztiLwiW-xblAd2Bpm4EQ.png" /><figcaption>Inline styles in webpack output</figcaption></figure><p>With a quick npm i style-loader css-loader and then adding a rule to the <strong>Webpack</strong> config that looks like this:</p><pre>{</pre><pre>test: /\.css$/,</pre><pre>use: [&#39;style-loader&#39;, &#39;css-loader&#39;]</pre><pre>}</pre><p>You now have the ability to import styles into your <strong>React</strong> components and make something not only functional, but pretty as well. 😁</p><p>So now we have a couple things working and a foundation of how to configure <strong>Webpack</strong>, some ideas on <strong>Babel</strong> (which is its own beast to tame), and how to add loaders for increased functionality.</p><p>This is the beginning of a beautiful relationship. Build processes can be daunting, but if you have a solid foundation and know how to expand upon that you can get along just fine.</p><p>If you have additional resources or see a problem with this guide feel free to drop me a line in the comments. I’m also on twitter <a href="https://twitter.com/GrantGlidewell">@GrantGlidewell</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45d2b08ae754" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/its-time-for-you-to-learn-webpack-45d2b08ae754">It&#39;s time for you to learn Webpack</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing with Cypress.io]]></title>
            <link>https://medium.com/@grant.glidewell/testing-with-cypress-io-10ca7e4984e0?source=rss-d290ccb13d56------2</link>
            <guid isPermaLink="false">https://medium.com/p/10ca7e4984e0</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[Grant Glidewell]]></dc:creator>
            <pubDate>Mon, 30 Jul 2018 22:13:09 GMT</pubDate>
            <atom:updated>2018-07-30T22:13:09.202Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rk8KmyCo8RbwGAQt" /><figcaption>“Lone green treetop tree on the coastline field at Poipu Beach” by <a href="https://unsplash.com/@toddquackenbush?utm_source=medium&amp;utm_medium=referral">Todd Quackenbush</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a>. Its a tree, probably not a cypress, dont be so picky.</figcaption></figure><p>Testing, how does it work? Well, to be honest, I don’t know much about it. I have used jest a handful of times, I have manually tested UI, and done my best to error-proof (go ahead, laugh at that) response handlers in my front end code. But as for actually making a good habit of testing the overall functionality of my code I have fallen, staggeringly short of my goals. The main hurdle for me was getting down to <strong>what needs to be tested</strong>. There are schools of thought on this, but my opinion would follow along with <a href="https://medium.com/u/86da80adff6a"><em>Guillermo Rauch</em></a><em> </em>when he tweeted<em> - ‘</em>Write tests. Not too many. Mostly integration.’</p><p>In those tests I want to cover as much ground as possible. Cypress.io gives it’s users tools to spin up a browser, and using a j-query-like syntax walk it through flows of behavior a user would actually go through. Considering our app requires auth to access it’s core behaviors, I needed something that would give me the ability to log in, render my UI, interact with it, and then test certain expected outcomes. Cypress.io has excellent <a href="https://docs.cypress.io/">docs</a> and I was able to get up and going in minutes. I’ll only briefly cover that process. Installation through npm is just like any other package, upon running npm run cypress open for the first time you’ll be introduced to your new best friend: The Cypress test runner. It comes with examples of almost everything you could want to accomplish, and tests are listed out in their electron interface. You can select other browsers to run if you have them installed. Lots of room here to really go nuts if you want to. I did not. I just needed a test, so first things first, let’s create a test to ensure the app fails correctly when someone uses bad credentials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oWxTwxSRwbGIelUQlq7M7g.png" /></figure><p>The first thing you may notice is that Cypress allows you to set up environment variables. This is excellent, as well as the ability to create custom commands (logging in with good credentials, navigating to a certain app segment, anything you need automated). Cypress uses mocha under the hood so writing assertions should be familiar to anyone who has used it before, and simple enough for anyone who has not. Line by line this test does the following-</p><p>go to the local instance of app</p><p>get the username input</p><p>input the environment value for an invalid username</p><p>check that the value in that field is correct</p><p>get the password field</p><p>input the environment value for an invalid password</p><p>check that the value in that field is correct</p><p>get the submit button</p><p>click it</p><p>expect the failure to log in message to appear.</p><p>Straight forward enough. Now when the test is run you are able to observe as chrome and cypress walk through the flow you’ve provided. The final outcome looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DoEULqX0JKUFKyr-iDl7SA.png" /></figure><p>Each assertion is highlighted, network requests displayed, each step is selectable and allows the user to interact with the DOM at that point in history. This is only a small example of the power of Cypress.io. Writing tests for our Accounts UI took a matter of hours, and that covers almost everything a user can do in the application. From spinning up an instance all the way through to managing teams of users and giving them access to an instance. Since the tests are so straightforward to write, changing them in response to changes in our user flows are just as simple. Could this have been done with Nightwatch, or Selenium? Probably. But I think the testing should complement the process of development, and not become another development project in and of itself.</p><p>Cypress does a great job of getting out of the way and letting me work. It also has integrations into CircleCI and has docker container available to use your browser of choice for the remote tests. If you’re in need of testing for your front end project, give Cypress a shot. It’s quick to start up, easy to implement, and it’s power is deep.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10ca7e4984e0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React front end for Zesty.io headless CMS & JSON API]]></title>
            <link>https://medium.com/@grant.glidewell/react-front-end-for-zesty-io-headless-cms-json-api-cf0a655e19cd?source=rss-d290ccb13d56------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf0a655e19cd</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[cms]]></category>
            <dc:creator><![CDATA[Grant Glidewell]]></dc:creator>
            <pubDate>Thu, 03 May 2018 17:47:22 GMT</pubDate>
            <atom:updated>2018-05-03T19:23:22.483Z</atom:updated>
            <content:encoded><![CDATA[<h3>Using Zesty.io Headless CMS with React</h3><p>To get things started, Ive created a git repo that I’ll be referencing later in the article. You can fork that <a href="https://github.com/grantglidewell/zesty-react-starter/">here</a>.</p><p>We’ll first need to have an endpoint to consume. With a new account on Zesty.io the first thing it will ask you to do is create a web property. Once you’ve named your property it will ask about a blueprint. Since we are using Zesty as a headless CMS we don’t have to worry about that, select one, or none and the manager app should open up from that point. Now that we have a web property, we need some configuration. If you go to the Config &gt; Site Settings, and then under developer you need to turn on ‘Access to Basic JSON API for content’ and ‘Allow cross domain access to Basic JSON API’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*E3fFPkpumihPdvVoqzRrxA.png" /><figcaption>Your settings should look like this</figcaption></figure><p>Next is our Content Structure, or schema, data shape, ‘fields’, however else you’d like to refer to the information that your React app will be consuming. Over in the content structure section of Config we need to create a data set, and define the fields we want our content creators to fill in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_75Bi4SH1PPuqV75t6-fxQ.png" /></figure><p>For this example I want to keep things pretty simple, so we have a title, article, author and an optional image url(https://medium.com/currently%20the%20image%20data%20type%20if%20for%20internal%20use). Now we can go fill in some dummy data. Over in the Content section select our newly created ‘DataSet’, and throw some words at it. While you’re doing this, go ahead and publish these, Zesty allows content creators to work on drafts and only publish content that is ready to go.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6QljxgbCuC2Jkso2J6RNYQ.png" /><figcaption>now you have content</figcaption></figure><p>Lets get to the good stuff, now that we’re done with the one time setup. If you have the repo above ready to go, and have run npm install<em> </em>then lets get the right information into the .env</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*lq7QlqaFAo4SS-hWSHNHcQ.png" /><figcaption>From the URL bar, you can get your hash and the ID of the collection.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*obySCTouYRErlzff9ykk6w.png" /><figcaption>Shown in the renamed .env file here</figcaption></figure><p>For this example we’ll use the dev-preview domain (Zesty allows for multiple Domain options that we won’t get into here). With those variables in place we’re ready to get going on how to get this data into our React app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*y2JHrIkI0bpznRyzg8tdMQ.png" /><figcaption>Checking for environment variables</figcaption></figure><p>This is checking to make sure that the environment variables needed to make the fetch call are in place and then returns them. React scripts will automatically pick up environment variables pre-pended with ‘REACT_APP’ in the .env file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/1*uAeNsf51bcqWK-cHbK-mgw.png" /><figcaption>fetch call in componentDidMount</figcaption></figure><p>Using the environment variables we set, fetch is what is going to make the API call and allow us to set the data into our state. If you aren’t familiar with the fetch API it’s highly supported in modern browsers i suggest checking out <a href="https://jakearchibald.com/2015/thats-so-fetch/">this</a> article. Its important to note that our initial state key of apiData is set to an empty array, this is consistent with what is returned from the Zesty JSON API for reasons that are obvious in the render function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*0ZDQwGjZCovIoNQbwakrww.png" /><figcaption>map rendering Material-UI cards</figcaption></figure><p>Using the map Array method we can generate a card for each article that is returned from our JSON API. Map is super useful and if you aren’t familiar with it (or its friends filter, and reduce) check <a href="https://hackernoon.com/understanding-map-filter-and-reduce-in-javascript-5df1c7eee464">this</a> out and be enlightened.</p><p>Now that all of our ducks are in a row, throw npm run start in the terminal and see the magic of fetch, react, and Zesty headless CMS in all of it’s glory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*diOh1HWG_N2vhEWhKzeikQ.png" /></figure><p>This is just a jumping off point, There are lots of doors to cool things that this opens for us that we will be exploring in further detail down the road.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf0a655e19cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>