<?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 Chris Feist on Medium]]></title>
        <description><![CDATA[Stories by Chris Feist on Medium]]></description>
        <link>https://medium.com/@chris-feist?source=rss-19cbc8915ae7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*7VV4pQYM0O7fo3a3h9h2PA.png</url>
            <title>Stories by Chris Feist on Medium</title>
            <link>https://medium.com/@chris-feist?source=rss-19cbc8915ae7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 22:01:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chris-feist/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[Having fun with React Hooks]]></title>
            <link>https://medium.com/weekly-webtips/having-fun-with-react-hooks-a5451fe12f70?source=rss-19cbc8915ae7------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5451fe12f70</guid>
            <category><![CDATA[konami-code]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[easter-egg]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Chris Feist]]></dc:creator>
            <pubDate>Tue, 23 Mar 2021 03:49:54 GMT</pubDate>
            <atom:updated>2021-04-07T06:43:10.758Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sA9pPN6a42LMG-hrmXSxqg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@helloimnik?utm_source=medium&amp;utm_medium=referral">Hello I’m Nik</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I was recently tasked with creating an Easter Egg in our application to launch a troubleshooting menu. In the past, I’ve done this by clicking on a sequence of items or on what appears to be a disabled icon a few times. However, this time I decided to try a different approach and implement a React hook that listens for the <a href="https://en.wikipedia.org/wiki/Konami_Code">Konami Code</a> input on the keyboard. Thus, the <a href="https://www.npmjs.com/package/use-konami">useKonami</a> hook was born. Here are the highlights:</p><ul><li>A hook that listens for a keyboard sequence (default is the Konami Code) on the window or a target element, and then calls an onUnlock callback after the sequence has been successfully entered by the user</li><li>Zero external dependencies</li><li>Built using standard <a href="https://reactjs.org/docs/hooks-reference.html">React Hooks API’s</a></li><li>Optimized to avoid unnecessary rerenders</li><li>Open source on <a href="https://github.com/chris-feist/use-konami">GitHub</a></li></ul><h4>How does it work?</h4><p>The hook uses React’s <a href="https://reactjs.org/docs/hooks-reference.html#useeffect">useEffect</a> hook to register and unregister a keydown event listener on the window or supplied target element. It then receives the keyboard down presses and compares them against the unlock sequence. Upon successfully pressing the sequence, the hook then calls the supplied onUnlock callback. If the sequence is entered incorrectly, then the optional onReset callback will be called. There is also an optional onKeyPress callback that is invoked each time a key in the sequence is successfully pressed.</p><h4>How is it optimized?</h4><p>A good hook implementation shouldn’t expect that the user is going to wrap their callbacks with React’s <a href="https://reactjs.org/docs/hooks-reference.html#usecallback">useCallback</a> hook. Since the keyboard event listener isn’t dependent on the supplied callback changes, <a href="https://github.com/chris-feist/use-konami/blob/4161ad60adab9c6e757500d1960a661c4b77ade3/src/index.ts#L70">the callbacks are stored</a> in a mutable variable using React’s <a href="https://reactjs.org/docs/hooks-reference.html#useref">useRef</a> hook. This avoids unnecessary re-renders and registering/unregistering of the keyboard event listener.</p><p>It should also be expected that a user may define their structured objects inline with the hook call as well. Therefore, the same approach was taken for a <a href="https://github.com/chris-feist/use-konami/blob/4161ad60adab9c6e757500d1960a661c4b77ade3/src/index.ts#L68">custom unlock sequence</a>. Both of these optimizations would guard against the following example:</p><pre>const MyUnlockableComponent = () =&gt; {<br>  useKonamiCode({<br>    // Callback defined inline<br>    onUnlock: () =&gt; console.log(&#39;UNLOCKED&#39;),<br>    // Structured data defined in render function<br>    sequence: [&#39;x&#39;, &#39;y&#39;, &#39;z&#39;, &#39;z&#39;, &#39;y&#39;],<br>  });</pre><pre>  return (&lt;div&gt;You can&#39;t unlock me!&lt;/div&gt;);<br>}</pre><h4>Any other goodies?</h4><ul><li>Fully typed codebase using TypeScript</li><li>Fully <a href="https://github.com/chris-feist/use-konami/blob/main/README.md">documented</a> API and repository</li><li><a href="https://chris-feist.github.io/use-konami/">Storybook examples available</a></li><li><a href="https://travis-ci.com/chris-feist/use-konami">Continuous Integration</a> with <a href="https://app.codecov.io/gh/chris-feist/use-konami">100% Test Coverage</a></li></ul><p>Thanks for reading my post and feel free to leave feedback here or in the <a href="https://github.com/chris-feist/use-konami">GitHub repo</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5451fe12f70" width="1" height="1" alt=""><hr><p><a href="https://medium.com/weekly-webtips/having-fun-with-react-hooks-a5451fe12f70">Having fun with React Hooks</a> was originally published in <a href="https://medium.com/weekly-webtips">Webtips</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up a Production GraphQL Server — Part 1: The Server]]></title>
            <link>https://medium.com/jetclosing-engineering/setting-up-a-production-graphql-server-part-1-the-server-e790c54f9adf?source=rss-19cbc8915ae7------2</link>
            <guid isPermaLink="false">https://medium.com/p/e790c54f9adf</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Chris Feist]]></dc:creator>
            <pubDate>Thu, 05 Mar 2020 21:56:55 GMT</pubDate>
            <atom:updated>2020-03-05T21:56:55.026Z</atom:updated>
            <content:encoded><![CDATA[<h3>Setting up a Production GraphQL Server — Part 1: The Server</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*z7o_SjOImbJI73tc" /><figcaption>Photo by <a href="https://unsplash.com/@aligns?utm_source=medium&amp;utm_medium=referral">Jordan Harrison</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>At <a href="https://www.jetclosing.com/">JetClosing</a>, we recently released Version 2 of our app. For this release, we developed a whole new backend service that uses <a href="https://graphql.org/">GraphQL</a> for its APIs. This mini-series will cover the steps needed to set up your own production-ready <a href="https://graphql.org/">GraphQL</a> server in <a href="https://aws.amazon.com/">AWS</a>, using the <a href="https://serverless.com/framework/docs/providers/aws/">Serverless Framework</a>, <a href="https://nodejs.org/">Node.js</a>, and <a href="https://www.apollographql.com/docs/apollo-server/">ApolloServer</a>. It utilizes <a href="https://aws.amazon.com/lambda/">Lambda</a> for running the server code, <a href="https://aws.amazon.com/api-gateway/">API Gateway</a> to serve our GraphQL API, and <a href="https://aws.amazon.com/dynamodb/">DynamoDB</a> as our backing data store.</p><h3>Create the Service</h3><p>To get started, you’ll want to make sure you have an <a href="https://serverless.com/framework/docs/providers/aws/guide/credentials/">AWS account set up and configured for Serverless</a>.</p><p>Next, we’ll want to generate our service using one of the templates. Run the following commands in your terminal, replacing my-graphql-service with the name of your service:</p><pre>mkdir -p ~/my-graphql-service<br>cd ~/my-graphql-service<br>npx serverless create --template aws-nodejs-ecma-script -n my-graphql-service<br>yarn install</pre><p>Using a template ensures we are using the latest standards; however, it requires some cleanup:</p><ul><li>Add a locked version of serverless: yarn add -D serverless</li><li>Delete example handlers: rm first.js second.js</li><li>In the serverless.yml file, delete everything under functions</li></ul><p>Next, we’ll want to add some better default options to our service. In the serverless.yml we’ll want to add the following under the provider field:</p><pre>provider:<br>  # Generated code...<br>  apiGateway:<br>    minimumCompressionSize: 1024 # Enable gzip compression for responses &gt; 1 KB<br>  environment:<br>    SERVICE: ${self:service}<br>    STAGE: ${opt:stage}<br>    AWS_NODEJS_CONNECTION_REUSE_ENABLED: 1 # Use http keep-alive for AWS connections</pre><p>Let&#39;s add the GraphQL and <a href="https://github.com/apollographql/apollo-server/tree/master/packages/apollo-server-lambda">ApolloServer</a> dependencies:</p><pre>yarn add graphql apollo-server-lambda graphql-tag graphql-tools</pre><h3>Create the GraphQL API</h3><p>Create the GraphQL and schema index.js files:</p><pre>mkdir -p src/graphQl/schema &amp;&amp; touch src/graphQl/index.js &amp;&amp; touch src/graphQl/schema/index.js</pre><p>Since we’re just setting up the server, we’ll create a temporary GraphQL schema for testing purposes. Add the following to your <a href="https://gist.github.com/chris-feist/769f8ca67edab408a49b87b3fc51c8d4">schema index file</a>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9003ee4d339be6aacfa4ba773f1dab5a/href">https://medium.com/media/9003ee4d339be6aacfa4ba773f1dab5a/href</a></iframe><p>Now we can set up our GraphQL handler code. Update your <a href="https://gist.github.com/chris-feist/b1c9405c1384443f9e329c37ffe5a0d6">GraphQL index file</a>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1790914bce5f9d592623500c485c5857/href">https://medium.com/media/1790914bce5f9d592623500c485c5857/href</a></iframe><p>You’ll notice we have enabled <a href="https://graphql.org/learn/introspection/">introspection</a> when not using a prod stage. If developing a public API, you should always enable it so that your API consumers can view the documentation.</p><p>Add the GraphQL function to your serverless.yml file under the functions field:</p><pre>functions:<br>  graphQl:<br>    handler: src/graphQL/index.graphQlHandler<br>    events:<br>      - http:<br>          path: /graphql<br>          method: post<br>          cors: true</pre><p>Now we have a functioning GraphQL service that can be deployed! You can test out a <em>dev</em> deployment by running:</p><pre>yarn serverless deploy -s dev</pre><h3>Setup GraphQL Playground</h3><p>Manually invoking a GraphQL API is cumbersome, so we’re going to set up a <a href="https://github.com/prisma-labs/graphql-playground">GraphQL Playground</a> environment to make manual testing of our API much easier.</p><p>Install the GraphQL Playground dependencies:</p><pre>yarn add graphql-playground-middleware-lambda aws-lambda</pre><p>Add the playground handler to your <a href="https://github.com/chris-feist/example-graphql-service/commit/6733af40590314fa57cedf22d4e22009acaabead">GraphQL index file</a>:</p><pre>import lambdaPlayground from &#39;graphql-playground-middleware-lambda&#39;;</pre><pre>export const playgroundHandler = lambdaPlayground({<br>  endpoint: `/${process.env.STAGE}/graphql`,<br>});</pre><p>Now add the playground function to your serverless.yml file:</p><pre>functions:<br>  # Existing graphQl function<br>  <br>  playground:<br>    handler: src/graphQL/index.playgroundHandler<br>    events:<br>      - http:<br>          path: /playground<br>          method: get<br>          cors: true</pre><p><em>You may consider securing your playground API unless your API is public</em></p><p>Now let&#39;s deploy our service so we can use the playground:</p><pre>yarn serverless deploy -s dev</pre><p>You should see the deployment result like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0jEjfBRh0oEA7J6D7j3SxQ.png" /></figure><p>Grab the playground endpoint and paste it into your browser. It should load up the playground and allow you to view our temporary schema and query the ping field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eyYhwz725eRoYJEI2gcOXw.png" /></figure><h4>Extra Credit: Unit Tests</h4><p>We will be using <a href="https://jestjs.io/">Jest</a> for our testing framework. Add the dependencies and initialize the project:</p><pre>yarn add -D jest babel-jest @babel/core @babel/preset-env<br>yarn jest --init</pre><p>Create a babel.config.js file in the root of your project:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/02fdeb0eaa61f5aaaff877b750272da1/href">https://medium.com/media/02fdeb0eaa61f5aaaff877b750272da1/href</a></iframe><p>Now you can create some <a href="https://github.com/chris-feist/example-graphql-service/commit/946bd7a53e29c7729a3ccb082c26b36703e5b13a">unit tests</a>.</p><p>Follow the <a href="https://medium.com/jetclosing-engineering">JetClosing Engineering Blog</a> and stay tuned for the next part which will include creating the API data with corresponding GraphQL schema and resolvers. Check out the <a href="https://github.com/chris-feist/example-graphql-service/tree/part1-the-service">example repo</a> for an implementation of everything up to this point.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e790c54f9adf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jetclosing-engineering/setting-up-a-production-graphql-server-part-1-the-server-e790c54f9adf">Setting up a Production GraphQL Server — Part 1: The Server</a> was originally published in <a href="https://medium.com/jetclosing-engineering">JetClosing Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create your own React hook]]></title>
            <link>https://medium.com/jetclosing-engineering/create-your-own-react-hook-5cae013304d2?source=rss-19cbc8915ae7------2</link>
            <guid isPermaLink="false">https://medium.com/p/5cae013304d2</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Chris Feist]]></dc:creator>
            <pubDate>Tue, 02 Jul 2019 17:26:23 GMT</pubDate>
            <atom:updated>2019-07-02T17:26:23.685Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*ONV-2xMNggMQCnUPJtZDFw.png" /></figure><p><a href="https://reactjs.org/docs/hooks-intro.html">React hooks</a> are a powerful way to supercharge functional components. However, beyond the useState and useEffect hooks, the <a href="https://reactjs.org/docs/hooks-custom.html">examples</a> for creating your own hooks are not very extensive. Let’s look at a practical example by implementing a file drag and drop on the whole window, which we’ll call the “Window Drop Zone”.</p><p>To get started, let&#39;s create our hook file. The <a href="https://reactjs.org/docs/hooks-custom.html#extracting-a-custom-hook">naming convention</a> for hooks is “use” plus the hook name, so let&#39;s create a file called useWindowDropZone.js with a basic shell function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f3b9a5b9379cebe843b862257969a0c/href">https://medium.com/media/3f3b9a5b9379cebe843b862257969a0c/href</a></iframe><p>When we use the window drop zone hook, we’ll want an onDrop callback that is invoked when the user drops files. We’ll need to use the <a href="https://reactjs.org/docs/hooks-reference.html#useeffect">useEffect</a> hook in order to add and remove the onDrop callback event listener.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef234ba3966ee127db28d648f04af272/href">https://medium.com/media/ef234ba3966ee127db28d648f04af272/href</a></iframe><p>The <a href="https://reactjs.org/docs/hooks-reference.html#useeffect">useEffect</a> hook is documented well, but here is a quick explanation: The first argument is a function that is executed on every render. It can optionally return a cleanup function that is executed before every re-render and when the component is unmounted. In our case, we’re adding the drop listener to the window and removing it in the cleanup function. The second argument of useEffect is an optional array of values that the effect depends on. This allows us to conditionally run the effect, instead of executing it on every render. In our case, we are saying only add the drop event listener when the onDrop argument changes. This means we don’t have to unnecessarily remove and re-add the listener on every render.</p><p>Let&#39;s see <a href="https://codesandbox.io/embed/usewindowdropzone-ondrop-88zk8">our new hook</a> in action:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rNm97D1-6aGqOmdakCVjaQ.gif" /></figure><h4>🤔🤔🤔</h4><p>It doesn’t appear to be working… What’s happening is that the browser is consuming the event and loading our dropped file. In order to fix this, we need to call the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault">preventDefault</a> method on the event. So we’ll have to supply our own drop event listener and a dragover listener to prevent the default event handling. We could easily create our own event listener functions to handle this. However, since we’re expecting our useWindowDropZone hook to be used in a functional component, that means each render will cause a new function to be created. Thankfully, React already has the <a href="https://reactjs.org/docs/hooks-reference.html#usecallback">useCallback</a> hook that only creates the function once, unless the dependencies change. Let’s see how this looks inside our hook:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb5100552aec8dcb16ff4d416b00bbd0/href">https://medium.com/media/bb5100552aec8dcb16ff4d416b00bbd0/href</a></iframe><p>So what did we do? We created onDropCallback that prevents the default handling of the event and calls the onDrop argument that is supplied to our hook. Like the useEffect hook, the second argument to the hook is an array of dependencies. In our case, we only want a new onDropCallback to be created when onDrop changes. We also created the onDragoverCallback that prevents the default event handling and we claim it has no dependencies by supplying an empty dependency array. This means that it will only be created once no matter how many times our useWindowDropZone hook is invoked while rendering. We also updated the drop event listener to use our new onDropCallback function, added a new dragover listener, and updated the effects dependencies.</p><p>Now let&#39;s see if our <a href="https://codesandbox.io/embed/usewindowdropzone-drop-dragover-yujnd">modified hook</a> works:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KRKFgRh0xs3UErZOjtLkmA.gif" /></figure><h4>Success!</h4><p>What if we could take this a step further and provide a dragging state from our hook? We can do that by returning an isDragging field from our hook. We’ll have to do some wiring up internally and leverage the <a href="https://reactjs.org/docs/hooks-reference.html#usestate">useState</a> and <a href="https://reactjs.org/docs/hooks-reference.html#useref">useRef</a> hooks:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5db0785833c576dd14ab183566d3c872/href">https://medium.com/media/5db0785833c576dd14ab183566d3c872/href</a></iframe><p>useRef what!?! An overlooked benefit to this hook is that it allows us to <a href="https://reactjs.org/docs/hooks-faq.html#is-there-something-like-instance-variables">keep track of mutable values</a> while not triggering rerenders. In our case, we need to count how many times we receive the dragenter and dragleave events so we can know when the drag has initially entered and finally left. Since we do want to trigger rendering when the dragging state changes, we use the useState hook. We also added a couple more event listeners and tied it all together. Let’s see our <a href="https://codesandbox.io/embed/usewindowdropzone-isdragging-wnwsu">latest changes</a> in action:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4PvIrWfN4ZWDTM41GYL4Hg.gif" /></figure><h4>It works!</h4><p>Now that we have a solid functioning hook, we could expand its features to include things such asonDragEnter and onDragLeave callbacks.</p><p>The true powers of hooks are yet to be fully realized, but with the right know-how, you can start to harness their power. Hopefully, this post will help you in creating your own hooks or expanding on existing ones. If you have any comments, feel free to leave them below and make sure to follow the <a href="https://medium.com/jetclosing-engineering">JetClosing Engineering blog</a> to see some of the great stuff we’re working on.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5cae013304d2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jetclosing-engineering/create-your-own-react-hook-5cae013304d2">Create your own React hook</a> was originally published in <a href="https://medium.com/jetclosing-engineering">JetClosing Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Manage table resources in serverless]]></title>
            <link>https://medium.com/hackernoon/manage-table-resources-in-serverless-df429f2fa58a?source=rss-19cbc8915ae7------2</link>
            <guid isPermaLink="false">https://medium.com/p/df429f2fa58a</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[cloudformation]]></category>
            <category><![CDATA[dynamodb]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Chris Feist]]></dc:creator>
            <pubDate>Fri, 08 Mar 2019 05:29:11 GMT</pubDate>
            <atom:updated>2019-03-08T18:03:13.756Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d5lcGhJ0YDxFaKZXDUgmtg.png" /><figcaption>Photo by <a href="https://unsplash.com/@blakeparkinson">Blake Parkinson</a> on <a href="https://unsplash.com/photos/3IX-Tz_0ZN0">Unsplash</a></figcaption></figure><p>Serverless is a great platform for managing your serverless infrastructure. It significantly reduces boilerplate code for setting up a service and defining functions. It even allows defining platform specific resources for things that aren’t supported out of the box. The problem is that service providers can require complex templates to support basic infrastructure. For example, AWS CloudFormation requires defining DynamoDB keys under two different fields for a single table. Therefore I created a plugin that would simplify table definitions, reduce boilerplate code and have smart defaults: <a href="https://github.com/chris-feist/serverless-plugin-tables">serverless-plugin-tables</a>.</p><h3>Let’s see an example</h3><p>Below are two example servlerless.yml definitions for a table described in the <a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html">DynamoDB documentation</a>. The first example is using the <a href="https://serverless.com/framework/docs/providers/aws/guide/resources#configuration">standard CloudFormation template</a> and the second is using serverless-plugin-tables.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af138f71d6545a0a3cf55ca30dd000ea/href">https://medium.com/media/af138f71d6545a0a3cf55ca30dd000ea/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f84d124ac1574a97dfd1bd59869c7635/href">https://medium.com/media/f84d124ac1574a97dfd1bd59869c7635/href</a></iframe><p>As you can see, the serverless-plugin-tables implementation has significantly reduced boilerplate (1/3 the lines). It also has sane defaults, using <a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadWriteCapacityMode.html#HowItWorks.OnDemand">On-Demand Billing Mode</a> and strings as the default data types. Despite being so simple to define, it is fully customizable, supporting every CloudFormation option at the time of release. See the complete <a href="https://github.com/chris-feist/serverless-plugin-tables#aws-example">example in the Readme</a>.</p><h3>Sounds great! Let’s incorporate it!</h3><p>First, add the dependency to your existing Serverless project:</p><p>yarn add -D serverless-plugin-tables</p><p>Now add the plugin to your service file:</p><pre># serverless.yml</pre><pre>plugins:<br>  - serverless-plugin-tables</pre><p>Now define the `resources` section if you don’t already have one, add a tables property, and start creating tables 🤩</p><pre># serverless.yml</pre><pre>resources:<br>  tables:<br>    # Start defining tables here</pre><p>Here is another table example for Users, with a little more configuration:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21906300802fc997911860059c594489/href">https://medium.com/media/21906300802fc997911860059c594489/href</a></iframe><p>For even more configuration options, check out the <a href="https://github.com/chris-feist/serverless-plugin-tables#providers">GitHub Readme</a>, which describes each option along with links to the AWS documentation.</p><h4>What about other providers and databases?</h4><p>I started off the project by implementing it for AWS DynamoDB. However, I designed it so it can easily expand to support other service providers and database platforms. So if there is another platform you want to be supported, comment here or submit an issue on <a href="https://github.com/chris-feist/serverless-plugin-tables">GitHub</a>.</p><p>Let me know what you think. Leave a comment below and give me some claps. The longer you hold the claps button, the more I get 👏👏👏</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df429f2fa58a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/manage-table-resources-in-serverless-df429f2fa58a">Manage table resources in serverless</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making serverless variables work for you]]></title>
            <link>https://medium.com/hackernoon/making-serverless-variables-work-for-you-900dcf0607f3?source=rss-19cbc8915ae7------2</link>
            <guid isPermaLink="false">https://medium.com/p/900dcf0607f3</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[serverless-framework]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Chris Feist]]></dc:creator>
            <pubDate>Wed, 16 Jan 2019 05:22:21 GMT</pubDate>
            <atom:updated>2019-03-07T04:20:41.361Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nl8RtUkb7gp3bmLbF_EhdA.png" /><figcaption>Photo by <a href="https://unsplash.com/@casparrubin">Caspar Camille Rubin</a> on <a href="https://unsplash.com/photos/fPkvU7RDmCo">Unsplash</a></figcaption></figure><p><a href="https://serverless.com/">Serverless</a>, a framework for managing cloud applications, is a very powerful tool. As your application grows in complexity, it can be difficult to manage deployment variables based on different stages (development, QA, production). Currently it isn’t easy to reference deployment specific custom or environment variables. I knew there had to be a better way of handling these variables while also making them composable. After some research into serverless’ architecture, I came up with a plugin that does just that: <a href="https://github.com/chris-feist/serverless-plugin-composed-vars">serverless-plugin-composed-vars</a>.</p><h3>What does it do?</h3><p><a href="https://github.com/chris-feist/serverless-plugin-composed-vars">serverless-plugin-composed-vars</a> lets you define stage specific variable files. It overrides the variables defined in your serverless.yml or in separate variables.yml and environment.yml files for custom and environment variables respectively. To define stage specific files, just insert the stage name into the file like so: variables.stage.yml or environment.stage.yml. For example, if you’d like to create variable files for your stage named “prod”, you’d name the files variables.prod.yml and environment.prod.yml.</p><p>Let’s see it in action:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e30da71fd026418e005dfbc5155832cf/href">https://medium.com/media/e30da71fd026418e005dfbc5155832cf/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/87543eca91c6581e12a570c910802ec8/href">https://medium.com/media/87543eca91c6581e12a570c910802ec8/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/34a2433d56a74b8957648e6f9c08e270/href">https://medium.com/media/34a2433d56a74b8957648e6f9c08e270/href</a></iframe><p>Using the example files above, custom and environment variables are composed and computed into the following for a “prod” deployment stage:</p><pre>custom:<br>  googlesWebsite: www.google.com<br>  myEndpoint: api.endpoint.com<br><br>environment:<br>  THE_ANSWER_IS: 42<br>  USER_TABLE_NAME: Users<br>  MY_ENDPOINT: api.endpoint.com</pre><p>For a cleaner serverless.yml service file, you can separate your default variables into their own variables.yml and environment.yml files. <a href="https://github.com/chris-feist/serverless-plugin-composed-vars">serverless-plugin-composed-vars</a> will automatically read those files when composing your deployment variables. Note that the serverless.yml file variables have the least priority when also using default variable files.</p><h3>How do I use it?</h3><h4>Install</h4><p>Install the plugin using your favorite package manager:</p><p>npm install -D serverless-plugin-composed-vars</p><p>or</p><p>yarn add -D serverless-plugin-composed-vars</p><h4>Enable</h4><p>Add the plugin to your service file:</p><pre># serverless.yml</pre><pre>plugins:<br>  - serverless-plugin-composed-vars<br>  - other-serverless-plugin</pre><p><strong>Note</strong>: To ensure compatibility with other plugins, it is recommended that <a href="https://github.com/chris-feist/serverless-plugin-composed-vars">serverless-plugin-composed-vars</a> be the first plugin in the plugins list.</p><h4>Create</h4><p>Create deployment stage variable files. The default file names are variables.stage.yml and environment.stage.yml for custom and environment variables. Here’s an example project structure for custom variables:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7828408832366aef9618c9a75fdb58a9/href">https://medium.com/media/7828408832366aef9618c9a75fdb58a9/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b29058fcf144a5e5faa6c3fbb4f41ee1/href">https://medium.com/media/b29058fcf144a5e5faa6c3fbb4f41ee1/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a289e606c3112e09de3eeb6d48559f60/href">https://medium.com/media/a289e606c3112e09de3eeb6d48559f60/href</a></iframe><h4>Advanced Usage</h4><p>For advanced usage and configuration, see the <a href="https://github.com/chris-feist/serverless-plugin-composed-vars#advanced-usage">GitHub Readme</a>.</p><h3>How does it work?</h3><p>Under the covers, <a href="https://github.com/chris-feist/serverless-plugin-composed-vars">serverless-plugin-composed-vars</a> leverages the fact that serverless doesn’t compute variables <a href="https://serverless.com/framework/docs/providers/aws/guide/plugins/#serverless-instance">until hooks are executed</a>. This allows the plugin to compose deployment stage variables and rewrite them before your service is packaged for deployment.</p><h3>Check it out!</h3><p>Now that you’ve seen how easy it is to use deployment stage variables, give the plugin a shot. Leave any comments or suggestions here or submit issues on the <a href="https://github.com/chris-feist/serverless-plugin-composed-vars">GitHub</a> repository.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=900dcf0607f3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/making-serverless-variables-work-for-you-900dcf0607f3">Making serverless variables work for you</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing private JavaScript functions using Babel]]></title>
            <link>https://medium.com/jetclosing-engineering/testing-private-javascript-functions-using-babel-20cab9bc48f4?source=rss-19cbc8915ae7------2</link>
            <guid isPermaLink="false">https://medium.com/p/20cab9bc48f4</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[babel]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Chris Feist]]></dc:creator>
            <pubDate>Tue, 18 Sep 2018 17:25:35 GMT</pubDate>
            <atom:updated>2018-12-18T18:42:03.283Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*Flxld10x12l6HfmMj7zEYw.jpeg" /></figure><p>At <a href="http://www.jetclosing.com/">JetClosing</a> we utilize decomposition and modular programming. As projects get larger, it’s important to clearly define the interface between objects by exporting the methods that make up that interface. Sometimes this can cause issues when trying to unit test that code, especially the private functions. The existing strategies for accomplishing this have their own issues:</p><ul><li><strong>Exposing private members</strong> - This creates potential security issues and can effect development; such as when auto imports suggest the intended private members over other public members.</li><li><strong>Testing through public functions</strong> - This approach is a pain! In order to have targeted tests for the private functions, it requires a bunch of setup and teardown code just to ensure the private function is executed.</li><li><strong>Use existing 3rd party options</strong> - The current options are limited, and require multiple plugins or custom test imports; such as <a href="https://www.npmjs.com/package/denude">denude</a> and <a href="https://www.npmjs.com/package/babel-plugin-test-export">babel-plugin-test-export</a>.</li></ul><p>None of these strategies are ideal or practical in large projects, so we decided to create our own solution as a single Babel plugin: <a href="https://github.com/JetClosing/babel-plugin-testable">babel-plugin-testable</a>. Like most modern javascript developers, we are using Babel to compile modern javascript into backwards compatible code. Therefore, we made a plugin that could export our ES6+ code for testing purposes.</p><h3>Integrating the plugin</h3><h4>Install</h4><p>Install the plugin using your favorite package manager: npm install -D babel-plugin-testable or yarn add -D babel-plugin-testable.</p><h4>Enable</h4><p>Add the plugin to your Babel configuration:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c11c9c4d297cacea3907eaf91554caa/href">https://medium.com/media/4c11c9c4d297cacea3907eaf91554caa/href</a></iframe><h3>Using the Plugin</h3><p>Now, decorate and import!</p><h4>Decorate</h4><p>Add testable comments to the code you want to test:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3238049deed3f2e390b737956be68442/href">https://medium.com/media/3238049deed3f2e390b737956be68442/href</a></iframe><h4>Import</h4><p>Import your private members along with the public members in your tests, and add any test code you need:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ca55b190e50db54abb3e509df954069/href">https://medium.com/media/0ca55b190e50db54abb3e509df954069/href</a></iframe><h3>That’s it!</h3><p>Now you can import any private function, variable, or class for testing purposes. Simple and clean!</p><h4>The Nitty Gritty</h4><p>So how does it work? This is pretty simple too!</p><p>When compiling the code, the plugin keys off of the NODE_ENV or BABEL_ENV environment variables to determine if the code is being compiled for tests. If neither of these are &#39;test&#39;, then it compiles as it normally would. Otherwise, it looks for top level private members (variables, functions, and classes) that are annotated with the // @testable comment, and adds an export in front of them. This allows the private members to be imported in your test files like any other exported member.</p><h3>Give it a shot!</h3><p>Now that we’ve made testing private members easier for you, give it a shot! Let us know what you think in the comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20cab9bc48f4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jetclosing-engineering/testing-private-javascript-functions-using-babel-20cab9bc48f4">Testing private JavaScript functions using Babel</a> was originally published in <a href="https://medium.com/jetclosing-engineering">JetClosing Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>