<?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 Diego Molina on Medium]]></title>
        <description><![CDATA[Stories by Diego Molina on Medium]]></description>
        <link>https://medium.com/@diego-molina?source=rss-85de18621e4c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*IiNzuk2aa1uSWcrUkZFQOQ.jpeg</url>
            <title>Stories by Diego Molina on Medium</title>
            <link>https://medium.com/@diego-molina?source=rss-85de18621e4c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 13:21:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@diego-molina/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[Interesting Aspects of JavaScript]]></title>
            <link>https://medium.com/swlh/interesting-aspects-of-javascript-aa106296673e?source=rss-85de18621e4c------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa106296673e</guid>
            <category><![CDATA[closure]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[js]]></category>
            <category><![CDATA[event-loop]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Diego Molina]]></dc:creator>
            <pubDate>Thu, 07 Jan 2021 23:12:22 GMT</pubDate>
            <atom:updated>2025-04-02T13:09:56.599Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*nNXz9sl50h2ppnwQUH75mA.jpeg" /><figcaption><a href="https://www.freepik.com/vectors/technology">Technology vector created by vectorjuice</a></figcaption></figure><p>Let me start saying that I love discovering new things about JavaScript. Especially because I do not know some of its features. This taught to me to go through a process of learning, and understanding this programming language and part of its core.</p><p>A while ago I had a nice and interesting interview. The first question the interviewer asked me, I failed. Fun fact: I answered with full confidence in my own knowledge. I actually had a good understanding but not enough to give a good and right answer. So after this event — This is something I always do when I fail an interview — I grabbed some books, found some articles, checked some docs, and I studied. Having said this, I’d like to share some of the things I found interesting about JavaScript that I didn’t manage well.</p><h3><strong>The Scope</strong></h3><p>When you create a function in JavaScript it has some properties, one of those properties is the [[scope]] and it is actually called <strong>lexical scope</strong>. The scope collects and maintains a searchable list of identifiers (variables) that can be accessed.</p><blockquote>The internal [[scope]] properties contains a collection of <strong>objects </strong>representing the <strong>scope</strong> in which the function was created. This collections is called the <strong>function’s scope chain</strong> and it determines the data that the function can access — Nicholas C. Zakas, High Performance JavaScript.</blockquote><p>Why is this important to know and understand? Because you can only access a variable from where you have declared it and depending on how nested your scope is, it might affect the performance of your code if you’re trying to reach a variable from an inner function to an outer scope.</p><p>Along with this scope, when a function is actually called, it creates an object called <strong>execution context, </strong>which contains:</p><ul><li>Global object — Reference of the Global Object.</li><li>Special object.</li></ul><p>The execute context has its own scope chain for the process of the <strong>identifier resolution</strong> and the values from the executing context are copied in the order they appear. Two distinct actions are taken for a variable assignment: first, the compiler declares a variable (if not previously declared) in the current Scope, and second, when executing, the engine looks up the variable in Scope and assigns to it, if found — Kyle Simpson, Scope and Closure.</p><blockquote>A <em>variable can be used </em><strong><em>before</em></strong><em> been declared and hold any other value; </em>this is thanks to something called <strong>Hoisting.</strong></blockquote><blockquote>Each time a variable is <strong>encountering</strong> during the <strong>function’s execution, </strong>the process of <strong>identifier resolution </strong>takes place to <strong>determine </strong>where to retrieve or store the data. During this process, the execution context’s scope chain is searched for an identifier with the same name. the search begins at the front of the scope chain, in the execution functions’s activation object. <strong>if found the variable with the specified identifier is used; if not, the search continue on to the next object in the scope chain. </strong>— Nicholas C. Zakas, High Performance JavaScript.</blockquote><p>From the above quote, I think it is best to declare and keep variables within the scope of the function that is going to access these variables. Example, with a stateless React component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0fd4a4c1776e463c88a4091c0b78c9bd/href">https://medium.com/media/0fd4a4c1776e463c88a4091c0b78c9bd/href</a></iframe><blockquote>A good rule of thumb is to always store out-scope values in local variables if they are used more than once within a function — Nicholas C. Zakas, High Performance JavaScript.</blockquote><p>As an example for that side note, you can do something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e11a32bb3e192bd9d260d7981b4131d9/href">https://medium.com/media/e11a32bb3e192bd9d260d7981b4131d9/href</a></iframe><p>Accessing a variable from an outer scope might indeed affect the performance (which is not easily perceived nowadays due to the power of the contemporary computers) and it can lead to some undesirable effects. Scopes are nested inside other scopes. So, if a variable cannot be found in the immediate scope, the engine consults the next outer containing… The same identifier name can be specified at multiple layers of nested scope, which is called “<em>shadowing</em>” ( the inner identifier “shadows” the outer identifier)… — Kyle Simpson, Scope and Closure.</p><h3>Hoisting</h3><p>JavaScript is a <strong>compiled </strong>language. Yes, it is compiled before being interpreted. Part of the compilation phase is to find all the variables and functions and then execute the code. The variables can be assigned values before being declared and this will work. This is because the compiler first took the declared variables and put them into the scope and then the code is executed.</p><blockquote>Only the declarations themselves are hoisted, while any assignments or other executable logic are left <strong>in place</strong>. If hoisting were to re-arrange the executable logic of our code, that could wreak havoc. — Kyle Simpson, Scope and Closure.</blockquote><h3>The Event Loop</h3><p>The event loop is a concurrency modal that is in charge of keeping tasks, processing events, and executing the code. How the async/await functions, and multiple calls to an async/away functions work at the “<em>same time” </em>it is part of how the event loop works (Actually the async events are <strong>sync</strong> events 💥)<em>.</em>The event loop is like the heart of JavaScript. Execute chunks of your code in a <strong>single thread</strong> over time.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FcCOL7MC4Pl0%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DcCOL7MC4Pl0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FcCOL7MC4Pl0%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3a96017164c40a05618a82e11549d21/href">https://medium.com/media/f3a96017164c40a05618a82e11549d21/href</a></iframe><p>With the implementation of <strong>async/await</strong> there’s a new understanding of how the event loop works with async/await. Reading about this I found a new concept: <strong>Microtasks</strong>. Microtasks are usually scheduled for things that should happen straight after the currently executing script, such as reacting to a batch of actions, or to make something async without taking the penalty of a whole new task. The microtask queue is processed after callbacks as long as no other JavaScript is mid-execution, and at the end of each task. Any additional microtasks queued during microtasks are added to the end of the queue and also processed. Microtasks include mutation observer callbacks, and as in the above example, promise callbacks — Jake Archibald.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*LWYyP6VdxlbeN6vLKdhGhg.jpeg" /><figcaption>Image extracted from: <a href="https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/">https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/</a></figcaption></figure><h3>Closure</h3><p>Closure is a technique that allows you to return another function inside a function. You can “store” and persist the data from the scope of the parent functions and access to it from the inner function. This can be explained in a different way such as a function can access data that is outside of its local scope — Nicholas C. Zakas, High Performance JavaScript.</p><p>Something important to recall is when a function is called, the execution context is created, therefore a scope chain is created. When the inner function is called, an activation object is created. This object will contain any variable in the parent scope as the inner function; as both have a reference, the parent function scope cannot be destroyed because the inner function has its reference.</p><h3>The Comma Operator</h3><p>Many years ago it was very popular to see, and even nowadays, variables declaration like this:</p><p>var a, b, c, d;</p><p>The argument for some developers was that this is a shortened way of declaring variables and indeed it is. But in JavaScript the comma has a “behavior.” When you declare variables using the comma operator, you are actually returning the last variable. You can have some code like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a9dc29b6581b59cc22bc66c02c46699/href">https://medium.com/media/0a9dc29b6581b59cc22bc66c02c46699/href</a></iframe><h3>Unary Operands</h3><p>The unary operands are basic on each language. In JavaScript you can make cool — weird sometimes — things. Basically the unary operan either is plus or minus, when evaluating, it tries to convert its operant into a number that it isn’t already. You can use it as a shorthand for some built-in methods.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c7fa1002618b4f5dcd9b95c95d3e6fb/href">https://medium.com/media/9c7fa1002618b4f5dcd9b95c95d3e6fb/href</a></iframe><p>This is just a very small review of some interesting aspects of JavaScript. I really hope you enjoyed it 😃 and thanks for your time reading it.</p><p>Thanks to J. Drake for helping me review this article. ❤️</p><p>Cheers!</p><p><strong><em>References</em>:</strong><br><a href="https://www.amazon.com/_/dp/1449335586?tag=oreilly20-20">Scope &amp; Closures — Kyle Simpson</a><br><a href="https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/">Tasks, microtasks, queues and schedules</a><br><a href="https://www.amazon.com/_/dp/1491904224?tag=oreilly20-20">Async &amp; Performance — Kyle Simpson</a><br><a href="https://www.amazon.com/High-Performance-JavaScript-Application-Interfaces/dp/059680279X">High Performance JavaScript — Nicholas C. Zakas</a><br><a href="http://www.ecma-international.org/ecma-262/7.0/#sec-execution-contexts">Execution Context</a><br><a href="http://www.ecma-international.org/ecma-262/7.0/#sec-comma-operator-runtime-semantics-evaluation">Comma Operator</a><br><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop">Event Loop</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa106296673e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/interesting-aspects-of-javascript-aa106296673e">Interesting Aspects of JavaScript</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Applying Atom Design Methodology and Hexagonal Architecture Using React — Part II]]></title>
            <link>https://javascript.plainenglish.io/applying-atom-design-methodology-and-hexagonal-architecture-using-react-part-ii-c51d0d7ece9?source=rss-85de18621e4c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c51d0d7ece9</guid>
            <category><![CDATA[design]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Diego Molina]]></dc:creator>
            <pubDate>Sun, 28 Jun 2020 01:23:08 GMT</pubDate>
            <atom:updated>2021-01-14T21:03:46.027Z</atom:updated>
            <content:encoded><![CDATA[<h3>Applying Atom Design Methodology and Hexagonal Architecture Using React — Part II</h3><h4>This is the next part of my previous article <a href="https://medium.com/javascript-in-plain-english/applying-atom-design-methodology-and-hexagonal-architecture-using-react-6dbb1863a5d5">“Applying Atom Design Methodology and Hexagonal Architecture Using React”</a>.</h4><figure><img alt="Atom Design example of Atoms, Molecules, Organisms, and Templates" src="https://cdn-images-1.medium.com/max/1024/1*NF0AXImPhODIt9M5-Mg5Lw.png" /><figcaption>I extracted this image from: <a href="http://site-backelite-wordpress-int.ppr-5-4.bkt.mobi/2016/03/atomic-design-a-promising-co-creation-method/">http://site-backelite-wordpress-int.ppr-5-4.bkt.mobi/2016/03/atomic-design-a-promising-co-creation-method/</a> — It does not belongs to me.</figcaption></figure><p>First of all, this is not something new. What I’m going to explain in here is how <strong>I</strong> applied the Atomic Design to my components and you can do the same or do it differently because what I’m expressing in here is not a standard, it’s just how I saw the folder structure within the <strong>UI Layer</strong> of the Hexagonal Architecture. This article is a personal journey and all that I’m about to discuss might be “wrong” for some of you. So, that being said, if you find something you don’t agree with, I’m very happy to hear your thoughts on the matter 😄.</p><h3>What Is Atom Design Methodology?</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FtAPkUnA2GQNVK%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fatomic-atoms-tAPkUnA2GQNVK&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2FtAPkUnA2GQNVK%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="278" frameborder="0" scrolling="no"><a href="https://medium.com/media/de1fc63bdb6b0566adea7623b963e59e/href">https://medium.com/media/de1fc63bdb6b0566adea7623b963e59e/href</a></iframe><p>Before giving you my understanding of this, I’d like you to go to this link: <a href="https://atomicdesign.bradfrost.com/chapter-2/#:~:text=Atomic%20design%20is%20atoms%2C%20molecules,parts%20at%20the%20same%20time.">atom-design-methodology</a>. This is one of the best link out of there to start with Atom Design. Nevertheless, here is a very simple explanation from myself: Atom Design divides your final mock up or prototype into smaller and reusable components, giving them specific functionalities. Each big part is composed by the smaller parts in a hierarchical manner.</p><p>Let me show you the next simple mockup to explain step by step this whole idea of components under the Atom Design Methodology.</p><blockquote><em>⚠️ The definitions of each part of the Atom Designs are going to be describes from a React development perspective.</em></blockquote><figure><img alt="Template example" src="https://cdn-images-1.medium.com/max/1024/1*Or7RQ2y3W2k3Xe8aSYJlZg.jpeg" /><figcaption>Basic mockup</figcaption></figure><h3>Templates, Organisms, Molecules, and Atoms ⚛️</h3><p>The Template is composed by all the needed <strong>Organisms, Molecules, </strong>and<strong> Atoms. </strong>Before moving forward with the concepts I’d like to make clear that this part is very important because you can also see how many containers you could need. Templates from now on will take on a new definition under the React world. I came up with something like this: A <em>Template is conceptually a representation of all the possibles containers you could have in one page or screen. Keeping in mind that containers will have all the complex logic</em>. From the above mockup I can see the next <strong>possible </strong>containers.</p><figure><img alt="Container division inside the template" src="https://cdn-images-1.medium.com/max/1024/1*mGHQ3csynReWQvgECavH9A.jpeg" /><figcaption>Possible containers that the screen/page might have.</figcaption></figure><p>Having this division of containers is very useful to identify the next components: The Organisms<strong>. </strong>The Organisms are small sections that a Template is composed with. An Organism can be composed of many <strong>Molecules </strong>or<strong> Atoms</strong> but not of other Organisms<strong>. </strong>Ideally an Organism should not have logic but there might be exceptions. If so, try to make a very simple logic, something that is part of the component and does not depend on the container logic.</p><figure><img alt="Organism division" src="https://cdn-images-1.medium.com/max/1024/1*CppMGItcsIKFnE3T6gfZFQ.jpeg" /><figcaption>All the Organisms</figcaption></figure><p>Now it’s time to see what the Molecules are. The Molecules are smaller than Organism. It can be composed of <strong>Atoms</strong>, but it doesn’t have to be<strong>. </strong>These types of components are a high level of <strong>Atoms</strong>, this is because atoms are the very basic shape of a component and must not have logic at all. From the Template that I’m using as an example, you can see one Molecule.</p><figure><img alt="Molecules on the template" src="https://cdn-images-1.medium.com/max/1024/1*fv6QYVpWNCJSI4lqmA62yA.jpeg" /><figcaption>The Molecules</figcaption></figure><p>Finally the smallest components: the Atoms. They can be anywhere and the only strict rule is that they must not have logic at all. They should be very simple components.</p><figure><img alt="All the Atoms on the Template" src="https://cdn-images-1.medium.com/max/1024/1*tqD4lPXYqKkEUpr7EodeeA.jpeg" /><figcaption>All the found atoms!</figcaption></figure><h3><strong>Building your components</strong></h3><p>Now, you might be wondering: How can I use this with React? Let’s go back to the Hexadecimal folder structure from the <a href="https://medium.com/javascript-in-plain-english/applying-atom-design-methodology-and-hexagonal-architecture-using-react-6dbb1863a5d5">previous article </a>and add the folders you might need, thinking of components as if they were part of the Atom Design. The folder structure should be something like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f9c68ed1a480a41d6c48c612e40ec6d/href">https://medium.com/media/8f9c68ed1a480a41d6c48c612e40ec6d/href</a></iframe><p>As you already know which part of the Template are Organisms, Molecules and Atoms, you can now start writing the components starting from the smallest one to the whole page. In the next image, I’m showing what the Atoms could be.</p><figure><img alt="List of the possible Atoms Components" src="https://cdn-images-1.medium.com/max/1024/1*c6959ydj99DpyS-H_9wBhQ.jpeg" /><figcaption>List of the possible Atoms Components</figcaption></figure><p>In the next example I have the components in one file, but they should be in their respective files. Also, the components that I did are just three from the above image, I don’t think you need more to get the idea.</p><blockquote><em>Note: Remember always use PropTypes and the defaultProps 😜</em></blockquote><p><em>(I’m pretending making use of </em><a href="https://styled-components.com/"><em>Styled Components</em></a><em> 💅 )</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f47b73e660f19ea9f5e32b8dc4c236d1/href">https://medium.com/media/f47b73e660f19ea9f5e32b8dc4c236d1/href</a></iframe><p>As you can see, these components are tiny and basic. They just paint the UI and have no logic. Now the Molecules. The Molecule in this case is just a List component which contains Item components. Something very important to consider sometimes, as Molecules are composed by Atoms, the Molecule component will, in some cases, inherit the props from the Atoms it is composed with. Below you can see an example of this situation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fad4fc58672bcf4f29aa4dfd50c3d1a5/href">https://medium.com/media/fad4fc58672bcf4f29aa4dfd50c3d1a5/href</a></iframe><p>⚠️ Organism won’t be named as general components, this means they won’t be named as: Button , Alert or Item . Instead they should be something related to the context but not to the screen. Think of the left Organism from the Template as a list of songs from an album, so this component might be named as ListSongs ; It’s a little bit <strong>general</strong> ( List ) but at the same time <strong>specific </strong>( Songs<strong> </strong>).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59dde2c52af9a466c4efa81ce7542e92/href">https://medium.com/media/59dde2c52af9a466c4efa81ce7542e92/href</a></iframe><p>In the end this Organism is going to part of a single container as I defined in one of the images from above. This and the rest of the containers will only render their own components — Organisms, Molecules and Atoms — preventing extra rendering when it is not needed. Also, all of these containers are going to be part of a single screen (<em>Template</em>) and they can be reused as well on other screens.</p><p>I hope that bringing this idea to your attention has been useful. Thanks for your time and for reading, and any feedback is very welcome! 😃.</p><p>Thanks to J. Drake, my husband, for helping me review this article. ❤️</p><p>Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c51d0d7ece9" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/applying-atom-design-methodology-and-hexagonal-architecture-using-react-part-ii-c51d0d7ece9">Applying Atom Design Methodology and Hexagonal Architecture Using React — Part II</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Applying Atom Design Methodologies with React]]></title>
            <link>https://javascript.plainenglish.io/applying-atom-design-methodology-and-hexagonal-architecture-using-react-6dbb1863a5d5?source=rss-85de18621e4c------2</link>
            <guid isPermaLink="false">https://medium.com/p/6dbb1863a5d5</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[redux]]></category>
            <dc:creator><![CDATA[Diego Molina]]></dc:creator>
            <pubDate>Mon, 01 Jun 2020 04:44:12 GMT</pubDate>
            <atom:updated>2025-04-02T13:08:07.312Z</atom:updated>
            <content:encoded><![CDATA[<h3>Applying Atom Design Methodology and Hexagonal Architecture Using React</h3><h4>First of all, this is an opinion article due to the nature of the content within. It’s a kind of “try-and-see-how-it-works” type of situation. What I did was take some of the principles of the Atom Design Methodology and the Hexagonal Architecture and apply them to a React project. Therefore, this is an article showcasing my adventures in doing this.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tZeyfiZe1VEt_R1mOwjVOw.jpeg" /></figure><p>⚠️ <strong>Important:</strong></p><ul><li>Read the comments I left on the code. They might be useful to understand <em>why </em>I did some things. Also in the comments I leave the path of where the files will reside.</li><li>This is just a way to structure your project folder and files. You can even use something simpler than this.</li></ul><p>⚠️ <strong>Note:</strong></p><ul><li>I’m going to divide this article into two parts: The Hexagonal Architecture and the Atom Design Methodology.</li></ul><h3>How Everything Began</h3><p>A few weeks ago I read an article from Netflix about <a href="https://netflixtechblog.com/ready-for-changes-with-hexagonal-architecture-b315ec967749">Hexagonal Architecture</a>. It was really interesting how this architecture separates everything from the domain, having different layers where each of them has their own responsibilities avoiding coercion between different parts of the software. Days before reading this article I was asked by the architect of a new project I’m working on to apply this architecture to a React project. In the beginning I struggled a lot because this is not my area and I have a lack of knowledge related to architectures. As I was reading, in addition to the architect explanation of some of the concepts of this architecture, I could have some kind of mental model of how this could work in a frontend project using React.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FCbSGut2wzWKZy%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Ffunny-work-architect-CbSGut2wzWKZy&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FCbSGut2wzWKZy%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="240" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc5e464ad8dc185c638733de3ede143e/href">https://medium.com/media/fc5e464ad8dc185c638733de3ede143e/href</a></iframe><h3>In The End, Everything is About Concepts</h3><p>You can take a concept and apply it or spark an epiphany from it. That was what I did. From the hexagonal architecture I took the next concepts:</p><blockquote>The idea of Hexagonal Architecture is to put inputs and outputs at the edges of our design. Business logic should not depend on whether we expose a REST or a GraphQL API, and it should not depend on where we get data from — a database, a microservice API exposed via gRPC or REST, or just a simple CSV file. — <strong>Netflix</strong></blockquote><ul><li><strong>The domain layer</strong>: The business logic. Knowing that this is the core of the application where the <strong>entities </strong>and the rules validations reside and it must not know or be related to any external layers, I could see, in a vague way, what it could be the domain of my application: Redux. Redux, as a centralized state and logic of my application, it could be the core of my domain layer. The application can have entities — user, post, credits, comments, and so on — and also has the state of my application. This make sense if you have worked before with Redux and treat it as a Database of entities. <em>(Remember that I’m only using the concepts or part of it.)</em></li><li><strong>The Application</strong>: This layer is represented by the use cases. It means what the final user is doing with the application or the software. In this case it would be any <strong>action — </strong>interactors in the Netflix diagram — executed from an input given by the user.</li><li><strong>The Infrastructure</strong>: This layer contains anything that will interact with external resources such as RestFul API, SOAP, gRCP calls and DB connections. For the frontend case it would be your API module calling any API or connection made to a database.</li><li><strong>The UI: </strong>The final external layer. This should be the last one because it is the last thing the user will interact with. In this case it would be the components — containers, screens, routers, etc.</li></ul><p>The hexagonal diagram that I came out with would be something like this:</p><figure><img alt="Hexagonal diagram applied to a frontend project" src="https://cdn-images-1.medium.com/max/960/1*zgxVUs-XCZDyNzJOnDAhbA.jpeg" /><figcaption>The (5-sided) Hexagonal Diagram — (sorry I wrote Sotore and it should be Store)</figcaption></figure><p>I think this looks good for being my first time doing this. Of course everything could be improved or maybe it is a bad idea to use this in a frontend project (as I said this is an opinion article 😄). The final project structure should be something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/733102c065ab60887f482a85a012f6cf/href">https://medium.com/media/733102c065ab60887f482a85a012f6cf/href</a></iframe><h3>The Hexagonal Monster! 👾</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fd3Kq5w84bzlBLVDO%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Ffrankenstein-top-100-movie-quotes-its-alive-d3Kq5w84bzlBLVDO&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fd3Kq5w84bzlBLVDO%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="243" frameborder="0" scrolling="no"><a href="https://medium.com/media/985bd497be013ae0b3976168a3e4929c/href">https://medium.com/media/985bd497be013ae0b3976168a3e4929c/href</a></iframe><h4>The Domain Layer</h4><p>The Domain Layer was the the easiest part of all of this because it contains only the state of the application and the entities. Below is how the code looks like. <em>(I’m using one file for practical case example.)</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aec2f15a513a6b991f450bf80cf05813/href">https://medium.com/media/aec2f15a513a6b991f450bf80cf05813/href</a></iframe><h4>The Application Layer</h4><p>Here I added all the actions to interact with my application and then interact with some services in the infrastructure layer. To create the actions I use createSlice from Redux Toolkit. Redux Toolkit allows to reduce the amount of code you could have done a time ago. One of the cool features is that it makes use of <a href="https://github.com/immerjs/immer">Immer</a> — which I’ve been using for a year — Immer is a fast library to work with immutable objects. It make use of the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy">Proxy object</a>.</p><p>⚠️ <strong>Note: </strong>If you create an action using createAction don’t pass it right away to the reducer object. As the createSlice function assigns the state and the payload to the given functions, the created functions with createAction will receive the state as it was the actual payload. This might cause some undesired behavior. To avoid this, add it to the final action object making use of the spread operator.</p><p>As you could see in the code, I like to keep the functions related to the Sagas together and to keep the rest of the actions above them.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40226973b272c8e2ad84c337db0eb500/href">https://medium.com/media/40226973b272c8e2ad84c337db0eb500/href</a></iframe><p>Now the configuration of the store. This is a very clean and simple configuration with the basic things you might need for a project. I recommend that you read the API doc from <a href="https://redux-toolkit.js.org/api/configureStore">Redux toolkit</a> as this code is using some of the functions from that library. I also really recommend that you remove your old code and start using the functions from Redux toolkit.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/286cae200b689373b2fd879a11bd47aa/href">https://medium.com/media/286cae200b689373b2fd879a11bd47aa/href</a></iframe><p>Before continuing with the Redux-Saga configuration, I’m gonna show you some tests. I’m not an expert writing tests and I am still learning, so If you find any mistake or you know a better way to do them, please, let me know by posting the answer below 😃. For me the tests must be simple and I just need to test the final <strong>expected</strong> output from a given input. So, from the actions, I see the next things that I should test.</p><ul><li>If the action returns the right object.</li><li>If the action called returns the initial state from the store.</li><li>The action should be called with a given payload.</li></ul><p>Using the code from above as an example, I have two actions: <strong>fetchUsers </strong>and <strong>fetchUsersSuccess.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad006fe98b9865d00ceab3353cedafd8/href">https://medium.com/media/ad006fe98b9865d00ceab3353cedafd8/href</a></iframe><p>On this test I’m taking advantage of the nice function toMatchSnapshot from <a href="https://jestjs.io/docs/en/getting-started">Jest</a>.</p><h4>The Infrastructure Layer</h4><p>Remember in this layer we will have all the modules and services needed to communicate with external resources. The first thing I did was create an abstraction of all the commonly-used HTTP verbs method (POST, PUT, DELETE, GET) You can use any library to do this. In the next code I made use of Axios. I loooove Axios 😍, it comes already with some security configuration that I don’t have to worry about most of the time and it has a huge community behind it. The code below could be improved to cancel the request and to add a more personalized configuration, but for a practical example this one is ok.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13d98355053d3d545544df37c2fe55d9/href">https://medium.com/media/13d98355053d3d545544df37c2fe55d9/href</a></iframe><p>The next code would be how I tested this code form above. I think I needed to test the successful and failure responses of each verbs from my API module implementation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d6082525aec49eab1afb1826d3525ea5/href">https://medium.com/media/d6082525aec49eab1afb1826d3525ea5/href</a></iframe><p>It’s time to show my Redux-Saga configuration. For those who doesn’t know about <a href="https://redux-saga.js.org/">Redux-Saga</a>, this is a great library to manage the side effects of your application. One of the cool things about Saga is that it makes use of function generators, this mean that you can pause your Promises, avoid callback hells, and you can make multiple calls in parallel as well. It’s well integrated with Redux making use of a middleware. If you did pay attention to the store configuration, the saga middleware is already there. What I usually use to mount all my Sagas is to make use of one of the following <a href="https://redux-saga.js.org/docs/advanced/RootSaga.html">Saga patterns</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c92087cc27ab7ea28a1ab1c3f4676598/href">https://medium.com/media/c92087cc27ab7ea28a1ab1c3f4676598/href</a></iframe><p>And then I have a single saga file that will interact only with the corresponding actions. Following the example from above, my actions are in the user folder, there for my saga will also be in the user folder and it will contain only requests from those actions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d6f167e47671dc32c483821fc7517d8/href">https://medium.com/media/5d6f167e47671dc32c483821fc7517d8/href</a></iframe><p>I think that keeping the Sagas this way makes it easy to test and to maintain. What I test from saga is:</p><ul><li>If the forked saga is listening to the given action.</li><li>If the effect calls the saga and this saga returns a successful or failure response.</li></ul><p>With those points in mind, the code I came up with using the example from above it would be something like the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b22b87fe061c798d958e1f25f2bb14f/href">https://medium.com/media/7b22b87fe061c798d958e1f25f2bb14f/href</a></iframe><h4>Bonus Track 😋</h4><p>An extra mention about Sagas. There’s another pattern that you could use when working with Sagas. This is something you might not find on the internet because I did it for a company I was working for. This pattern allows you to <em>inject</em> the Sagas before your container is mounted. This way, if you have a lot of Sagas, the starting point of your project wont be slow.</p><p>First of all, I needed to made use of the context from Redux. (You can make your own from React context API.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e806c5b9e46a07fef8f16dfae96ece32/href">https://medium.com/media/e806c5b9e46a07fef8f16dfae96ece32/href</a></iframe><p>As you can see I’m passing as parameters the <strong>injectedSagas, tasks</strong>, and the <strong>addTasks </strong>function. The addTasks will fork all the Sagas when the connected container is called. The injectedSagas will hold all the injected Sagas <strong>name </strong>to keep track on them<strong>. </strong>The tasks array<strong> </strong>is also needed and it<strong> </strong>might be useful, for example, if you logout from your app and you left some Sagas calling an external API, you could cancel those sagas preventing any undesired behaviors.</p><p>The store configuration file must change a little bit as well. I’m gonna take the example from above and update it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee57acf9917fdf9da77a9903ca4a8f6d/href">https://medium.com/media/ee57acf9917fdf9da77a9903ca4a8f6d/href</a></iframe><p>To call the Sagas by the respective container you must connect the container to the Saga. To do so you have to add the Saga and give a unique name.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e39c31257f5b9b3e49146b6a0355a0f0/href">https://medium.com/media/e39c31257f5b9b3e49146b6a0355a0f0/href</a></iframe><p>Finally fork the Sagas. I’m going to use the same example from above updating it a little bit.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae624552cb11f16b25b856d9efc17132/href">https://medium.com/media/ae624552cb11f16b25b856d9efc17132/href</a></iframe><p>This ways you have “async” Sagas. You could mix this pattern with the rest of the patterns. Play with them as you wish!.</p><p><strong>Part II</strong>:<a href="https://medium.com/@diegoAlbertoMV/applying-atom-design-methodology-and-hexagonal-architecture-using-react-part-ii-c51d0d7ece9"> Atom Design Methodology</a></p><p>That is all. As always, I hope you enjoyed the article and found it useful. Thanks for your time and for reading, and any feedback is very welcome! 😃.</p><p>Thanks to J. Drake for helping me review this article. ❤️</p><p>Cheers!</p><h4><strong>A note from In Plain English</strong></h4><p>Did you know that we have four publications and a YouTube channel? You can find all of this from our homepage at <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> — show some love by giving our publications a follow and <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>subscribing to our YouTube channel</strong></a><strong>!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6dbb1863a5d5" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/applying-atom-design-methodology-and-hexagonal-architecture-using-react-6dbb1863a5d5">Applying Atom Design Methodologies with React</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating, Testing and Publishing a VSCode Extension]]></title>
            <link>https://diego-molina.medium.com/creating-testing-and-publishing-a-vscode-extension-2981e06ff441?source=rss-85de18621e4c------2</link>
            <guid isPermaLink="false">https://medium.com/p/2981e06ff441</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vscode-extension]]></category>
            <category><![CDATA[js]]></category>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[visual-studio-code]]></category>
            <dc:creator><![CDATA[Diego Molina]]></dc:creator>
            <pubDate>Sun, 03 May 2020 21:36:24 GMT</pubDate>
            <atom:updated>2025-04-02T13:07:29.757Z</atom:updated>
            <content:encoded><![CDATA[<h4>When VSCode was released I was very happy. Mainly because I could develop extensions using JavaScript and I wanted to be one of the few people uploading an extension back in those days. At that time there were around six extensions available to install. To my surprise, the documentation was very poor of content. It was difficult to read and understand how to use the API and create an extension. Of course, the documentation improved over the time and the whole community around VSCode has done an amazing job with that, so thank you all for that!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*nLjaINw477F1D0prWH8oJA.png" /></figure><p>I’m pretty sure there’s a lot of these kinds of articles, but I will give you my experience developing an extension and also I will guide you step-by-step to build a basic extension.</p><p>One of the nice things of developing an extension for VSCode is that you can put in practice your skills with TypeScript or JavaScript. You could apply a new pattern that you might have learned or maybe just wanna create something you might need. I think this is a great opportunity to do that.</p><p><strong>What will you make?</strong> You will make an extension to convert from hexadecimal to RGB or RGBA color. The value will be taken from an Input Box and then the result will be shown on a message. You can use JavaScript or TypeScript, but the code I will show you is in JavaScript.</p><blockquote><strong>Advertising alert!</strong> ⚠️ These are my two extensions: <a href="https://marketplace.visualstudio.com/items?itemName=DiegoMolina.unitconverter"><strong>UnitConverter</strong></a> and <a href="https://marketplace.visualstudio.com/items?itemName=DiegoMolina.css-minify"><strong>CSS-Minify</strong></a>. I had four, one of them was a nice idea but it was requiring money to maintain the server 😅 and the other one was simple but got very popular, I removed it from the marketplace because it came built-in on a new VSCode version after it was released.</blockquote><h3>Installation</h3><p>First, you need to install globally three dependencies:</p><ul><li>vsce: It will help you to create your extension and publish it.</li><li>yo : Yeoman, you will need a generator that will make the template for your project.</li><li>generator-code : The generator that will create the template of the extension.</li></ul><p>After you have installed those dependencies, you have to run on your terminal the next command line:yo code and you will see something similar to the image below.</p><figure><img alt="Yo code prompt on terminal. It asks you question to generate the project structure." src="https://cdn-images-1.medium.com/max/938/1*k_5o4YOUcO4ouQWY1jDOwQ.png" /><figcaption>This is what you will see running “yo code”.</figcaption></figure><p>Choose <strong>New Extension</strong> either TypeScript or JavaSCript. Then you will have to answer the next questions shown on the image below. You can add whatever you want, just make sure it makes sense with the thing you are developing 😃.</p><figure><img alt="The questions that Yeo makes to you." src="https://cdn-images-1.medium.com/max/1024/1*009MmPieyWkD1vxCTQGI4Q.png" /></figure><p>Your folder structure will look similar to the next image.</p><figure><img alt="The generated project structure." src="https://cdn-images-1.medium.com/max/268/1*KcfchhUP5AVZBOtrYr1p8g.png" /><figcaption>Project structure.</figcaption></figure><p>The first thing you have to do is to create a new folder in which you will host all your code just to keep everything organized. Make a folder called app , inside of that folder make a single index.js or index.ts file. After that, you will have to edit some files. First edit the package.json file. Here you have to edit some parameters and add others.</p><p><strong>Parameters:</strong></p><ul><li>publisher : Add your name or nickname.</li><li>engines : This is very important. The engine is the version of your actual installed VSCode editor. If it’s lower than the actual version, you will have troubles debugging and generating your extension.</li><li>repository : It’s important for the description on the market place.</li><li>icon : The icon of your extension. Make a good one!</li><li>categories : You can define multiples but for now just keep the one the comes by default.</li><li>activationEvents : What it is going to trigger your extension. You can pick one or more from the next list: onLanguage , onCommand (default), onDebug , onDebugInitialConfigurations , onDebugResolve , workspaceContains , onFileSystem , onView , onUri , onWebviewPanel . For this example leave the default one. To know more about the activation events go to this link: <a href="https://code.visualstudio.com/api/references/activation-events">Activation Events</a>.</li><li>contributes : This is very important and is tightly related to the activationEvents . You chose onCommand, right? So when your extension is installed and is called by a command activation event, it is going to be triggered by that specific command. This command is registered in your code. In this case, it would be hextorgba.helloWorld . This command should be on the extension.js or extension.ts file. If you change it either from the extension.js or from the package.json file, make sure you have the same command name on both files.</li></ul><h3>Coding The Extension</h3><p>By default, the extension will be registered using a “command” (Do you remember what I said above?). If you want your extension to be executed, for example, only when you are working with a certain type of extension file, like PHP, you can change it to be triggered using the onLaguage activation event.</p><p>I won’t explain a lot about the extension.js file because it comes with a lot of useful comments that explain it. In here is where you will call your extension and all the needed code. The next picture shows the JavaScript version. It is not much different from the TypeScript version.</p><figure><img alt="lines of code found on the extension.js file" src="https://cdn-images-1.medium.com/max/631/1*rAtm32PMnRLRTToxjdIOFQ.png" /><figcaption>Default code on the extension.js file.</figcaption></figure><p>Now, on the extension.js file you should remove the comments if you already read them and also remove the line that says: vscode.window.showInformationMessage(&#39;Hello World from hexTorgba!&#39;); . The idea of removing this line of code is that you are going to add some code — I will show you soon — that will display an input box on the VSCode editor, then you will take the given value from that input box and convert it to an RGB and RGBA values. Finally, the result will be displayed on an information message box.</p><p>Did you make the app folder? if you don’t, do it and add into that folder an index.js file. On that file add the next lines of code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f157de72dd51dda29ff6d272fc1617c5/href">https://medium.com/media/f157de72dd51dda29ff6d272fc1617c5/href</a></iframe><p>You might try to understand this code, that’s something that any developer should do if they are copying and pasting code. But for the purpose of this article it’s not important because this is about the process of making a VSCode extension (<em>I’m open to get any feedback about my code</em> 😄). Now, go back again to your extension.js file and add the next line of code within the register command function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/513793f478b5ca1a7af13d2c8c951aa2/href">https://medium.com/media/513793f478b5ca1a7af13d2c8c951aa2/href</a></iframe><p>What happens on this code? Once you trigger your extension an input box will be displayed to you asking: “Type a hexadecimal color value”. Then you will type, let’s say <strong>fff, </strong>and<strong> </strong>hit enter. After the “enter” key pressed down, the function will be called and it will return you the typed value (<strong>fff)</strong>, take this value and convert it to RGB and RGBA color, and show the result on an information message box.</p><figure><img alt="Input box that vscode will show" src="https://cdn-images-1.medium.com/max/1024/1*oPeMZJDlXhcIQgldyQRInA.png" /><figcaption>Example of the input box.</figcaption></figure><blockquote><strong>Note: </strong>I encourage you to validate if the final user is typing a valid hexadecimal value. Also, have you realized that you are extending everything from the vscode object? Try to use destructuring for this.</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F26Ff4Ci2RNT1H1zb2%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fheyarnold-nickelodeon-hey-arnold-26Ff4Ci2RNT1H1zb2&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F26Ff4Ci2RNT1H1zb2%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/8582d01ccc058c1a88c505dd3514b7ed/href">https://medium.com/media/8582d01ccc058c1a88c505dd3514b7ed/href</a></iframe><p>The <a href="https://code.visualstudio.com/api/references/vscode-api#InputBoxOptions">shownInputBox</a> is a <strong>Thenable </strong>function. Most of the functions from the VSCode API are thenables<strong>. </strong>A thenable function is a function (recursion detected 👽) or an object that returns a then function, therefore it is promise. Now you have to call the hexToRgba function within the then function of the showInputBox . Your code should look something like this:</p><figure><img alt="Part of the final code" src="https://cdn-images-1.medium.com/max/410/1*KWeDE7vPGJYGjStTa5BAOQ.png" /></figure><p>If you want to try your extension or debug it you can go to the debug option on your left/right panel and click on the play icon. This will open a new instance of the VSCode editor. Once on the new instance type: shift+cmd+P on Mac, ctrl+shift+P on Windows and Linux, and type the name of your command; if you didn’t change it, it should be “<strong>hello world”. </strong>Then hit enter and you will see the input box asking you for typing a hexadecimal color value. Now it should display the converted color on an information message. To do this add the next line of code within the then function below your hexToRgba function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1a24ba6e03398cbbbd20e8d87658429/href">https://medium.com/media/d1a24ba6e03398cbbbd20e8d87658429/href</a></iframe><p>You need to pass your rgba variable to the first parameter of the showInformationMessage . The second parameter will display a button with the pass item as a text. It would be nice that, if you pass the variable as the second parameter, to try to find the way to copy and paste your rgba value and this way the final user can just paste it on its code.</p><figure><img alt="example of the information message with just the first param" src="https://cdn-images-1.medium.com/max/500/1*-aNyXT7xYA_SfmcACYOmBg.png" /><figcaption>Example using only the first parameter.</figcaption></figure><figure><img alt="Example using the rgba value in the second parameter" src="https://cdn-images-1.medium.com/max/500/1*we2KdCFbMf_TlH7x5CbK3Q.png" /><figcaption>Example using the rgba value in the second parameter.</figcaption></figure><p>If you added only the first param to the showInformationMessage your code should look something like this:</p><figure><img alt="final code" src="https://cdn-images-1.medium.com/max/466/1*ZmxD9yvB8XstYL6wd8eYgA.png" /><figcaption>final code.</figcaption></figure><p>Now it’s time to test your code.</p><h3>Testing Your Extension</h3><p>Why are you testing at the end of the code? I have two reasons:</p><ul><li>I wanted to explain to you a little bit about the workflow used to make an extension, get familiar with the code, and give you some useful tips.</li><li>Second, because when I tested my extensions I faced some issues and I ended up modifying the default configuration file to run tests. Testing the VSCode API, for me personally, is a little bit tricky.</li></ul><p>Of course, when you are coding your functions, you could code your test first and then code your functions. You are free to use any testing method or practice such as TDD, BDD or ATDD. But now I want you to get familiar with developing an extension.</p><p>When you generate your project it comes already with a small example of a test and also with the needed configurations. You can leave the runTests.js file just like that or you can modify it. On this file you can specify some of the next things:</p><ul><li>launchArgs : This is an array that will accept extra values to your suit of tests. For example, you could add the path to your fixtures or disable all the rest of your installed extensions and work only with yours. The last case is useful to prevent any possible conflict. To do that, add the launchArgs to the runtTests functions as a key parameter and add an array as a value, within the array add the next value: --disabled-extensions .</li><li>If you want to test your extensions with specific versions of VSCode, you have to download that version manually and added to the runTests function. To do so, add the next line of code:</li></ul><p>const vscodeExecutablePath = await downloadAndUnzipVSCode(&lt;version&gt;);</p><p>An issue that you might face once you run your test is that it won’t work because you might have another opened editor, meaning a new instance, and the test needs to actually download a new instance and set it up, but it cannot do this if you have already open a new instance. This also will happen if you don’t have opened another instance but your test downloaded the instance and it didn’t delete it — this happened to me randomly on Mac — . Either way you will have to delete the .vscode-test folder.</p><figure><img alt="Example of the error when another instance is running." src="https://cdn-images-1.medium.com/max/1024/1*REjKl4EyPN0cL9ZssRInGA.png" /><figcaption>Example of the error when another instance is running.</figcaption></figure><p>If the error still persists, you have two options:</p><ul><li>Close all of your VSCode instances, even the one you are working on and testing and run your test from the terminal. (Not ideal)</li><li>Change the version and download that version as I explained above. Add a version lower than the one you’ve got installed.</li></ul><p>Downloading a different version will definitely fix this problem. Your runTest.js file should look like this:</p><figure><img alt="Downloading manually a VSCode version to test." src="https://cdn-images-1.medium.com/max/800/1*7uL2FleANwDPuXGJxa_xVg.png" /><figcaption>Downloading manually a VSCode version to test.</figcaption></figure><p>To test the vscode API, I prefer to use <a href="https://sinonjs.org/"><strong>Sinon</strong></a>, which is so simple to use and works like a charm 💠! but you can use any framework that manages spies and stubs. Below there’s a simple test.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/549c989c947db6c2cdd698d1dfc691d9/href">https://medium.com/media/549c989c947db6c2cdd698d1dfc691d9/href</a></iframe><p>Once you’re done with this you can keep writing more tests like if the information message shows the right text, or validate the user input, or add the action button and test it as well 😃.</p><h3>Publishing Your Extension</h3><p>First, you need to have a Dev Azure Account. Create one and then go to the top right corner just like this image shows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/1*ulCOr7s8LwBlxjF8s9o26A.png" /></figure><p>Then click where it says “<strong>Personal access tokens</strong>”. Add a new token. Once there, just make sure you select “<strong>All accessible organizations</strong>” on the organization section. You can also add more days before your token expires. You have to go to <strong>Marketplace</strong> and select <strong>Acquire</strong> and <strong>Manage</strong>. Finally, click on “<strong>Create”. </strong>Copy and save your token in some note or text file.</p><p>Now, go to your terminal and type the next command line one-by-one:</p><ul><li>vsce package : This will generate the package.</li><li>vsce create-publisher : This is only once, and it’s for the very first time you want to upload an extension. I recommend for you to use the same publisher name you defined on the package.json file.</li><li>vsce login &lt;publisher_name&gt; : Log in using your created publisher name. This will ask you for the Access Personal Token.</li><li>vsce publish : Final step. It will upload your extension. If everything is ok, you will see it in a few minutes on the VSCode Marketplace.</li></ul><p>This is all. I hope you enjoyed the article and found it useful. Thanks for your time and for reading, and any feedback is very welcome! 😃.</p><p>Thanks to J. Drake for helping me review this article. ❤️</p><p>Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2981e06ff441" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Personal and Favorite Learning Resources as a Developer]]></title>
            <link>https://diego-molina.medium.com/my-personal-and-favorite-learning-resources-as-a-developer-8531ddd8a652?source=rss-85de18621e4c------2</link>
            <guid isPermaLink="false">https://medium.com/p/8531ddd8a652</guid>
            <category><![CDATA[programming-course]]></category>
            <category><![CDATA[programming-books]]></category>
            <category><![CDATA[books]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[course]]></category>
            <dc:creator><![CDATA[Diego Molina]]></dc:creator>
            <pubDate>Sun, 19 Apr 2020 19:06:52 GMT</pubDate>
            <atom:updated>2025-04-02T13:07:05.995Z</atom:updated>
            <content:encoded><![CDATA[<p>Thanks to the Internet we have access to a lot of information. This is a wonderful thing but at the same time it could be overwhelming and frustrating, especially when you are searching for a learning resource. There’s so many people out there saying: learn this in 5 minutes, watch this video tutorial, I even wrote and article about what I do when I’m coding using React. I still ask myself: “is this a good article?” “it worth it to pay for this book?” or “ should I buy this course?” These questions are sometimes resolved reading other people’s opinions about certain books or video tutorials. In the case of books, especially about coding, algorithms, and so on, it is so hard to understand them. Some of these “technical books” — as I call them — leave you a bitter flavor of “ugh, this book was a waste of money.” Here I will share my opinion about some resources, books and courses, that I need constantly in my life and some of them might be old but I’m still using them 😃.</p><h3>Books 📚</h3><h3>CSS Secrets: Better Solutions To Everyday Web Design Problems</h3><p>This is one of the coolest and most beautiful books that I’ve got. If you can buy it, do it, you won’t regret. Starting from a banal vision, each single page of this book has a beautiful and colorful design, the texture is like a magazine and the amount of content is amazing. Speaking about the content, everything in this book is well divided, everything is connected perfectly: images with explanation and the code examples. Definitely it has the best solutions and they are “secret” solutions, and I couldn’t wait for less because this books was written by the amazing and freaking smart woman <a href="https://en.wikipedia.org/wiki/Lea_Verou"><strong>Lea Verou</strong></a><strong>.</strong> I recommend you look for some conferences she has given. Her presentations are amazing. But, pay attention to them, she speaks really fast and makes fast mathematical calculations ⚠️.</p><p><a href="http://shop.oreilly.com/product/0636920031123.do">CSS Secrets</a></p><h3>You Don’t Know JS — The Saga!</h3><p>This is a 6 book saga. The nice thing about these books is how well everything is explained, and of course, because it was written by <a href="https://twitter.com/getify?ref_src=twsrc%5Egoogle%7Ctwcamp%5Eserp%7Ctwgr%5Eauthor"><strong>Kyle Simpson</strong></a>. He is a teacher — besides many other things — and you can see this while you’re reading his books. Kyle goes through the very basic things about JavaScript like scope until advanced and cool knowledge such a Symbols and Async/Await. He also wrote another book about <strong>Functional Programming.</strong> The nice thing about this last book it is that it was written with the help of a lot of people around the world. This books is for free reading it on <a href="https://github.com/getify/Functional-Light-JS"><strong>Github</strong></a> or you can buy it digitally. I also recommend you search for some of his talks about JavaScript and the weird parts of it.</p><p><a href="https://www.amazon.com/gp/bookseries/B01N9EBP9V">You Don&#39;t Know JS Book Series: Amazon.com</a></p><h3>Docker Deep Dive</h3><p>The title says it all. It is a book with a deep dive into the Docker world. The author, <a href="https://nigelpoulton.com/"><strong>Nigel Pouton</strong></a> gives you a bunch of useful knowledge in this book in order to work with Docker in a professional manner. He explains everything so well that even the hardest things about Docker are easy to understand, and that, in the computing world, is difficult to get in a book and he deserves my applauses 👌. I still go to my digital version to read some stuffs because this book is an essential tool.</p><p><a href="https://www.goodreads.com/book/show/36411996-docker-deep-dive">Docker Deep Dive</a></p><h3>The Complete Redux Book</h3><p>If you are starting in the React world you might ending up working at some point with <strong>Redux.</strong> This was and it is yet one of my essential reads about Redux. I don’t know much about the authors <a href="https://leanpub.com/u/ilyagelman"><strong>Ilya Gelman</strong></a> and <a href="https://leanpub.com/u/borisdinkevich"><strong>Boris Dinkevich</strong></a>, but I’ve watch some of the conferences made by <strong>500Tech</strong> and these guys Rock! I can tell you they have done an amazing job writing this book. The whole book covers the set-up, performance improvement and some patterns, all of this following the same example. This book will help you to work neatly with Redux.</p><p><a href="https://leanpub.com/redux-book">The Complete Redux Book (2nd edition)</a></p><h3>High Performance JavaScript</h3><p>Please, don’t think because is an old book it doesn’t have valuable information. <a href="https://www.oreilly.com/pub/au/3902"><strong>Nicholas C. Zakas</strong></a> wrote this simple and good book. If you are a beginner with JavaScript and manipulating the DOM, this is a book you must read. But it is not only for beginners, it is also for people that work with JavaScript in general. As an example he explains the use of the global scope, how actually works going beyond the words, this is essential to understand the basic concepts about performance on JavaScript.</p><p><a href="http://shop.oreilly.com/product/9780596802806.do">High Performance JavaScript</a></p><h3>Courses 🎥</h3><h3>Learn How To Code: Google’s Go (golang) Programming Language</h3><p>This is a course that you can find on Udemy. If you are starting with Go like me, I recommend this course 100%. I finished all the course and I have to say that I’m still watching it because it helps me to remember Go stuff. I’m a huge fan of <a href="https://www.udemy.com/user/toddmcleod/"><strong>Todd McLeod</strong></a>. He’s a professor and you can see that through the entire course. And the most important thing, he is a person; he behaves like that through all the videos, talking not only about Go, but also about friends, his work as a professor, even the few hours he’s been sleeping because he was preparing all the content for his videos. Definitely, this is for beginners and intermediate levels. He also has a <a href="https://www.youtube.com/user/toddmcleod">YouTube Channel</a> where he’s constantly showing how to code with Go, especially websites.</p><p><a href="https://www.udemy.com/course/learn-how-to-code/">How to Code: Learn Google&#39;s Go (golang) Programming Language</a></p><h3>Docker and Kubernetes: The Complete Guide</h3><p>I found <a href="https://www.udemy.com/user/sgslo/"><strong>Stephen Grider</strong></a><strong> </strong>when I was searching for a MongoDB course, and I loved how well he explained everything, it is worth it to buy his course. He even covered more content like testing and for me, at that moment, it was important because I needed to know how to write tests. Due to all of that, when I was searching for a Docker course and found one made by Stephen I didn’t hesitate and I bought it. This course is so good for any level of knowledge. One of the nice things is that you will see some common mistakes and how to resolve them, you will understand in short videos all the essentials and more about Docker.</p><p><a href="https://www.udemy.com/course/docker-and-kubernetes-the-complete-guide/">Docker and Kubernetes: The Complete Guide</a></p><h3>React — The Complete Guide (incl Hooks, React Router and Redux)</h3><p>This course is good for beginners. In my case I found nothing I didn’t already knew, but I must say that <a href="https://www.udemy.com/course/react-the-complete-guide-incl-redux/"><strong>Maximilian Schwarzmüller</strong></a><strong> </strong>did an amazing job. He is really good explaining everything about React. He touches all the topics that you should definitely know about React. I recommend this video for beginners and intermediate levels. He also has a <a href="https://www.youtube.com/c/academind/">YouTube Channel</a> that is really worth to checking out.</p><p><a href="https://www.udemy.com/course/react-the-complete-guide-incl-redux/">React 16: The Complete Course (incl. React Router 4 &amp; Redux)</a></p><h3>Learn and Understand NodeJS</h3><p>When you search for learning NodeJS on Google most of the time you will find how to use NodeJS with ExpressJS. Learning NodeJS is more than implementing a framework and making an API or a website. <a href="https://www.udemy.com/user/anthonypalicea/"><strong>Anthony Alicea</strong></a><strong> </strong>made such a wonderful course about NodeJS. He dives into the core of NodeJS. You will learn and understand how it really works. He will show you why NodeJS is so powerful and gives you a very good and solid experience about NodeJS and its dependencies. In this course you will learn how to work with emit events, streams, using pipe, and so on. This is a course you should buy <strong><em>before</em></strong><em> </em>starting with ExpressJS or any other NodeJS framework.</p><p><a href="https://www.udemy.com/course/understand-nodejs/">Node JS Training: Learn and Understand Node JS</a></p><p>These are my favorite resources and I’m always going back to them when I don’t remember something. A personal thought, I know more thanks to these people and they are a nice inspiration to never stop learning.</p><p>I hope you liked the article and that it is has been helpful for you.</p><p>As always thanks to J. Drake for helping me review this article. ❤️</p><p>Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8531ddd8a652" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Write, Test and Deploy Your First NPM Package Using Travis-CI]]></title>
            <link>https://levelup.gitconnected.com/write-test-and-deploy-your-first-npm-package-using-travis-ci-74b5ab94379c?source=rss-85de18621e4c------2</link>
            <guid isPermaLink="false">https://medium.com/p/74b5ab94379c</guid>
            <category><![CDATA[travis-ci]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[jasmine]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Diego Molina]]></dc:creator>
            <pubDate>Sun, 12 Apr 2020 01:50:10 GMT</pubDate>
            <atom:updated>2025-04-02T13:06:16.992Z</atom:updated>
            <content:encoded><![CDATA[<h3>Write, Test, and Deploy Your First NPM Package Using Travis-CI</h3><h4>I’m going to make a simple test with Jasmine and give you a step-by-step guide to upload your first npm package using Travis.</h4><p>Before giving you a simple and small guide on how to deploy your npm package using Travis, I want to encourage you to write anything! even reinvent the wheel <em>(I’ll write an article about this because I think it is an interesting subject). </em>Writing code is the only way to practice and learn from your own mistakes. What is explained here it was my learning process using these tools. This means that I’m not an expert but the learning process was absolutely nice and successful. That’s why I wanted to share it with you.</p><p>I will try to explain the following:</p><ul><li>Write a simple package that will transform any word into its hexadecimal color format using a very simple function. This is for only educational purposes.</li><li>Test the function that will return the hexadecimal value.</li><li>Add a Travis configuration file.</li><li>Upload our project to Github and connect Travis with our Github account.</li><li>Let Travis do all the work. Testing and deploying the app, and then upload your package to npm.</li></ul><blockquote><strong>IMPORTANT: </strong>You need to create a Github account and npm account before starting.</blockquote><h3>The Package.json File and Our Index.js File</h3><p>Don’t be scared. Writing an npm package is not difficult and nothing you probably haven’t done yet. Let’s start with the basic thing you need, a package.json file.</p><p>The best way to do this, if you don’t already have a package.json file to use as a boilerplate, is running the npm init command from your favorite terminal. After running the command, the terminal will prompt asking you:</p><ul><li>package name : Choose the name wisely. It is very important to know that the name is going to be used for installing and importing your package into your project or other projects. Choose something easy to write and fancy as well 💅. For this example, I will choose <strong>colorword.</strong></li><li>version: (1.0.0) If you don’t know what to write here, just leave it blank.</li><li>description: Write a nice one. e.g.- <em>Tiny but fun library to transform words into hexadecimal colors.</em></li><li>entry point: (index.j) This is the index file form <strong>where</strong> your function is going to be imported. If you are using babel for some reason and your final code is at lib then the entry point would be that route.</li><li>test command: For now, leave this empty. You’ll change it later.</li><li>git repository: Add your git repo where your code is going to be hosted.</li><li>keywords: For this example, keywords are not needed. But you will want to use them if you want to reach the right people. e.g. words to colors or javascript .</li><li>author: Your name. <em>You can be a rockstar!</em> 🙌.</li><li>license: (ISC) This is up to you. I mostly use MIT license.</li></ul><p>That’s it! Now make an index file and leave it empty because now you will make your first test!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*Wv0ZkbPQ3lGBg6QkdBU6Mg.png" /><figcaption>I made this bored image :P</figcaption></figure><h3>Testing Your Function</h3><p>For testing, I’m going to use Jasmine. There’s nothing against the others; actually you can use any other testing framework like Mocha (<em>I love running Mocha on the Back</em>), but I just wanted to use Jasmine because it is simple and easy to install. Now, you need to install jasmine and jasmine-spect-reporter. After installing this you have to configure Jasmine. All of this is very simple, just run:</p><p>npx jasmine init</p><blockquote>npx is a package runner that runs any package from the npm repository. This is very helpful, we can run any CLI tool without install it globally or locally.</blockquote><p>This will create a support folder with some default configurations. You don’t have to modify anything from here, but you need to make a second folder called helpers where you’ll add a reporter.js file and add the next lines of code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32050484ed1c7b7b3bc9f3f2cfe03b1f/href">https://medium.com/media/32050484ed1c7b7b3bc9f3f2cfe03b1f/href</a></iframe><p>This is for getting a nice report on the terminal when you run your test. Now modify your package.json and replace your test script for this:</p><p>&quot;scripts&quot;: {&quot;test&quot;: &quot;jasmine&quot;}</p><p>That’s all with Jasmine installation and configuration. Finally, you need to write your first tests called color.spec.js. Add the next lines of code into that file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62f05353e5c3311c93f0ee7348c9df1b/href">https://medium.com/media/62f05353e5c3311c93f0ee7348c9df1b/href</a></iframe><blockquote><strong>NOTE</strong>: There are many nomenclatures for testing files. You can use: _color_test.js , or color.test.js , or Spec.color.js , and on. I recommend for you to read which one is widely used with the framework you are using. Here I’m using Jasmin. It is a standard to use thespec word in Jasmine.</blockquote><p>After all the setting up your project structure should look like this:</p><figure><img alt="Example of a project structure." src="https://cdn-images-1.medium.com/max/506/1*TxvtMcb7WWPH36M4-0_cgA.png" /><figcaption>project structure</figcaption></figure><p>If you run your test, it’s going to fail. This is because you haven’t written any code yet. This way of making test is called <strong>TDD</strong>. I’m not going to dive into this. But <a href="https://en.wikipedia.org/wiki/Test-driven_development">wikipedia</a> has a very good explanation of it.</p><p>The idea behind the colorWord function is to pick a word, in this case hello , use only the first 3 letters from it and get the hexadecimal color from that.</p><p>Now, give me the code! Add this code in your function and run your test again. It should be successful now.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7da748f1978f286d9a213bbb7ac86ba7/href">https://medium.com/media/7da748f1978f286d9a213bbb7ac86ba7/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F5p2wQFyu8GsFO%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2F5p2wQFyu8GsFO&amp;image=https%3A%2F%2Fmedia2.giphy.com%2Fmedia%2F5p2wQFyu8GsFO%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="245" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d7f692994efd70b5e740314ff1ac2c0/href">https://medium.com/media/5d7f692994efd70b5e740314ff1ac2c0/href</a></iframe><p>Now that you made your first test and works properly — <em>Remember, this is just a basic example, in real life you will have tons of tests</em> 😅 — It is time to configure Travis to run your test every time you are adding or modifying your code before deploying your package and sharing it with the world!. This is called <strong>C</strong>ontinuous <strong>I</strong>ntegration (CI) and testing is just part of it.</p><h3>Configuring Travis and Connect It with Your Github Account</h3><p>If you don’t have a Github account, create one 😬. When you go to Travis website, you will to sign up using your Github account to make everything just easy. Once you’re in, you have to add the repository from where you will get the uploaded project you want to test and make CI. Go to the left panel and press the plus symbol.</p><figure><img alt="Left panel of Travis-CI. Here you can add your repositories from git" src="https://cdn-images-1.medium.com/max/328/1*3iFlrsOj4MsNPEmI2LhNBQ.png" /><figcaption>left panel of my Travis</figcaption></figure><p>As you can see on the image — this is my Travis panel — I have 3 repositories added. Each one of them has tests and one of them a different configuration which is the one you will use now. This configuration has “steps” such as: test and deploy if the tests are successful.</p><p>When you add a repository you can configure how’s Travis is going to run<em>. </em>Some configures are: Run after pushing to the master branch, or only when there’s a pull request, and so on. For now, just switch the button and don’t make any extra configuration<em>.</em></p><figure><img alt="Panel where you can look for your repository and added to travis" src="https://cdn-images-1.medium.com/max/871/1*XFCjIoDppWrnuZimzN-rGQ.png" /><figcaption>Example of Travis showing my list of repositories from my Github account.</figcaption></figure><p>After this, you should go back to your project and add the next code to your .travis.yml file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d095119751006cce7b906028ce01c00/href">https://medium.com/media/9d095119751006cce7b906028ce01c00/href</a></iframe><p>You can configure your jobs in many different ways. For me, this is what works and fits perfect for my project and I think it’s the same for this example.</p><blockquote><strong>IMPORTANT</strong>: In this example I have node_js version 12.13. You should change it to the version of your installed NodeJS.</blockquote><p>Let me describe some tags from the file:</p><ul><li>jobs : These are the “tasks” known as stage that Travis will run one after the other.</li><li>stage : This allows to run several jobs in parallel. In this case I have two jobs, one in the stage called test and the other one in the stage called deploy .</li></ul><blockquote>Build stages is a way to group jobs, and run jobs in each stage in parallel, but run one stage after another sequentially.</blockquote><blockquote>In the simplest and most common use case, you can now make one job run <em>only</em> if several other, parallel jobs have completed successfully. — Extracted from Travis documentation</blockquote><ul><li>name : It will assign a name to the job. You can find it when they are running on the main page or in the dashboard.</li><li>email and api_key : These are important, and you have to go to your npm account. If you don’t have one, create it. After creating your account, just sign in and go to your profile, then it’s pretty straight forward to create a token from here. Copy that token and go to Travis website, click on the button that says <strong>more options</strong> and click on <strong>settings</strong>, then go to <strong>Environment Variables</strong> and add the environment keys. These keys are the same constant that the file has, NPM_EMAIL_ADDRESS and NPM_AUTH_TOKEN . Any name can be an Environment Variables use something that makes sense like the project you are working on and what the environment variable is for.</li></ul><p>Travis runs the tests by default. In the configuration file that you’ve got it will run the tests and then it will run the next stage. You will see something similar to this on Travis:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3vsTNgH9acUaLnQU0T0pPA.png" /><figcaption>running jobs</figcaption></figure><p>If you do click on deploy you will see something like this: <br><em>(This is a picture from one of my projects. It’s just an example of what the terminal will prompt to you)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*HQov_uZvvH3z90x_gkQdmQ.png" /></figure><p>This is it! Now you can work on a real project that you have in mind and start deploying tested versions to the world.</p><p>Something that I faced through all this process was an issue with the Travis configuration file. There’s an option that allows you to use your stag from Github. This is not clear — at least for me— in the documentation. You have to be careful if you use the param tags:true on the travis.yml file because if you do, you will need to add all_branches:true as well to make this work, but you cannot use branch: &lt;name_of_your_branch&gt; and tags:true together, otherwise it will fail giving you the next message: <strong><em>skipping a deployment with the npm provider because this is not a tagged commit.</em></strong></p><p>Also, it is a good idea to have an .npmingore file to not push any unnecessary file with your package to your npm repository.</p><p>This is it! I hope you liked the article and that is has been useful for you. I’m still learning some things about npm packages.</p><p>Thanks to J. Drake for helping me review this article. ❤️</p><p>Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74b5ab94379c" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/write-test-and-deploy-your-first-npm-package-using-travis-ci-74b5ab94379c">Write, Test and Deploy Your First NPM Package Using Travis-CI</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I code when I work with React.]]></title>
            <link>https://levelup.gitconnected.com/how-i-code-when-i-work-with-react-5f8a554fd68a?source=rss-85de18621e4c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f8a554fd68a</guid>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Diego Molina]]></dc:creator>
            <pubDate>Tue, 07 Apr 2020 14:27:47 GMT</pubDate>
            <atom:updated>2025-04-02T13:05:45.851Z</atom:updated>
            <content:encoded><![CDATA[<h3>How I Code When I Work With React</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*592NWrgXEZTrQXWGYA0XAw.png" /><figcaption>Image extracted from: <a href="http://blog.desafiolatam.com/conociendo-mas-sobre-react/">http://blog.desafiolatam.com/conociendo-mas-sobre-react/</a></figcaption></figure><p>I love React, and I might go so far as to say that I’m good coding with it. I’m neither an expert nor a beginner. One difficulty you might run into while working with React, aside from figuring out how to use the API, is that you have to keep in mind the <strong>people</strong> you are working with now and possibly in the future. In my opinion, what is important when I’m working with React is trying to keep everything as clear, clean, and easy to read as possible (I think about performance too).</p><h3>Think Always in Functions</h3><p>This is something you maybe already know. I’ve seen some coworkers having trouble looking through the code. They get confuse about what is a component or a controller because there’s so much a code that is hard to follow some kind of pattern that you use in your company.</p><p>Thinking in function means: start writing a simple function, and if it gets too verbose, move to a class, but try to avoid that. Also, If you need more control over the lifecycle of a component definitely go for a class. But always start thinking in functions.</p><p>We can declare components as a function in different ways. I’d like to make a differentiate between a function as a component and a function that needs to process some data and return the result or trigger some action. Also the way I declare the props and where I start using destructuring is important for me.</p><p>When I work with stateless components, I like to use anonymous functions and destructuring the props between the parenthesis. Why do I do this?:</p><ul><li><strong>Differentiation </strong>between a stateless component that is only going to paint and one that might be a controller.</li><li><strong>Less code: </strong>This is only something visually, and it’s something that I’m doing on my code. It is easy to read and maintain.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6fc86c72f6633d07cb251e70f451df82/href">https://medium.com/media/6fc86c72f6633d07cb251e70f451df82/href</a></iframe><p>There could be another situation where this component manages some state inside of it. In that case, I follow some rules and they also apply for containers that are made of functions instead of extending from Component or PureComponent .</p><ul><li>Any function within the component must <strong>not</strong> be an anonymous function, just normal functions declaration.</li><li>I use destructuring where I <strong>need</strong> it, thinking always in the scope.</li><li>I keep all in “<strong>blocks</strong>”. Hooks / Functions / Props / Component.</li><li>If I use useState I prefer to keep the well-known variable and function state and setState .</li><li>I <strong>Don’t</strong> use destructuring for the state. I like to know what variables are from the props and which ones from the state.</li><li>Is you are using useState and your state grows up, you should move to useReducer .</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72bbd76f344b5566a74ef62526bfadc0/href">https://medium.com/media/72bbd76f344b5566a74ef62526bfadc0/href</a></iframe><h3>Naming Functions</h3><p>Sometimes naming functions with general names is simple and clean. But we can have a lot of functions and we need to create a difference among them.</p><p>What I do for functions triggered by an <strong>event</strong> — a click on a button — is to go from the <strong>general</strong> to the <strong>specific </strong>making functions easy to understand. This is important; code is not only algorithms, but it is also about explaining ideas with words.</p><ul><li><strong>The general: </strong>Start using the name of the events as a prefix: onClick , onMouseDown , onChange , etc.</li><li><strong>Specific: </strong>Where is trigger these actions? I often use the name of the component or part of it. Sometimes it’s the action that is going to trigger the function: onClickNewUser , onChangeTitle , onClickDeleteAccount .</li><li><strong>Make a difference: </strong>Add Handler at the end of the function. This is something you can find in many tutorials, videos, articles, so on. This is a good practice that helps us to make the differentiation between an event function and a normal event.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c35dadd28ed440f376a0aa924009b17/href">https://medium.com/media/0c35dadd28ed440f376a0aa924009b17/href</a></iframe><h3>Don’t Mount and Unmount Repeatedly</h3><p>It’s pretty common to hide or show a <strong>component </strong>by some conditions. This, for small applications is not a big deal, but for big ones it could be a way to save memory and make the applications smooth. Of course, this is not a golden rule and sometimes we actually <strong>need</strong> to unmount a component and mount it again. We need to know <strong>when</strong> to do it and <strong>what</strong> to do about it. My tip is to think about components like alerts or modals, or something with an animation. You could use a CSS class to hide them without unmounting and mounting the component constantly. This CSS class could have: display: none; or maybe opacity: 0; or even visibility: hidden;. Just use what is the best for you.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da11d985ea530b634658c40e52eeb577/href">https://medium.com/media/da11d985ea530b634658c40e52eeb577/href</a></iframe><h3>No More than 10 Functions Within a Component</h3><p>Since we can use state in a function thanks to hooks, we’ve been using them to make light and fast components. But, we <strong>must </strong>remember that the functions within this component are going to be created again by each rendering, using space in memory. For this situations, I developed a mental guide.</p><ul><li>If I have <strong>more than 10</strong> functions within a stateless component and they have a lot of complex logic, I prefer to use a component that extends from Component or PureComponent .</li><li>If I <strong>have more than 10</strong> functions but some are simple and <strong>just a few</strong>, like 2 or 3 are complex, I keep the component as stateless but I use, with the complex functions within, useCallback hook.</li></ul><h3>If It Doesn’t Change, Just Created It Once and Reuse It</h3><p>Imagine you have a list of all the countries in the world in an array. This will probably remains constant. What if your component also has a city list and this list will be filtered each time you select a different country. This flow will render my component constantly. Of course, you <strong>have</strong> to use a unique ID and pass it to the key attribute if you are mapping to make a list component. But, <strong>before</strong> that, we are filtering the list of cities, making a new array; This is good because we have immutability, but we are using extra memory. For a scenario like that, we have many solutions. I’m going to show the one that I prefer. I make use of useMemo hook.</p><blockquote>… will only recompute the memoized value when one of the dependencies has changed. This optimization helps to avoid expensive calculations on every render. … — Extracted from React documentation.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b3399d184bff54d2c12bd6fa669f79b/href">https://medium.com/media/1b3399d184bff54d2c12bd6fa669f79b/href</a></iframe><p>The nice thing about useMemo is that it returns what we filtered earlier, and only created a new object or array when something has change, otherwise it keeps using the same.</p><h3>Divide and Conquer</h3><p>Definitely we could end up having a big container. Importing this container or even more than one could cause the application to render your components slowly, having a white screen for a couple of seconds or more. For cases like this, I use React Lazy Load. React offers us a function and a component: lazy and Suspense . The lazy function is for <strong>code splitting</strong> and the Suspense component helps us mount this “splitted” container or component and render it without <strong>blocking</strong> the rest of the containers or components.</p><ul><li><em>The </em><em>React.lazy function lets you render a dynamic import as a regular component. … The lazy component should then be rendered inside a </em><em>Suspense component, which allows us to show some fallback content (such as a loading indicator) while we’re waiting for the lazy component to load. — Extracted from React Documentation.</em></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27e3e12a87d42d8dc7b035db63fd6eb0/href">https://medium.com/media/27e3e12a87d42d8dc7b035db63fd6eb0/href</a></iframe><p>You might wonder why I said you should use this for containers but not components. I personally do this because following the above rules my components would be smaller with no functions or just a few. But a container could have more containers and it could have a lot of functions. Therefore this file will be a big bundle taking time on the request. Splitting this big file will help you to load your code faster because you are going to dispatch small chunks of code. 🚀</p><h3>Check Your Prop Types</h3><p>Try as much as possible to check the prop type using the <a href="https://www.npmjs.com/package/prop-types">prop-types library</a>. This will help you to prevent inconsistency passing your props. It’s very useful, for example, if you are working with data and your component must receive certain types of data or structures like an array of objects. Another nice thing about using prop types is when you are working with Storybook and the addon-doc to document your components, this will generate a nice documentation of the type of props your component can receive.<br>(<em>Added: 06–15–2020 — before the end of the world 💥)</em></p><h3>My Very Personal One, My TOC: Cascading Descending 😁</h3><p>I have to insist. How your code looks matter. Through the time I developed some kind of TOC about my code. I’ve been applying this to JS and CSS and I think it is nice and clean, and the most important thing, easy to read. This is not something that might change your coding ability or how efficiently your code will run. I repeat, <strong>it’s just something visually.</strong></p><ul><li>All variables are declared in descending order.</li><li>All imports are declared in descending order using the from keyword as a reference. Except the <strong>main</strong> libraries, which has to be just <strong>one </strong>like React, and it goes always first.</li><li>Destructuring also in descending order.</li><li>Variables are together but not mixed.</li><li>Make use of new lines. Don’t keep all your code tight and together. Imagine you are writing a book and someone is going to read it.</li><li>Make simple code. Complexity doesn’t necessarily mean “better” and “cooler”. Simple and clean is best. (Yes, I’m kind of a minimalist person).</li></ul><p>I’m going to show you an example and you can judge by yourself.</p><p><strong>Update:</strong> Some people had tell me they prefer Ascending order. I think Ascending and Descending are both great options and definitely better than having all your imports and variables all messy. Thanks for the feedback! 😃</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/24e3691bf2cc22930ce583c4d2e626b8/href">https://medium.com/media/24e3691bf2cc22930ce583c4d2e626b8/href</a></iframe><p>All of this I’ve been trying to apply to my code. If you check my Github, some of my projects might not follow this, and it’s because they are old and I had other ideas about coding at that time. But reading articles, books, meeting people, reading code from others and working with many different and diverse persons, made me, I think, a better programmer.</p><p>Thanks to J. Drake for helping me review this article. ❤️</p><p>I hope you enjoyed it. Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f8a554fd68a" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/how-i-code-when-i-work-with-react-5f8a554fd68a">How I code when I work with React.</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>