<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Kris Guzman</title>
    <description>The latest articles on Forem by Kris Guzman (@krisguzman_dev).</description>
    <link>https://forem.com/krisguzman_dev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F522658%2Fc8818078-6edf-4293-9dc8-44ad54c7c9e3.jpg</url>
      <title>Forem: Kris Guzman</title>
      <link>https://forem.com/krisguzman_dev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/krisguzman_dev"/>
    <language>en</language>
    <item>
      <title>React Server Components (Lingering Questions)</title>
      <dc:creator>Kris Guzman</dc:creator>
      <pubDate>Fri, 12 Nov 2021 03:03:21 +0000</pubDate>
      <link>https://forem.com/krisguzman_dev/react-server-components-lingering-questions-3md9</link>
      <guid>https://forem.com/krisguzman_dev/react-server-components-lingering-questions-3md9</guid>
      <description>&lt;p&gt;I watched &lt;a href="https://reactjs.org/blog/2020/12/21/data-fetching-with-react-server-components.html"&gt;the talk&lt;/a&gt; on React Server Components, and after all the excitement finally settled, I was actually left a bit confused. Hoping some smarter folks than I can shed some light on a few things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;"Server components don't render into HTML, they render into a special format" - Then what parses that special format into rendered HTML once it's streamed to the client? Does the React client side library do this automagically?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I understand that server components can be re-fetched when props change, while still maintaining the rendered dom on the client, but how are server components made aware of changes in props triggered in client components?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Anyone have any good reads on streaming rendering in relation to React?&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>react</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Getting the Job: What's more important than technical skills?</title>
      <dc:creator>Kris Guzman</dc:creator>
      <pubDate>Tue, 29 Dec 2020 11:00:10 +0000</pubDate>
      <link>https://forem.com/krisguzman_dev/getting-the-job-what-s-more-important-than-technical-skills-3o7m</link>
      <guid>https://forem.com/krisguzman_dev/getting-the-job-what-s-more-important-than-technical-skills-3o7m</guid>
      <description>&lt;p&gt;As developers, we put a lot of merit on our own technical abilities. When we chase client work or go for that new job, we obsess over emphasizing our technical skills.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"I know how to build a scalable architecture!"&lt;/p&gt;

&lt;p&gt;"I've used React, Redux, Vue JS, Express, C++, Java, etc!"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But what if I told you...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Your skills don't matter as much as you think.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Having interviewed several developers, as well as having heard feedback from client projects I've won, trust me, skills are rarely the key deciding factor!&lt;/p&gt;

&lt;p&gt;So if skills aren't the most important thing, what &lt;em&gt;does&lt;/em&gt; matter?&lt;/p&gt;

&lt;h3&gt;
  
  
  Personality
&lt;/h3&gt;

&lt;p&gt;This is going to piss people off, but it's the truth. You are working with people, not robots, and people have the right to want to work with someone they can genuinely talk to each day. &lt;br&gt;
When a client or interviewer asks what you like to do on your free time, it's not a test question. Don't tell me "I stay up to date with tech trends". If you like binging a certain Netflix series, share that! It's often a great talking point.&lt;/p&gt;

&lt;h3&gt;
  
  
  Communication Skills
&lt;/h3&gt;

&lt;p&gt;This isn't the 90s. You need to be able to effectively communicate on a team, and this doesn't mean being able to explain your code to people. This is about taking the initiative to ask questions, contributing your own thoughts to conversations, and using your expertise to bring up potential issues that only you can foresee a developer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Business Oriented Thinking
&lt;/h3&gt;

&lt;p&gt;Many developers claim to have this, but few do. Business oriented thinking is the ability to put your developer intuitions aside and put business priorities first. Did you want to use a Framework X but Framework Y would get the job done faster? Go with Framework Y. Does that fancy animation in your header contribute any business value? No? Then drop it.&lt;/p&gt;

&lt;p&gt;If you're going for a junior or mid developer position, you will probably do fine without this skill, but once you start aiming for higher positions, this gets increasingly more important.&lt;/p&gt;

&lt;p&gt;For freelance developers seeking clients, &lt;em&gt;this is everything.&lt;/em&gt; Get good at it, because this will get you where you want to be beyond your technical skills.&lt;/p&gt;

&lt;h3&gt;
  
  
  Passion &amp;amp; Genuine Interest
&lt;/h3&gt;

&lt;p&gt;Every happy client I've had and job I've gotten was due to this. Being smart and talented are fantastic traits, but it won't necessarily get you as far as you might have thought. On the other hand, showing genuine interest in the client or company, the problems they are trying to solve, as well as showing the passion you have for your own work, those are the things that get you hired.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The fact is, everyone claims to have strong technical skills, and it is hard to verify those skills in a 1 hour phone call. Knowing this, interviewers and clients use other methods to determine whether to hire you over the sea of other "expert JavaScript developers" out there. &lt;/p&gt;

&lt;p&gt;Not surprisingly, these methods often come down to, "would I like working this guy / gal"?&lt;/p&gt;

&lt;p&gt;Does that sound unfair to you? Then you're thinking about it wrong. We live in a world full of people, and people are social creatures whether you like it or not. The sooner you recognize that, the faster you will find success (and dare I say happiness).&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>career</category>
    </item>
    <item>
      <title>6 Things Programmers Can Learn From Writers</title>
      <dc:creator>Kris Guzman</dc:creator>
      <pubDate>Thu, 10 Dec 2020 15:05:33 +0000</pubDate>
      <link>https://forem.com/krisguzman_dev/6-things-programmers-can-learn-from-writers-5806</link>
      <guid>https://forem.com/krisguzman_dev/6-things-programmers-can-learn-from-writers-5806</guid>
      <description>&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  6 Things Programmers Can Learn From Writers
&lt;/h1&gt;

&lt;p&gt;The art of writing actually has a lot to teach programmers about good software. Here are six tips you learn as a writer that can also be used by developers.&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  1. The First Draft Will Probably Suck
&lt;/h1&gt;

&lt;p&gt;When writing, your first draft is usually… not great. As you get better at writing, the quality of your first draft will improve as well. Fewer and fewer adjustments will be needed over time, but the point remains: Your first draft will almost always be the worst version.&lt;/p&gt;

&lt;p&gt;Programming is no different! Accept that your first draft is exactly that — a draft. That doesn’t mean you don’t put your best effort into it, but you shouldn’t be prematurely optimizing and spending a bunch of time “beautifying” your code. There is a high chance that no matter what you do, when you come back to your desk on the next go-around, you will have thought of a far better solution.&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  2. Proof Read Your Own Work
&lt;/h1&gt;

&lt;p&gt;This is an obvious one. Anyone can usually tell when a writer didn’t even proofread their own work (spoiler alert, I didn't proof read this article!). The same applies to programmers.&lt;/p&gt;

&lt;p&gt;Typos, leftover console logs, bugs so obvious you can catch them at a glance — these are all typically red flags in a code review that the programmer didn’t do much proofreading of their own work.&lt;/p&gt;

&lt;p&gt;Proof testing your work is equally important. If you are submitting a feature as ready for user testing/review, make sure it actually works. Even if it's a one line change, I promise you that the one time you decide to skip the verification step, it's going to break something in the app against all odds.&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  3. Then Let Others Proof Read Your Work
&lt;/h1&gt;

&lt;p&gt;Great writers usually have someone proofread their work. Sometimes no matter how much you look over your own work, you just can’t catch the obvious (or not so obvious) issues. Programming in a team is no different. The whole concept of “code reviews” revolves around this one idea of having others proofread your work to minimize problems.&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  4. There Will Probably Be a Second or Third Draft
&lt;/h1&gt;

&lt;p&gt;When you had to write essays in school, how often did you submit your first draft and never have to touch it again? I assume (hope?) that has never happened. I remember having to revise my work two or three times before I was allowed to submit it as “complete.”&lt;/p&gt;

&lt;p&gt;Programmers often tie their ego to getting their code right the first time (code interviews and competitions kind of push that).&lt;/p&gt;

&lt;p&gt;Considering that an error-free piece of software has never been written, I’d say that kind of thinking will set you up for disappointment.&lt;/p&gt;

&lt;p&gt;Your pull request may get rejected even when you think you did everything perfectly. That’s OK. You should be happy someone has given you the opportunity to learn and improve. We all have something to learn from each other.&lt;/p&gt;

&lt;p&gt;Now, you may submit a second pull request and get rejected &lt;em&gt;yet&lt;/em&gt; &lt;em&gt;again&lt;/em&gt;. OK, I’ll admit that hurts the ego a bit, but it’s the same principle: Learn, improve, repeat.&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  5. A Finished Piece Is Better Than a Perfect Work in Progress
&lt;/h1&gt;

&lt;p&gt;The article that is never complete will always be worse than the article never written. Have you ever &lt;em&gt;not&lt;/em&gt; submitted an essay to your teacher because you were perfecting it and received an A+ as a grade? Hell no. You got a big fat F for failure.&lt;/p&gt;

&lt;p&gt;Coding is absolutely no different. If your software takes two years to build because you want it to be perfect, you’ve probably already failed (and a year ago at that).&lt;/p&gt;

&lt;p&gt;Accept that even your completed work won’t be a masterpiece and you will still be iterating on it long after you considered it done. The most important theme shared between writers and developers is that it is important to get feedback as soon as possible so we can make the necessary improvements sooner rather than later.&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  6. Keep a Cohesive Narrative
&lt;/h1&gt;

&lt;p&gt;Have you ever read an article that can’t seem to stay on track? It’s like a roller coaster, but on a roller coaster, you enjoy the random twists, turns, and loops. In an article where all you want is information (or a good story), this is usually not desirable.&lt;/p&gt;

&lt;p&gt;Something that requires a lot of skill in both writers and developers is the ability to elegantly flow the narrative from start to finish. To make the reader feel like they went on a journey, even if all they read was “I watched paint dry yesterday,” is part of what makes the top writers here on Medium so successful.&lt;/p&gt;

&lt;p&gt;Programmers may be thinking, “Code should be optimal and easy to read — not tell a story.”&lt;/p&gt;

&lt;p&gt;Is that so? What if I told you code that tells a story is easier to read? There is a reason humans are so responsive to a well-told story. Just check out this &lt;a href="https://www.wired.com/2011/03/why-do-we-tell-stories/"&gt;article on the psychology of storytelling.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When your code has a clear start, middle, and end, it naturally forms a story (an admittedly boring one), which makes it easier for other programmers to follow it.&lt;/p&gt;

&lt;p&gt;If you really want to level up your programming skills, see if you can write code that is not only optimal but tells a narrative as well. I think you will find that others have a much easier time navigating your code.&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Writing and programming have more in common than you may have thought.&lt;/p&gt;

&lt;p&gt;See more connections? Add them in the comments section!&lt;/p&gt;

</description>
      <category>programming</category>
      <category>productivity</category>
      <category>codequality</category>
    </item>
    <item>
      <title>Better Way to Structure React Projects (Part 2)</title>
      <dc:creator>Kris Guzman</dc:creator>
      <pubDate>Wed, 09 Dec 2020 15:25:45 +0000</pubDate>
      <link>https://forem.com/krisguzman_dev/better-way-to-structure-react-projects-part-2-b3</link>
      <guid>https://forem.com/krisguzman_dev/better-way-to-structure-react-projects-part-2-b3</guid>
      <description>&lt;p&gt;&lt;a href="https://dev.to/krisguzman_dev/a-better-way-to-structure-react-projects-96a"&gt;In part 1 of this series&lt;/a&gt;, I talked about how to use the &lt;a href="https://atomicdesign.bradfrost.com/chapter-2/" rel="noopener noreferrer"&gt;atomic design methodology&lt;/a&gt; to structure your React components. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It's safe to say that there was a lot of controversy around it.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Objections
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;This is nice on small projects but it doesn't scale.&lt;/li&gt;
&lt;li&gt;I would go nuts trying to differentiate between an atom, molecules, organism, etc.&lt;/li&gt;
&lt;li&gt;This is a design methodology, it doesn't work well in development.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All fair points. I purposefully didn't go into much detail in part 1, so if you had any of the concerns mentioned above, today is the day I address them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Objection 1: This is nice on small projects but it doesn't scale.
&lt;/h3&gt;

&lt;p&gt;A big concern is that many components either don't nicely fall under an atomic category, or are so domain specific that they can only be used in one place.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First let me ask you this.&lt;/strong&gt; How often do you use a new JavaScript library, found the first example in the documentation, and it satisfied your requirements for small and large projects alike? &lt;/p&gt;

&lt;p&gt;Probably not often.&lt;/p&gt;

&lt;p&gt;The same applies to an atomic design folder structure. &lt;strong&gt;You have to adjust it to your specific needs.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here are two ways I have used it on existing projects:&lt;/p&gt;

&lt;h4&gt;
  
  
  Option A - Add a "components" sub folder in each page
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqjbr31dyp390c5s5zj6o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqjbr31dyp390c5s5zj6o.png" alt="component sub folder"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You might be hesitant to add yet another components folder, but in practice I found this to be very intuitive for developers. You have a "shared" components folder at the root. You can even rename your root components folder to "shared" if it helps separate concerns a bit more. The new components folder, specific to each page, contains one-off components with a lot of business logic that feel doesn't make sense to put in a shared folder.&lt;/p&gt;

&lt;p&gt;A benefit of this approach is that it's easy to take your "shared" components folder and turn it into a component library with very little additional work.&lt;/p&gt;

&lt;h4&gt;
  
  
  Option B - Add a "domains" folder
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F88un8661qmpcui552fnk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F88un8661qmpcui552fnk.png" alt="Example folder structure with a domains folder"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This structure works particularly well for Next.js applications, since you can't add components to the pages folder without them being detected as actual web pages.&lt;/p&gt;

&lt;h3&gt;
  
  
  Objection 2: I would go nuts trying to differentiate between an atom, molecules, organism, etc.
&lt;/h3&gt;

&lt;p&gt;This can get very subjective, but like any other organizational decision, how each level of components are differentiated &lt;strong&gt;should be agreed upon by the whole team.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It's okay if your definition of an atom and a molecule don't exactly match what Brad Frost defines as an atom and a molecule. &lt;strong&gt;Define it in a way that makes sense to you, your team, and your project.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;How I categorize components changes from project to project, &lt;strong&gt;but here is how I approach it in general&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxlatmcspunhdatcgz0tf.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxlatmcspunhdatcgz0tf.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;atoms&lt;/strong&gt;&lt;br&gt;
The smallest component I can create. Typically these are Buttons, Icons, Typography, Images, Text Fields, etc. It isn't very hard to determine what would make an atom. If you can't break a component down any further, you have an atom.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;molecules&lt;/strong&gt;&lt;br&gt;
Components that are a relatively simple combination of atoms. They should have a very specific responsibility. Here are some examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A search field and submit button &lt;/li&gt;
&lt;li&gt;A multi select dropdown&lt;/li&gt;
&lt;li&gt;A product list item with an image, title, price, and description (or any kind of list item)&lt;/li&gt;
&lt;li&gt;A snackbar component with a message, icon, and close button&lt;/li&gt;
&lt;li&gt;A card component&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;organisms&lt;/strong&gt;&lt;br&gt;
organisms and molecules are the hardest to differentiate. I personally identify organisms as orchestration components. They tend to be more abstract, and control how molecules are laid out and interact with one another. This includes things like headers, sidebars, modals, forms, grid layouts, lists, etc. &lt;/p&gt;

&lt;p&gt;In a simple world, you would keep application state out of organisms and let pages feed the actual data, but I found that this only works for very simple apps.&lt;/p&gt;

&lt;p&gt;With that being said, this is typically the lowest level of components where I start injecting app specific state in order to keep a balance between performance and organization.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;templates&lt;/strong&gt;&lt;br&gt;
Truthfully, I don't use this folder very much in practice on large projects. It can be very handy when you are using tools like storybook and want to mock entire parts of the application, or if you have an app with a relatively simple state structure, but I haven't found much value outside of that. By definition, you wouldn't want these components to manage any application state since that would defeat the purpose of it being a template. Consequently, it's hard to justify this additional layer on large projects, but if anyone has suggestions please share!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;pages&lt;/strong&gt;&lt;br&gt;
This is one is usually clear cut. One thing I'll say about it is that if you can keep all of your business logic at the page level, then more power to you. &lt;strong&gt;It makes maintenance extremely easy, since your application state is in one place.&lt;/strong&gt; However, this is pretty hard to implement in large, data driven applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My advice would be to try and keep your business logic at the page level for as long as you can&lt;/strong&gt;, and only move things down layers when it's absolutely necessary. This should keep you from pre-maturely optimizing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Objection 3: This is a design methodology, you can't use it in development.
&lt;/h3&gt;

&lt;p&gt;... what? We can't draw inspiration from places outside of our domain? &lt;/p&gt;

&lt;p&gt;Atomic design is a mental model that &lt;strong&gt;applies directly to Component Driven Development principles.&lt;/strong&gt; In CCD, we want to start with the smallest, simplest components and build our way up until we get our end result: pages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Atomic design encourages you to think in terms of composition&lt;/strong&gt;. It's not a rigid set of rules. You can just as easily create some kind of analogy to legos, an orchestra (my personal favorite), or sports. Whatever floats your boat and gets the point across.&lt;/p&gt;

&lt;p&gt;To say we can't use atomic design as developers because it's a design methodology just sounds lazy. &lt;strong&gt;If we as developers are doing our jobs right, we are designers as well, just at a different stage of the system.&lt;/strong&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I hope this cleared up some doubts around the use of atomic design in a development environment. &lt;strong&gt;I'm not saying atomic design is the all encompassing solution to your code organization problems, but it's definitely a handy tool to have in your toolbox.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>tutorial</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to Run Stripe Webhooks Locally</title>
      <dc:creator>Kris Guzman</dc:creator>
      <pubDate>Fri, 04 Dec 2020 10:18:17 +0000</pubDate>
      <link>https://forem.com/krisguzman_dev/how-to-run-stripe-webhooks-locally-43g5</link>
      <guid>https://forem.com/krisguzman_dev/how-to-run-stripe-webhooks-locally-43g5</guid>
      <description>&lt;p&gt;Today's article is going to be a bit niche, but nevertheless it's an issue I have run into on multiple projects and have finally reached a solid solution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note: This solution can be applied to PayPal, and any other platform that requires you to listen to webhooks.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;Stripe (and other payment solutions like PayPal) allows your application to listen to webhooks for all kinds of payment events (subscription updated, invoice creation, etc).&lt;/p&gt;

&lt;p&gt;When trying to test payment events locally, we have to use our "live" test endpoints, since Stripe can only send events to a real server, not localhost.&lt;/p&gt;

&lt;p&gt;This is a huge pain when debugging payments, since you have to deploy your test environment for every single change.&lt;/p&gt;

&lt;p&gt;Also, Stripe only gives you two environments: test mode, and live mode. This ends up being pretty limiting for the common "local, dev, qa, prod" environment setup.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Solution
&lt;/h2&gt;

&lt;p&gt;We need a way to funnel webhook events to our locally running API. Luckily, some people smarter than I have created free tools for us to do this.&lt;/p&gt;

&lt;h3&gt;
  
  
  Install Ultrahook
&lt;/h3&gt;

&lt;p&gt;What is &lt;a href="https://www.ultrahook.com/"&gt;ultrahook&lt;/a&gt;? It's an awesome, free tool that allows you to receive webhook events on localhost by funneling requests from the Ultrahook cloud (via your unique url), to your private endpoint (ex. localhost:8080). Once you try it, you won't ever go back.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;If you haven't already, &lt;a href="https://www.ultrahook.com/register"&gt;create an Ultrahook account&lt;/a&gt; to receive your API key.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next, run &lt;code&gt;gem install ultrahook&lt;/code&gt; on the command line. You may have to install &lt;code&gt;ruby&lt;/code&gt; first by running &lt;code&gt;brew install ruby&lt;/code&gt; on Mac, or perhaps  &lt;a href="https://rubyinstaller.org/"&gt;this easy-installer&lt;/a&gt; for Windows.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run &lt;code&gt;echo "api_key: INSERT_API_KEY_HERE" &amp;gt; ~/.ultrahook&lt;/code&gt; so you don't have to pass in your API key on every ultrahook command&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run &lt;code&gt;ultrahook stripe INSERT_DESTINATION_HERE&lt;/code&gt;, where the destination is your local endpoint (ex. localhost:8080/webhooks/stripe)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And that's it! Thank you &lt;a href="https://twitter.com/veesahni"&gt;Vinay Sahni&lt;/a&gt; for creating this!&lt;/p&gt;

&lt;h3&gt;
  
  
  Note for Teams
&lt;/h3&gt;

&lt;p&gt;There are two approaches (that I've thought at least) you can take to get this setup for a team:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Let each member create their own ultrahook account, and as part of the onboarding process, they add their listeners to Stripe.&lt;/li&gt;
&lt;li&gt;Use a master ultrahook account and share it with your team.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I think option 1 is the safer choice, although more tedious.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a New Stripe Account
&lt;/h3&gt;

&lt;p&gt;This might seem a bit annoying, but it really makes your dev life easier.&lt;/p&gt;

&lt;p&gt;I usually organize it as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Main Stripe Account -&amp;gt; live -&amp;gt; production&lt;/li&gt;
&lt;li&gt;Main Stripe Account -&amp;gt; test mode -&amp;gt; QA&lt;/li&gt;
&lt;li&gt;Test Stripe Account -&amp;gt; test mode -&amp;gt; local&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Enjoy the fruits of your labor
&lt;/h3&gt;

&lt;p&gt;It takes a hot minute to set this up, but once you do, you will be &lt;em&gt;so&lt;/em&gt; happy you did. At least I was.&lt;/p&gt;

&lt;p&gt;If anyone goes with this setup, I'd love to hear about your experience! Any ideas for improvements? Let me know.&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>JS 101: Destructuring Assignment over Function Parameters</title>
      <dc:creator>Kris Guzman</dc:creator>
      <pubDate>Thu, 03 Dec 2020 11:50:32 +0000</pubDate>
      <link>https://forem.com/krisguzman_dev/js-101-destructuring-assignment-over-function-parameters-29j7</link>
      <guid>https://forem.com/krisguzman_dev/js-101-destructuring-assignment-over-function-parameters-29j7</guid>
      <description>&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  JavaScript: Use Destructuring Assignment over Function Parameters
&lt;/h1&gt;

&lt;p&gt;With ES6 comes the ability to leverage destructuring assignment. For those who aren’t familiar with the syntax, it can seem a little weird. Once you understand how it works, I promise you will want to  use it almost everywhere.&lt;/p&gt;

&lt;h1&gt;
  
  
  Quick Primer on Destructuring Assignment
&lt;/h1&gt;

&lt;p&gt;Destructuring assignment with objects is just a way to take any JavaScript object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myFoods = {a: 'apple', b: 'banana', c: 'carrot', d: 'donut'}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And pull out the parameters we want into its own variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { a, b, c, d} = myFoods
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we aren’t sure a variable exists, we can easily provide a default value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const {a = 'apple didn't exist', b, c, d} = myFoods
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we want to rename one of the variables, we can do so like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// we renamed a to be apple 
const {a: apple, b, c, d} = myFoods
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we only want fruits (&lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; without &lt;code&gt;c&lt;/code&gt; and &lt;code&gt;d&lt;/code&gt;), we can pick out the fruits and group the random foods by doing the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// you will often see "...rest" used as a convention 
const {a, b, ...otherFoods} = myFoods  
const carrotAndDonut = {...otherFoods} 

console.log(carrotAndDonut) // prints out {c: 'carrot', d: 'donut'}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that’s all there really is to it!&lt;/p&gt;

&lt;h1&gt;
  
  
  How this will replace your function parameters
&lt;/h1&gt;

&lt;p&gt;Lets say we have the following function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function printFruits(apple, banana) {
    console.log(`we should have an ${apple} and ${banana}`)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Okay great, we expect an apple and banana. Let’s say we are using the same object as the one demonstrated in the primer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myFoods = {a: 'apple', b: 'banana', c: 'carrot', d: 'donut'}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can use &lt;code&gt;printFruits&lt;/code&gt; as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// a corresponds to apple, b corresponds to banana
printFruits(myFoods.a, myFoods.b)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  But there are a few problems here
&lt;/h2&gt;

&lt;p&gt;First, order of parameters matters. The following can happen very easily and cause hard to track bugs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// an innocent swap of variables can rain hell on our software
printFruits(myFoods.b, myFoods.a)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, what if we want &lt;code&gt;printFruits&lt;/code&gt; to be smart enough to extract the fruits it expects and discard everything else? We &lt;em&gt;could&lt;/em&gt; do the following using the &lt;code&gt;...rest&lt;/code&gt; syntax in ES6 (yes, it works for function parameters too):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function printFruits(apple, banana, ...otherFruits) {
    console.log(`we should have an ${apple} and ${banana}`)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But now we have an unused variable, which is yucky.&lt;/p&gt;

&lt;p&gt;Okay, no problem, what if we just passed in the whole object like below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function printFruits(myFoods) {
    console.log(`we should have an ${myFoods.a} and ${myFoods.b}`)
}

printFruits(myFoods)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s a little better. It solves the problems above, but introduces a new one by losing the clarity of the function signature. Before, we knew immediately that we needed to pass an apple and banana. Now we have to actually look at the function definition to see what we are trying to grab out of &lt;code&gt;myFoods&lt;/code&gt;. Not so fun when your function spans 100 lines.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This is where destructuring assignments really shines.&lt;/strong&gt; Here is what &lt;code&gt;printFruits&lt;/code&gt; looks like using destructuring assignment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function printFruits(myFoods) {
    const {a, b} = myFoods
    console.log(`we should have an ${a} and ${b}`)
}

printFruits(myFoods)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can go one step further and actually use destructuring assignments right in the function’s parameters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function printFruits({a, b}) {
    console.log(`we should have an ${a} and ${b}`)
}

printFruits(myFoods)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And if we don’t like the (purposefully vague) parameter names, we can always rename them!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function printFruits({a: apple, b: banana}) {
    console.log(`we should have an ${apple} and ${banana}`)
}

printFruits(myFoods)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As well as give a default value if we try to pull out a variable that doesn’t exist:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function printFruits({a: apple = 'default apple', b: banana = 'default banana'}) {
    console.log(`we should have an ${apple} and ${banana}`)
}

printFruits(myFoods)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  If I’m using Flow or TypeScript, who cares?
&lt;/h1&gt;

&lt;p&gt;Fair, but using this method (pun not intended) you can still free yourself from worrying about the order of parameters. Even in TypeScript, if you have two parameters that are both strings, you may accidentally swap them and be in an &lt;em&gt;even worse&lt;/em&gt; position than non Flow / TypeScript folks because you trusted the system to catch that for you.&lt;/p&gt;

&lt;p&gt;That being said, this &lt;em&gt;is&lt;/em&gt; primarily for my vanilla JS folks out there who want a little more safety in their code. We shouldn’t let a type system keep us from doing our due diligence as not every project we come across as developers will make use of Flow or TypeScript.&lt;/p&gt;

&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;I hope this helps shine some light on the practical benefits on destructuring assignment in JavaScript. There are plenty more applications, but this one I found to be one of the most common. Let me know your thoughts in the comments section!&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>A Better Way to Structure React Projects</title>
      <dc:creator>Kris Guzman</dc:creator>
      <pubDate>Wed, 02 Dec 2020 14:56:13 +0000</pubDate>
      <link>https://forem.com/krisguzman_dev/a-better-way-to-structure-react-projects-96a</link>
      <guid>https://forem.com/krisguzman_dev/a-better-way-to-structure-react-projects-96a</guid>
      <description>&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F2880%2F1%2AIxNR_wwKH11YYmZTg7en6Q.jpeg" class="article-body-image-wrapper"&gt;&lt;img alt="Image for post" src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F2880%2F1%2AIxNR_wwKH11YYmZTg7en6Q.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First off, if you don’t know what atomic design is, I’ll give a brief primer below but I suggest you go to &lt;a href="http://atomicdesign.bradfrost.com/chapter-2/" rel="noopener noreferrer"&gt;Brad Frost’s website&lt;/a&gt; and check it out.&lt;/p&gt;

&lt;p&gt;Atomic design is Brad Frost’s methodology for building design systems. The idea is that we can take the basic building blocks of living things and give our UI a hierarchical structure based on it.&lt;/p&gt;

&lt;p&gt;Brad Frost defines five main stages of UI components:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Atoms&lt;/li&gt;
&lt;li&gt; Molecules&lt;/li&gt;
&lt;li&gt; Organisms&lt;/li&gt;
&lt;li&gt; Templates&lt;/li&gt;
&lt;li&gt; Pages&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Atoms&lt;/em&gt; are the simplest form of UI, consisting of things like headers, labels, input fields, buttons, etc.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Molecules&lt;/em&gt; are a combination of atoms that form more complex pieces of our UI, such as a search field with a submit button.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Organisms&lt;/em&gt; build on top of molecules and orchestrate larger parts of the UI. This can include a list of products, a header, forms, etc. Organisms can even include other organisms.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Templates&lt;/em&gt; are where our pages start to come together, giving context to all of our organisms and molecules by giving them a unified purpose. For example, a template for a contact page will have organisms for headers and forms, and molecules for text fields and navigation bars.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Pages&lt;/em&gt;&lt;strong&gt;,&lt;/strong&gt; as the name implies, is our final page with all its content. The difference between pages and templates is that templates don’t provide any content.&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Goal of This Article
&lt;/h1&gt;

&lt;p&gt;I want to present a way to apply atomic design in your development workflow with the goal of making your code and project structure more &lt;em&gt;maintainable, scalable, and intuitive.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Additionally, atomic design is a framework that can help bridge the communication gap between development and design. It is important that developers understand it so they speak to designers in a unified language.&lt;/p&gt;

&lt;p&gt;When components are appropriately categorized, teams will be surprised to see how much more intuitive and organized their UI systems feel. Code is more maintainable, updates and refactors are easier, and on-boarding new designers and developers becomes a more efficient process.&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Common Project Structure
&lt;/h1&gt;

&lt;p&gt;Many of you are probably familiar with the folder structure below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F910%2F1%2ANcbbbaGmiVb5yy69-lpZ3g.png" class="article-body-image-wrapper"&gt;&lt;img alt="Image for post" src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F910%2F1%2ANcbbbaGmiVb5yy69-lpZ3g.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The idea here is that we try to keep components as “dumb” and as stateless as possible, while containers orchestrate our components and act as our pages.&lt;/p&gt;

&lt;p&gt;I think we should get rid of this whole “container” vs. “component” concept for the following reasons:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;It’s not scalable.&lt;/strong&gt; We only have two buckets to dump our UI in. What happens when we have 200 components and just two categories? Exactly.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;It’s not intuitive.&lt;/strong&gt; What’s a container, really? Is it a page? Or is it just a stateful component? Where do the two meet?&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;It’s a dev concept, not a design concept.&lt;/strong&gt; How can we efficiently cooperate with designers if we are speaking a different language? Designers aren’t concerned with stateful vs. non-stateful, they are concerned with &lt;em&gt;application and relationships&lt;/em&gt;. How is the component used, and how does it relate to the rest of the UI?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  A Better Project Structure
&lt;/h1&gt;

&lt;p&gt;Why don’t we structure our project according to the stages of atomic design?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F972%2F1%2Ay27rTHhPYP_Pq-IqzXxlTw.png" class="article-body-image-wrapper"&gt;&lt;img alt="Image for post" src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F972%2F1%2Ay27rTHhPYP_Pq-IqzXxlTw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice how we put pages outside of our components folder. Intuitively, we don’t put pages in the same category as the other four stages. Pages are the final presentation, not the individual components themselves.&lt;/p&gt;

&lt;p&gt;Also, I typically create a &lt;code&gt;/forms&lt;/code&gt; folder inside the root organisms folder. Forms are super common so it’s a nice way to make your folder structure a bit more granular.&lt;/p&gt;

&lt;p&gt;So, what do we gain here by making this small adjustment? Surprisingly, a lot!&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Unified design and dev language.&lt;/strong&gt; It is much easier to collaborate with your design team now that you are using the same lingo across the board. For my devs using storybook out there, this is even more beneficial.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Scalable folder structure.&lt;/strong&gt; We now have refined categories for our components. It is much easier to keep our UI organized even if we have 200+ components.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Minimal project context needed.&lt;/strong&gt; Normally, a new developer needs to have a good amount of context on a project in order to find components they need. With atomic design, the language and structure are more universal, so it is much easier to say: “Well, a header is an organism, so let me check the organism folder.”&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Cleaner code.&lt;/strong&gt;  How, you ask? Well, atomic design forces you to better understand the relationship between your components. Even if you start with a big, messy, multi-functional component, refactoring is a breeze when you start thinking: “OK, where do I see organisms, molecules, atoms, etc.”&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What’s Next?
&lt;/h1&gt;

&lt;p&gt;Congrats, you have a rock-solid folder structure for your next UI project. Is that all?&lt;/p&gt;

&lt;p&gt;Let’s fast-forward a couple of weeks. You have a few atoms, a few molecules, life is good, you’re thinking: “This is working out great! Kris isn’t so dumb after all!”&lt;/p&gt;

&lt;p&gt;But then you hit a roadblock… You are building a complex component and aren’t sure whether it’s an organism or a molecule. Can molecules have state? When does a molecule become an organism? For that matter, where is the line between an organism and a template? A template and a page?&lt;/p&gt;

&lt;p&gt;The lines between stages can get fuzzy in practice, so in part 2, we will take a look into how we can define these lines in a React project.&lt;/p&gt;

&lt;p&gt;That’s all for this part, thanks for reading!&lt;/p&gt;

</description>
      <category>react</category>
      <category>architecture</category>
      <category>design</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>JS 101: Classes in Plain JavaScript</title>
      <dc:creator>Kris Guzman</dc:creator>
      <pubDate>Mon, 30 Nov 2020 10:47:36 +0000</pubDate>
      <link>https://forem.com/krisguzman_dev/js-101-implementing-classes-from-scratch-10n7</link>
      <guid>https://forem.com/krisguzman_dev/js-101-implementing-classes-from-scratch-10n7</guid>
      <description>&lt;p&gt;&lt;a href="https://dev.to/krisguzman_dev/js-101-implementing-the-new-keyword-5h1j"&gt;In my last article&lt;/a&gt;, I talked about how to implement the &lt;code&gt;new&lt;/code&gt; keyword from scratch. Now we are going to take it a step further and re-implement a basic version of the somewhat controversial class syntax introduced in JavaScript. Why is it controversial, you might ask?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Rectangle {
  constructor(width, height) {
    this.width = width
    this.height = height
  }
  size() {
    console.log(`${this.width} x ${this.height}`)
  }
}
class Square extends Rectangle {
  constructor(scale, width, height) {
    super(width, height)
    this.scale = scale
  }
  size() {
    console.log(`${this.width}px wide and ${this.height}px tall`)
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looks pretty straightforward, right? I agree. However, there is one thing wrong with all of this...&lt;/p&gt;

&lt;h3&gt;
  
  
  The Problem with JS Classes
&lt;/h3&gt;

&lt;p&gt;The problem with classes is that... well... JavaScript doesn't have classes! It's a language based on  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain"&gt;prototypal inheritance&lt;/a&gt; , not classical inheritance.&lt;/p&gt;

&lt;p&gt;It's like trying to put a dress on a bear. Sure it will look less scary, but it doesn't change what's under the dress. &lt;/p&gt;

&lt;p&gt;Don't be the guy or gal who uses classes thinking it works exactly like classes in Java or Python. Impress your hiring interviewer by understanding what's underneath! JavaScript classes I mean, not the bear with the dress.&lt;/p&gt;

&lt;h3&gt;
  
  
  Steps to implement classes in JavaScript
&lt;/h3&gt;

&lt;p&gt;Let's implement our example above in plain old JavaScript without the syntax sugar. Here's what we will have to do:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create our &lt;code&gt;Rectangle&lt;/code&gt; constructor function with &lt;code&gt;width&lt;/code&gt;, &lt;code&gt;height&lt;/code&gt;, and &lt;code&gt;size&lt;/code&gt; attached to &lt;code&gt;this&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Create a second constructor function called &lt;code&gt;Square&lt;/code&gt;, which will call our &lt;code&gt;Rectangle&lt;/code&gt; function to initialize parameters (this is the &lt;code&gt;super(...params)&lt;/code&gt; line). It will also have a new member called &lt;code&gt;scale&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Make sure our &lt;code&gt;Square&lt;/code&gt; "class" inherits the prototype of &lt;code&gt;Rectangle&lt;/code&gt; as well by copying the prototype of &lt;code&gt;Rectangle&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Copying the prototype of &lt;code&gt;Rectangle&lt;/code&gt; means &lt;code&gt;Square.prototype.constructor&lt;/code&gt; will be &lt;code&gt;Rectangle.prototype.constructor&lt;/code&gt; rather than the Square constructor we defined, so we must redefine the property.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Does all that make absolutely zero sense? No problem, let's go step by step with code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Create our &lt;code&gt;Rectangle&lt;/code&gt; constructor function with &lt;code&gt;petName&lt;/code&gt; and &lt;code&gt;bark&lt;/code&gt; attached to &lt;code&gt;this&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Easy enough:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Rectangle() {
 this.width = width
 this.height = height
 this.size = function() {
  console.log(`${this.width} x ${this.height}`)
 }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nothing new here, just a standard constructor function as we would do pre-class syntax days.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2
&lt;/h3&gt;

&lt;p&gt;*Create a second constructor function called &lt;code&gt;Square&lt;/code&gt;, which will call our &lt;code&gt;Rectangle&lt;/code&gt; function to initialize parameters (this is the &lt;code&gt;super(...params)&lt;/code&gt; line). *&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Square(scale, width, height) {
 Rectangle.call(this, width, height)
 this.scale = scale
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is where the confusion often begins. Why did we call &lt;code&gt;Rectangle.call(this, width, height)&lt;/code&gt;? This basically says "call our Rectangle constructor function, but use the &lt;code&gt;this&lt;/code&gt; parameter we pass in rather than the one in Rectangle. Also, pass in any other parameters expected by Rectangle." This is essentially the same is running &lt;code&gt;super(width, height)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Our other member, &lt;code&gt;scale&lt;/code&gt;, is exclusive to our Square class, so we assign it after we run the parent constructor function.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Make sure our &lt;code&gt;Square&lt;/code&gt; "class" inherits the prototype of &lt;code&gt;Rectangle&lt;/code&gt; as well by copying the prototype of &lt;code&gt;Rectangle&lt;/code&gt;&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Square.prototype = Object.create(Rectangle.prototype)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What the hell is this? Great question!&lt;/p&gt;

&lt;p&gt;In plain english, this basically says "I want the prototype of Square to be a copy of the prototype of Rectangle".&lt;/p&gt;

&lt;p&gt;Okay, so you may be wondering now, &lt;strong&gt;why&lt;/strong&gt;  do we want to do this? Take the following example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Rectangle.prototype.getArea = function() {
  return this.width * this.height
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we define the &lt;code&gt;getArea&lt;/code&gt; method on the prototype of &lt;code&gt;Rectangle&lt;/code&gt;, but forget to do step #3, our &lt;code&gt;Square&lt;/code&gt; won't have access to this method. Why would we define methods on prototypes? You'll have to follow me and wait for the next article to explain that one!&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Copying the prototype of &lt;code&gt;Rectangle&lt;/code&gt; means &lt;code&gt;Square.prototype.constructor&lt;/code&gt; will be &lt;code&gt;Rectangle.prototype.constructor&lt;/code&gt; rather than the Square constructor we defined, so we must redefine the property.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Our last step is an odd one, but basically if ran:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Square.prototype.constructor.name === Rectangle.prototype.constructor.name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we would see that they are equal, which isn't what we want. We want our &lt;code&gt;Square&lt;/code&gt; to point to the &lt;code&gt;Square&lt;/code&gt; constructor function, but because we literally copied the whole &lt;code&gt;Rectangle&lt;/code&gt; prototype, we lost that connection.&lt;/p&gt;

&lt;p&gt;So let's fix that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Object.defineProperty(Square.prototype, 'constructor', {
 value: Rectangle,
 enumerable: false, // prevents this property from showing up for-in loop statements
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 5: Profit
&lt;/h3&gt;

&lt;p&gt;Phew! That wasn't super straightforward. Here is our final implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Rectangle() {
 this.width = width
 this.height = height
 this.size = function() {
  console.log(`${this.width} x ${this.height}`)
 }
}

function Square(scale, width, height) {
 Rectangle.call(this, width, height)
 this.scale = scale
}

Square.prototype = Object.create(Rectangle.prototype)

Object.defineProperty(Square.prototype, 'constructor', {
 value: Rectangle,
 enumerable: false, 
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might be thinking, "okay... nope I'm just going to use the class syntax", which is exactly why it was introduced in the first place!&lt;/p&gt;

&lt;p&gt;The point of this article isn't to say "hey, classes aren't real so don't use them". The point is to understand what is really happening behind the scenes so you can make the educated decision between using class syntax or functions. &lt;/p&gt;

&lt;h3&gt;
  
  
  Coming Up Next on December 2nd...
&lt;/h3&gt;

&lt;p&gt;We saw how classes are implemented in plain JavaScript, but what are the pros and cons of using the class syntax? Are there performance implications? &lt;/p&gt;

&lt;p&gt;Follow me to find out! Or you can just google it I guess...&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>JS 101: Implementing the "new" keyword</title>
      <dc:creator>Kris Guzman</dc:creator>
      <pubDate>Sun, 29 Nov 2020 12:49:23 +0000</pubDate>
      <link>https://forem.com/krisguzman_dev/js-101-implementing-the-new-keyword-5h1j</link>
      <guid>https://forem.com/krisguzman_dev/js-101-implementing-the-new-keyword-5h1j</guid>
      <description>&lt;p&gt;Because there is no real concept of classes in JavaScript, it helps to understand what some of these classical keywords are really doing under the hood.&lt;/p&gt;

&lt;p&gt;We're going to create a simplified version of the "new" keyword in JavaScript. For example, using the new keyword to instantiate an object we would do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const dog = new Dog()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;but we are going to do something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sparky = newObject(Dog, 'Sparky', 3)
const spot = newObject(Dog, 'Spot', 6)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What the "new" Keyword Does
&lt;/h2&gt;

&lt;p&gt;To understand the "new" keyword, it's important to understand constructor functions. Constructor functions in JS are just regular ole functions that are responsible for initialization. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// the upper case function name is just a standard practice, not necessarily required
function Dog(petName, age) {
   this.petName = petName
   this.age = age
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So here are the steps that the "new" keyword does in the background:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create an empty object&lt;/li&gt;
&lt;li&gt;Assign the prototype of the empty object to the prototype of the constructor function&lt;/li&gt;
&lt;li&gt;Run the constructor function using the "this" context of the new object&lt;/li&gt;
&lt;li&gt;If the constructor returns an object, return that, otherwise, return "this"&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's start off by defining a function called &lt;code&gt;newObject&lt;/code&gt; that will replace the new keyword.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* 
   We will need the constructor function, and all of the constructor
   parameters. Using the handy spread operator here.
*/
function newObject(constructor, ...params) {
 // we will fill this out in the following steps
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 1: Create an empty object
&lt;/h3&gt;

&lt;p&gt;Easy enough. Let's do that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function newObject(constructor, ...params) {
 function d() {}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Assign the prototype of the empty object to the prototype of the constructor function
&lt;/h3&gt;

&lt;p&gt;A little trickier, but &lt;code&gt;Object&lt;/code&gt; has a handy function called &lt;code&gt;setPrototypeOf&lt;/code&gt;. Let's use it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function newObject(constructor, ...params) {
 function d() {}
 Object.setPrototypeOf(d, constructor.prototype)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not bad so far!&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Run the constructor function using the "this" context of the new object
&lt;/h3&gt;

&lt;p&gt;Alrighty, this is probably the most complicated part for new JavaScript programmers. There is a function that all objects have called &lt;code&gt;call&lt;/code&gt; and &lt;code&gt;apply&lt;/code&gt;. They run a particular function where the &lt;code&gt;this&lt;/code&gt; parameter of that function is the one we pass. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Dog(petName) {

   this.petName = petName
}

/* 
   we pass "this", so the "this" in "this.petName" refers to the one 
   we passed in.  
*/
Dog.call(this, 'Harold')

/* 
   if we want to pass an array of parameters, we can use the multi- 
   parameter equivalent of the "call" function.
*/
Dog.apply(this, ['Harold', 'James', 'Clark'])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Okay, so now that we know how to use &lt;code&gt;call&lt;/code&gt; / &lt;code&gt;apply&lt;/code&gt;, which one do you think we should use to handle step number 3? Remember, a constructor function can have any number of parameters.&lt;/p&gt;

&lt;p&gt;Ready? Here it is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function newObject(constructor, ...params) {
 function d() {}
 Object.setPrototypeOf(d, constructor.prototype)
// apply expects an array-like second parameter, which is why
// we spread it in an array
 constructor.apply(d, [...params])
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: If the constructor returns an object, return that, otherwise, return "this"
&lt;/h3&gt;

&lt;p&gt;To finish off our &lt;code&gt;newObject&lt;/code&gt; function, we add a quick conditional check to see if the constructor function returns an object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function newObject(constructor, ...params) {
 function d() {}
 Object.setPrototypeOf(d, constructor.prototype)
 const obj = constructor.apply(d, [...params])
 if(typeof obj === 'object') return obj
 return d
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that &lt;code&gt;null&lt;/code&gt; is technically an object, so if a constructor returns null,  that will be returned by our instantiation function.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Profit
&lt;/h3&gt;

&lt;p&gt;Let's put everything together and give our function a whirl!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// our fancy new function
function newObject(constructor, ...params) {
    function d() {}
  Object.setPrototypeOf(d, constructor.prototype)
  const obj = constructor.apply(d, [...params])
  if(typeof obj === 'object') return obj
  return d
}

// an example constructor function
function Dog(petName, age) {
   this.petName = petName
   this.age = age
   this.bark = function() {
      console.log(`${this.petName} is ${this.age} years old`)
   }
}

const bill = newObject(Dog, 'Bill', 8)
const sam = newObject(Dog, 'Sam', 2)

dog.bark() // prints: Bill is 8 years old
dog2.bark() // prints: Sam is 2 years old
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Now that we have seen how the new keyword works, we can appreciate how handy it is that all we have to do is type &lt;code&gt;const dog = new Dog()&lt;/code&gt; to get the same result.&lt;/p&gt;

&lt;h3&gt;
  
  
  FUN FACT!
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;new&lt;/code&gt; keyword will run the given function regardless of whether you type &lt;code&gt;new Dog()&lt;/code&gt; or &lt;code&gt;new Dog&lt;/code&gt;, so technically you don't need to do the former, but for the sake of everyone's sanity it's probably better to just go with the former option.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
