<?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 Rodo Abad on Medium]]></title>
        <description><![CDATA[Stories by Rodo Abad on Medium]]></description>
        <link>https://medium.com/@rodoabad?source=rss-8ea83dfb2b87------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*lVJNfsof5rRrJKK0kBFp5Q.jpeg</url>
            <title>Stories by Rodo Abad on Medium</title>
            <link>https://medium.com/@rodoabad?source=rss-8ea83dfb2b87------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 03 Apr 2026 22:51:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rodoabad/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[2007 Honda Civic: The car that keeps on giving]]></title>
            <link>https://medium.com/@rodoabad/2007-honda-civic-the-car-that-keeps-on-giving-332564890ca2?source=rss-8ea83dfb2b87------2</link>
            <guid isPermaLink="false">https://medium.com/p/332564890ca2</guid>
            <category><![CDATA[maintenance]]></category>
            <category><![CDATA[cars]]></category>
            <category><![CDATA[cost-of-ownership]]></category>
            <category><![CDATA[civics]]></category>
            <category><![CDATA[honda]]></category>
            <dc:creator><![CDATA[Rodo Abad]]></dc:creator>
            <pubDate>Sun, 24 Feb 2019 00:53:42 GMT</pubDate>
            <atom:updated>2024-10-07T03:47:36.968Z</atom:updated>
            <content:encoded><![CDATA[<h4>I bought my 2007 Honda Civic 5 Speed Automatic EX with Navigation back in November of 2006 with the help of my mom [Thanks, mom!] for roughly $22K. Since then, the car has given me 90,000+ miles of driving pleasure.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OZFNNpUZjJ_LxRhxqp9Skw.jpeg" /></figure><p>The 2007 Honda Civic sedan is a beautiful car especially when you compare the car to its competition like the Mazda 3, Toyota Corolla, and Nissan Sentra. Compared to past Civic generations the progressive design of the 8th generation Honda Civic feels like it’s on a different class of cars – liberal, contemporary, and sophisticated. The two-tier dashboard felt like I was in a spaceship and with the big tachometer smacked right in the middle of your dashboard you’re either checking whether you’re at the optimum RPM to have the best miles per gallon or when you’re about to hit VTEC to get the best smiles per gallon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Lr_GTBh1zwL-nkD6gmp3w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D9O-mH6DjM5qemxn4nJipw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jTIL54eLjqDNnol3dvIfpw.jpeg" /><figcaption>With a progressive interior, this car looked very contemporary when it was released back in 2007.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BqDYSitthjHrCda80g_OgA.jpeg" /></figure><p>I’ve driven this car all the way to Canada, California, Nevada, and Illinois from Colorado with no problems, all I had to do was make sure that I have my passport for the Canada road trip and that I have enough money to fill up and buy food along the way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sNtH-qjwKlUKl8DVMQKKsA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EHLyc-F8gHawtBz3tL4ufQ.jpeg" /><figcaption>Exterior looks weren’t bad either and have aged gracefully.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fPkwh-8WWADMzpO_0KM2zA.jpeg" /></figure><h3>Cost of Ownership</h3><p>I can keep praising the car as much as I want but I’m sure you would also like to know how much does it cost to maintain this car? Provided you are a decent driver and you actually take care of your cars.</p><p>I’ll break it down into two parts — regular maintenance which includes oil changes, tire rotations, wiper blade replacements, etc and the more expensive type of maintenance which includes new tires, new engine parts, etc.</p><h4>Regular Maintenance</h4><p>When it comes to regular maintenance, the car has cost me on average less than $50 per visit. Now mind you, I drive this car close to 9,000 miles a year. Not a lot compared to other commuters so my car maintenance schedule is a bit on the low-end of the spectrum — if there is nothing wrong with the car, I go twice a year for a total of $100.</p><p><strong>Current Total Cost: $100 ($9/month)</strong></p><h4>Miscellaneous Maintenance</h4><p>For over 10 years that I have owned this car, I had a total of five maintenance that will fall under “miscellaneous”.</p><ul><li>Tires: $700+</li><li>Engine (VTEC related): $800+</li><li>Wheel Bearing: $450+</li><li>Brake Pads: $250+</li><li>Oil Leak: $120+</li><li>A/C Compressor: $800+</li><li>Battery: $150+</li><li>Tint: $170+</li><li>Windshield: $350+</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QnQjAm4y-QUxJrmwLRhwRg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XQaeg1nKlcBoKqKScxlI3Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*saoOouG5icRxwdWzk3537A.jpeg" /><figcaption>Not a lot of downtime for this car as maintenance usually takes no more than a couple of hours if the dealership is busy.</figcaption></figure><p>The total cost of all these miscellaneous maintenances that I had come close to $3800. You might think that it is starting to get expensive but you have to remember that these types of maintenance do not happen every year. In fact, if you average it out over the years that I have owned the car (10 years), it equates to roughly $380 a year.</p><p>Which brings us to an annual cost of $480 — $100 for regular maintenance and $380 for miscellaneous maintenance per year.</p><p><strong>Current Total Cost: $480 ($40/month)</strong></p><h4>Gas and Miles per Gallon</h4><p>I started tracking how much I spend on gas and how far can I go with it a couple of years ago. So far I am averaging $25 per fuel-up and driving close to 30 miles per gallon.</p><p>This occurs close to twice a month, so it’s safe to say that I need $50 every month for my gas which is $600 per year.</p><p><strong>Current Total Cost: $1,080 ($90/month)</strong></p><p>Does it still look like a lot? Let’s break it down even further. $1080 per year is roughly $90 per month!</p><p>The cost of having an extremely reliable car like the 2007 Honda Civic that will take you anywhere close to 600 miles at any given month cost less than two typical A+ Steam games ($49.99 each).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nget6-rY7BJjuMDIKb53NA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SVCyfnz5CqjNDKvmgHFmYA.jpeg" /><figcaption>I love my Honda.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=332564890ca2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Reusability Pattern For React Components]]></title>
            <link>https://medium.com/@rodoabad/the-reusability-pattern-for-react-components-7f10a73d8635?source=rss-8ea83dfb2b87------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f10a73d8635</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[patterns]]></category>
            <category><![CDATA[open-closed-principle]]></category>
            <category><![CDATA[components]]></category>
            <dc:creator><![CDATA[Rodo Abad]]></dc:creator>
            <pubDate>Sat, 02 Feb 2019 04:21:03 GMT</pubDate>
            <atom:updated>2019-02-02T07:32:09.860Z</atom:updated>
            <content:encoded><![CDATA[<h4>Finding the right balance when it comes to reusability is challenging when you’re working with multiple teams working on multiple projects. Here’s a list of patterns that we’ve adopted to ensure most of our consumers of our React components are happy.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*cFbWlt89sK7xijVDPFSMqg.jpeg" /></figure><blockquote>Most of these are pet peeves of mine where I start thinking–<em>Why can’t they just &lt;…&gt;?!</em></blockquote><h3>Open your component’s top level class to extension.</h3><p>This was one of the most requested features by our consumers when it came to overriding the styles for our components.</p><h4><strong>❌</strong>Before</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d3c89678f4d9af861b9776bb5e023f2/href">https://medium.com/media/7d3c89678f4d9af861b9776bb5e023f2/href</a></iframe><p>The example above limits consumers to overriding the current classes being used by “MyComponent” and it makes the noise level quite high if you’re using CSS modules.</p><h4><strong>✔️</strong>After</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/88107b662b3c3847db11bb2767e93037/href">https://medium.com/media/88107b662b3c3847db11bb2767e93037/href</a></iframe><p>We’ve added the <a href="https://www.npmjs.com/package/classnames">classnames</a> package to help us manage the external and internal classes a lot easier. Now the consumer can use their own class names if they want to override the styles.</p><h3>Allow your consumers to pass in additional props to your top level component.</h3><p>Let’s take into account our last component after adding the feature where consumers can use their own class names. This time, we’ve also added the feature where the consumer can set a custom greeting.</p><h4>❌Before</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd93fa99dfdae81465bb0449b0cfeee8/href">https://medium.com/media/dd93fa99dfdae81465bb0449b0cfeee8/href</a></iframe><p>Now let’s say the consumer wants to add an additional prop that was not specified, like a data-testid prop to enable tests to have a hook to MyComponent?</p><h4>✔️After</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a05fcac52625e5c659655d5c2f70ecd7/href">https://medium.com/media/a05fcac52625e5c659655d5c2f70ecd7/href</a></iframe><p>By making sure that you are accepting other props through otherProps and spreading them at the top level element, you are ensuring that whatever the consumer wants to add will be added to the top level element. Since we have already taken out className through destructuring, we do not need to worry about the consumer not being able to take advantage of classnames.</p><h3>Let your consumers customize the React components that you are using.</h3><p>The examples that I’ve provided have mostly been simple components so let’s add some more complexity by using other components.</p><h4>❌Before</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18cec679f6b34d410af694437d500cfa/href">https://medium.com/media/18cec679f6b34d410af694437d500cfa/href</a></iframe><p>We now have a Greeting component that consumes greeting as part of its message.</p><p>What if Greeting has other props like the colour of the message through color? You can’t use color anymore since it’s being used by Header. Now you have a collision that you want to avoid. You either rename color to headerColor and add greetingColor to solve the issue or stay with color and have greetingColor. You will continue to have this problems as your components get more complex.</p><p>Our first solution was to name space component props.</p><h4>❌First Iteration</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7c46ed4e5acf205c58d9446fd14d72c/href">https://medium.com/media/b7c46ed4e5acf205c58d9446fd14d72c/href</a></iframe><p>We could already see the problem when we want to scale this solution because if we want to use more props from either Header or Greeting then we have to modify MyComponent every single time — annoying especially when Header and Greeting also have their own Prop Types.</p><p>Our goal was to have the ability to extend but not necessarily modify the source code for MyComponent.</p><h4>✔️Latest Solution</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b8ed7eab556122b3b489ae13e48f48c/href">https://medium.com/media/7b8ed7eab556122b3b489ae13e48f48c/href</a></iframe><p>Here’s a list of advantages with this type of pattern that we really ❤️.</p><ul><li>If Header and Greeting are updated and you want to use them in MyComponent there is no need to update the implementation of MyComponent. The term we used was <em>it just works</em>.</li><li>Since this is a pattern that we will be using on our components then it is safe to assume that both Header and Greeting can also be extended the same way as MyComponent.</li></ul><p>Here is what it looks like on the consumer’s side.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a24e78ce463519a9c4e08cfc1f8794d0/href">https://medium.com/media/a24e78ce463519a9c4e08cfc1f8794d0/href</a></iframe><p>Let me know what you think and if you’re using this pattern, let me know as well! Maybe tweet me <a href="https://twitter.com/rodoabad">@rodoabad</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f10a73d8635" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Lesson In Code Structure]]></title>
            <link>https://medium.com/@rodoabad/a-lesson-in-code-structure-2806b0f850be?source=rss-8ea83dfb2b87------2</link>
            <guid isPermaLink="false">https://medium.com/p/2806b0f850be</guid>
            <category><![CDATA[concise-code]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[performant-code]]></category>
            <category><![CDATA[working-code]]></category>
            <category><![CDATA[clean-code]]></category>
            <dc:creator><![CDATA[Rodo Abad]]></dc:creator>
            <pubDate>Sun, 10 Jun 2018 07:51:55 GMT</pubDate>
            <atom:updated>2018-06-10T08:14:29.009Z</atom:updated>
            <content:encoded><![CDATA[<h4>These are a series of “lessons learned” that I’d like to share. Hopefully it helps your future you the next time you’re going to write some code.</h4><p>It’s late at night, I’m writing a couple of tools for my personal project to help me compute for adjusted dividend amounts based on the amount of applicable splits that happened for that stock option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dkUX3xLnNqw2OajGCfDOjw.gif" /><figcaption><a href="https://github.com/dibidendo/ui">https://github.com/dibidendo/ui</a></figcaption></figure><p>Here’s what I came up with.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce6025354faa0b76c371244ea18b26d8/href">https://medium.com/media/ce6025354faa0b76c371244ea18b26d8/href</a></iframe><p>We’ll start withadjustDividendAmountForSplits because that’s our entry point. I’ll give you a couple of minutes to digest what’s happening and let you ponder on the screw up. Just remember though, this code passes the tests that I’ve written. However, you should always remember that one of the things I do is — <em>refactor relentlessly</em>.</p><p>Still not seeing it? Maybe this will help.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3140ff6613624efde60d96dbf2a2c8a/href">https://medium.com/media/e3140ff6613624efde60d96dbf2a2c8a/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2dd58027a729f7cf42bdb24601440b49/href">https://medium.com/media/2dd58027a729f7cf42bdb24601440b49/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0880fcd16672b4cfbb1741247c84638/href">https://medium.com/media/e0880fcd16672b4cfbb1741247c84638/href</a></iframe><p>Now you’re seeing it and if you’re not here’s the screw up.</p><p>Look at applySplitsRatiosToMatchingDividendAmount and you’ll notice that this function is dependent on BigNumber, a Math library for JS. No problem right? We just do import BigNumber from &#39;bignumber.js&#39; and it should fix it. While true, that’s not what I wanted to show you. If you notice, the dividendAmount parameter has to be wrapped with BigNumber since it will be the first index in our accumulator. And that my friends is the problem because now we are expecting that the dividendAmount that will be passed as the argument to be always wrapped with BigNumber or else our function does not work [because we’re using the multipliedBy method available only to numbers wrapped in BigNumber]. You’ll also notice that I did exactly that in adjustDividendAmountForSplits where I am wrapping dividend.amount with BigNumber.</p><p>Let’s fix that.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/727ec6f31aae003a80e5aec02943ca31/href">https://medium.com/media/727ec6f31aae003a80e5aec02943ca31/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35523361f432a4b8115a5028bb8cffb4/href">https://medium.com/media/35523361f432a4b8115a5028bb8cffb4/href</a></iframe><p>Now applySplitRatiosToMatchingDividendAmount can take in a normal number for dividendAmount, all the BigNumber magic happens inside the function and not outside of it. <strong>Perfection</strong>.</p><p>We’ve also cleaned up adjustDividendAmountForSplits so that the only time BigNumber happens is when we’re adjusting the decimal places. Other than that, we’ll always be returning a number [hence toNumber()] and not an instance of BigNumber so that our functions are highly reusable.</p><p>Now I can sleep. Goodnight!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2806b0f850be" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reducing magic boilerplate and making your React unit tests a lot more concise]]></title>
            <link>https://medium.com/@rodoabad/reducing-magic-boilerplate-and-making-your-react-unit-tests-a-lot-more-concise-aa94053a1355?source=rss-8ea83dfb2b87------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa94053a1355</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[bdd]]></category>
            <category><![CDATA[magic]]></category>
            <category><![CDATA[unit-testing]]></category>
            <dc:creator><![CDATA[Rodo Abad]]></dc:creator>
            <pubDate>Wed, 11 Oct 2017 03:00:35 GMT</pubDate>
            <atom:updated>2017-10-12T16:45:47.457Z</atom:updated>
            <content:encoded><![CDATA[<h4>Because sometimes less is more — my everyday endeavour to refactor relentlessly.</h4><p>As a software engineer, we write a lot of tests every single day — it’s one of the many ways we protect what we ship from ourselves and from other engineers.</p><p>The more tests we write and encounter the more <strong>Magic</strong> we see happening in these tests. Sometimes we’ll ask ourselves— what just happened in this test? <strong>Magic</strong> occurs when we’re reading a spec and suddenly we have no idea where it got a specific value or something — tl;dr things just happened in that test’s scope.</p><h4>Say no to Magic boilerplate.</h4><p>Here are the following requirements — if you’re not using these tools then you will probably have a different pattern but most of the time they are the same.</p><ul><li>Mocha (testing framework)</li><li>Code (assertion library)</li><li>Enzyme (testing utility for React)</li></ul><p>Let’s assume for a second that this was the component that we’ve written tests for…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/612f76d18b174dd58d26cc7596488a2f/href">https://medium.com/media/612f76d18b174dd58d26cc7596488a2f/href</a></iframe><p>Judging from the code it’s a component that displays the taxable income and it has a label and value and the value is displayed in US dollars. In order for this component to render properly, a taxableIncome prop of type number is required.</p><h4>What does our test look like?</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bea0235ff7ac3a314c295c50125e98a9/href">https://medium.com/media/bea0235ff7ac3a314c295c50125e98a9/href</a></iframe><p>It all started out with us writing a test for the section. Why? Because that’s the first thing we need, then the test for the label and eventually the value being displayed. BDD done!</p><p>Let’s focus particularly on line’s 40 to 49 real quick. We can see that we’ve repetitively called props() 4 times. What a waste of time and effort because all we really want to know is — in order to <em>display the taxable income</em> we need the following to be true.</p><ol><li>It is FormattedNumber component and this component is a children of the current component that we’re rendering.</li><li>We should be using the following props in order for us to get the rendered HTML we want.</li></ol><p>Instead of expecting 4 times, why not expect it once and be done with it? In order for requirement #2 to happen, all these props have to be there all at once. In short we should be testing them as a group.</p><h4>Behold our first refactor iteration!</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a3e5d63cc60d905a05f51a7cf8f4b78/href">https://medium.com/media/3a3e5d63cc60d905a05f51a7cf8f4b78/href</a></iframe><p>One expect to solve our problem! We can do this because Enzyme’s props() method <a href="http://airbnb.io/enzyme/docs/api/ReactWrapper/props.html">returns an object</a>. We can then do a deep comparison with our expectedTaxableIncomeProps [Yay naming convention!] If you’re not seeing .deep.equal it’s because we’re using version 3.x of code which automatically does a deep comparison.</p><h4>Still not happy with this result.</h4><p>You’re probably asking yourself (and me), well Rodo where the hell does mockProps come from anyway? How did it find its way in our atomic test? [Magic!]</p><p>With mocha we typically use beforeEach() to set things up to run <em>before each</em> test. I personally used to be a fan of these helper methods but they are often abused in a larger code base with multiple contributors and it can become cumbersome to maintain let alone look up if you’re wondering where stuff came from.</p><p>Let’s get rid of that magic and make sure that the next person who looks at this piece of art knows exactly what is going on and we’ll save them the time to find out where things are coming from.</p><p>Here is our old test setup with beforeEach().</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17d7027abc035714bea42e34e7eceab1/href">https://medium.com/media/17d7027abc035714bea42e34e7eceab1/href</a></iframe><p>And here is the new one.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a4373ec06e9351ab9324ce1b980a903/href">https://medium.com/media/8a4373ec06e9351ab9324ce1b980a903/href</a></iframe><p>Let’s break this down real quick.</p><p>Instead of just assigning values to component and mockProps we wrote two methods that we can call to generate the required props with requiredProps() and to render the component with render().</p><p>Why requiredProps()? We call it required props because this is the props that is required for our component to work — this is our bare minimum.</p><p>Do we override our required props? No we don’t. We do however pass a new props argument in render() if we want new props. In fact we should not even care about the values being returned when calling requiredProps() because they are simply there to make it work. They are not there for asserting if the prop value is properly being set.</p><h4>How does our test look like now?</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa8bf5cf11d90014465e3a1697d5b9a5/href">https://medium.com/media/fa8bf5cf11d90014465e3a1697d5b9a5/href</a></iframe><p>Boom shakalaka! Let’s go over this refactored test in detail so we know what is going on in our atomic test.</p><p>We now have a prop object that has our requiredProps() and the taxableIncome value that we are expecting for our test. Oh but Rodo! requiredProps() also returns a taxableIncome value that you can expect later! Y U MEK 1MORE?! The answer is pretty simple, for this test, we want to make sure that the taxableIncome value that we’re generating originated from this test and not some random method. Remember what we said about requiredProps() values not being used for assertion? It’s for real, dawg. It really is there so that you do not get any prop warnings.</p><p>We then render()the component and pass the props we’ve declared at line 3. Just like what we mentioned in #1, we want to make sure that for this test the props that we’re sending are originating from this test alone.</p><p>And that’s it! We reduced the amount of expectations and our test is a lot more concise now.</p><h4>Final gist for you folks!</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/516fd6ac038d96e5b678aaa349770e4f/href">https://medium.com/media/516fd6ac038d96e5b678aaa349770e4f/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa94053a1355" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dividends, Dividends, Dividends — Putting My Earnings Into Perspective]]></title>
            <link>https://medium.com/@rodoabad/dividends-dividends-dividends-putting-my-earnings-in-perspective-35f1c123d939?source=rss-8ea83dfb2b87------2</link>
            <guid isPermaLink="false">https://medium.com/p/35f1c123d939</guid>
            <category><![CDATA[finance]]></category>
            <category><![CDATA[financial-independence]]></category>
            <category><![CDATA[dividends]]></category>
            <category><![CDATA[investing]]></category>
            <dc:creator><![CDATA[Rodo Abad]]></dc:creator>
            <pubDate>Sun, 09 Jul 2017 19:35:51 GMT</pubDate>
            <atom:updated>2017-07-14T01:25:12.426Z</atom:updated>
            <content:encoded><![CDATA[<h4>I started earning dividend income on one of my brokerage accounts back in May. Here’s a look at how it was three months back.</h4><p>Before this all started I was earning $0 per month, now I am earning at least $6 per month! $6 might not seem like a lot in today’s money but for me that is a free movie night or a meal from a decent restaurant — I can do one of those each month without taking money from my income stream!</p><blockquote>The best part of this is that it can only go up from here as I continue to put in money into this dividend growth taxable account per month. Since I won’t be taking any money from this account, that $6 per month will be used to buy even more stocks!</blockquote><p>I am currently putting in around <a href="https://medium.com/@rodoabad/putting-my-money-where-my-mouth-is-an-investing-experiment-with-dividend-growth-stocks-b7972b22751">$500 per month</a> in this account and from the looks of it, $500 earns me around $1.50 per month or around $4.50 per quarter. So, if I continue doing this then I will be going into double digits by the end of this year!</p><p>And to make things even better, I do believe that I will be earning money every month now since that was one of my early goals — to earn money each month instead of every quarter. Which is why I bought stocks that will not overlap one another (at least in the early days of this account). This makes it a joy to track so if you’re just starting out I recommend that you do this! It might not be ideal when it comes to maximizing profits but once you’re getting money each month the happier you’ll be!</p><p>One thing I’d like to add is that since I am using Robinhood for this account, I don’t have to pay any commission fees! One disadvantage though is that I cannot DRIP and I can only buy a full stock instead of a partial one. I don’t see that as a problem though because as I put in more money the income from the dividends will keep increasing until I can buy one or more stocks in the future! I would also like to invest my earnings in a different stock each time. Hooray for diversified portfolios!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35f1c123d939" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Putting my money where my mouth is— an investing experiment with dividend growth stocks.]]></title>
            <link>https://medium.com/@rodoabad/putting-my-money-where-my-mouth-is-an-investing-experiment-with-dividend-growth-stocks-b7972b22751?source=rss-8ea83dfb2b87------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7972b22751</guid>
            <category><![CDATA[investing]]></category>
            <category><![CDATA[money]]></category>
            <category><![CDATA[financial-independence]]></category>
            <category><![CDATA[dividends]]></category>
            <category><![CDATA[early-retirement]]></category>
            <dc:creator><![CDATA[Rodo Abad]]></dc:creator>
            <pubDate>Fri, 14 Apr 2017 03:17:53 GMT</pubDate>
            <atom:updated>2017-04-16T02:31:44.388Z</atom:updated>
            <content:encoded><![CDATA[<h4>Apart from retiring early I would like to be financially independent. and I’m going to start with $500 to achieve that goal.</h4><p>Everyone has to start somewhere right? To me that would mean that I will be setting aside a minimum of $500 per month from my take home salary and invest it on dividend growth stocks.</p><p>I plan on using a taxable account for this investing experiment and I will re-invest all the dividend income that I get back into this taxable account. Moreover, since I will most likely have at least one transaction per month I will be using <a href="https://www.robinhood.com/">Robinhood</a> as my broker to save on transaction fees.</p><h4>What about my 401K, IRA, and other investment accounts?</h4><p>Full disclosure here, I am already maxing my 401K and IRA accounts however, even though these and my other taxable investment accounts are earning dividends I will not include them since I consider these accounts as my over 65 years old retirement accounts so these accounts are automatically off-limits when concluding if I have reached FI (Financial Independence) or not. For this experiment we will only focus on one taxable account — the dividend growth stocks account to which I will be contributing a minimum of $500 per month.</p><blockquote>This is going to be excruciatingly slow at the start but I am prepared to deal with it mentally and financially.</blockquote><p>There is not going to be any magic of some sort happening here where suddenly I will be earning more than what I am spending in a few years. Believe me folks when I say that this is going to be a painful grind for me at the start. But since I have the power of compounding interest involved, I will be able to document what is going on and share my experiences with you guys.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7972b22751" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The bucket list: Justifying an impractical purchase]]></title>
            <link>https://medium.com/@rodoabad/the-bucket-list-justifying-an-impractical-purchase-75c6dd585f84?source=rss-8ea83dfb2b87------2</link>
            <guid isPermaLink="false">https://medium.com/p/75c6dd585f84</guid>
            <category><![CDATA[automotive]]></category>
            <category><![CDATA[cars]]></category>
            <category><![CDATA[lifestyle]]></category>
            <category><![CDATA[bucketlist]]></category>
            <category><![CDATA[work-life-balance]]></category>
            <dc:creator><![CDATA[Rodo Abad]]></dc:creator>
            <pubDate>Thu, 03 Nov 2016 02:13:05 GMT</pubDate>
            <atom:updated>2017-05-08T02:12:43.271Z</atom:updated>
            <content:encoded><![CDATA[<h4>How does a very frugal person [me] justify wasting money on an impractical purchase?</h4><p>Ever since I got behind the steering wheel of an automobile I’ve always enjoyed the drive and experience. I remember sitting on my father’s lap as he drove around the small streets of Manila and I will try and take control of the steering wheel — I was around two years old. Fast forward thirty-some years later and I still enjoy driving. I can drive for long periods of time and I will never get tired or bored regardless of what kind of automobile I drive. The longest one that I’ve done is from driving from Colorado to Toronto and back.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*vHUMcluuMNuvKwVn9K23pA.jpeg" /><figcaption>My 1990 Nissan 240SX SE</figcaption></figure><p>To me it’s not about the car that I’m driving but more about the journey itself. I’ve driven cars that are as old as me and I still enjoyed it— I don’t care as long as I get to drive. That’s all that matters.</p><p>I am now in my mid-thirties — well -paying job, homeowner, paid-off car, maxed-out retirement plans, investor, and currently <em>still</em> saving money.</p><blockquote>Life<em> </em>is<em> good </em>but not without major sacrifices.</blockquote><p>There’s nothing inherently wrong with what I did, it’s just that when I think about it I’ve never really rewarded myself with all that hard work. Sure I’ve made some huge purchases like a house and a normal car but those are in my humble opinion necessities — things that I <em>need</em>, not <em>want.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*Xtl5BBqy0tr9T2K-6MFeaA.jpeg" /><figcaption>My 2007 Honda Civic EX in Galaxy Gray Metallic</figcaption></figure><p>I’ve been slaving myself away since my early twenties trying to save as much money as I can. My life back then literally was <em>wake up, work,</em> and <em>sleep</em>. It was a boring life.</p><p>And lately, I’ve been thinking that maybe it’s finally time to reward myself before I settle down with my life — be a husband and a father.</p><blockquote>I want to buy a car with a true motorsport pedigree.</blockquote><p>A car that not only can take me from point A to point B but also a car that will put a smile on my face every time I drive it. That’s why I’m taking delivery of the new 2017 BMW M2 this year, a car that I bought as a gift for myself.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75c6dd585f84" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Red, Green, Refactor: Refactoring an action list unit test in Redux]]></title>
            <link>https://medium.com/@rodoabad/red-green-refactor-refactoring-an-action-list-unit-test-in-redux-cc169faa98c6?source=rss-8ea83dfb2b87------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc169faa98c6</guid>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[refactoring]]></category>
            <dc:creator><![CDATA[Rodo Abad]]></dc:creator>
            <pubDate>Sat, 01 Oct 2016 04:46:19 GMT</pubDate>
            <atom:updated>2016-10-01T04:49:16.308Z</atom:updated>
            <content:encoded><![CDATA[<h4>Red, Green, Refactor is a famous test-driven development mantra, where red means to write a failing test first and green means write code to make the failing test pass.</h4><p>Having an actions list is an important part of <a href="http://redux.js.org/docs/recipes/ReducingBoilerplate.html#actions">reducing the boilerplate</a> needed in <a href="http://redux.js.org/">Redux</a>. It helps keep your naming convention consistent since all the actions are located in one place. Something very important when you have a lot of collaborators working on a large project.</p><p>So let’s assume that your Redux-enhanced application already has a list of actions and each action already has a test for it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c1bb55bef539ea1700490cb9ee3e247/href">https://medium.com/media/5c1bb55bef539ea1700490cb9ee3e247/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ff34196d357d9ab33251500906de515/href">https://medium.com/media/6ff34196d357d9ab33251500906de515/href</a></iframe><p>Why are these tests important? It’s because you want to make sure that when you use <strong>CREATE_TODO</strong> that the action that you see logged is also called <strong>CREATE_TODO</strong> and not something else. You don’t want to be calling <strong>UPDATE_TODO</strong> and then have it appear as <strong>DELETE_TODO</strong> in your logger. Right? Exactly.</p><p>However, this can get very repetitive. And you can probably see where I’m going with this especially after line 12. If you need 100 actions, then you’ll need to write 100 tests. One for each action that you add.</p><p>So let’s take a step back and ask ourselves what do we really want to test…</p><ul><li>Is our action list immutable?</li><li>Does each action have the same key and value?</li></ul><h3>Time to refactor our test</h3><p>When we refactor our test we want to make sure that it still tests the behaviours that we want.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6c8093c263b9f098b4b72333bbc067b/href">https://medium.com/media/f6c8093c263b9f098b4b72333bbc067b/href</a></iframe><p>Our first refactor session is us removing the copy/paste behaviour to reduce test boilerplate and reduce the risk of forgetting to update the test description.</p><p>This happens a lot when you forget to take a double take on your tests.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/39bdd8d58d016f02e90392330d0e82a5/href">https://medium.com/media/39bdd8d58d016f02e90392330d0e82a5/href</a></iframe><p>By iterating over the <strong>actionsToTest</strong> array, we can also use it for writing our test descriptions through <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals">JavaScript template literals</a>. Now each test description is correct.</p><p>So far so good then. But what if we have someone else add an action without writing a test first?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21254aea130697a29be14ca2ff2b58ee/href">https://medium.com/media/21254aea130697a29be14ca2ff2b58ee/href</a></iframe><p>If we stick to our first refactor, then this test will still pass. So how do we prevent people from adding a new action first without testing it? Or at least making sure that each action added is tested?</p><p>The second refactor session is us removing the use of <strong>forEach</strong> and instead use a deep compare of the array against the object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62e73e80e38ab4852b921198b055188d/href">https://medium.com/media/62e73e80e38ab4852b921198b055188d/href</a></iframe><p>Now you have a guard against untested actions. But this is also a problem in itself because of this possible error.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2581f6b9ab5d94b6070ed91a1da1f28/href">https://medium.com/media/b2581f6b9ab5d94b6070ed91a1da1f28/href</a></iframe><p>Since we’re comparing the object <em>values </em>of <strong>actions</strong> against the object <em>values</em> of <strong>actionsToTest</strong> then as long as they look the same the test will pass.</p><p>So how do we fix this? By testing the object <em>keys </em>from <strong>actions</strong> against the object <em>values </em>of <strong>actionsToTest</strong>.</p><p>One thing to note though is that this is possible with the help of another tool — ESLint’s plugin <a href="https://github.com/jacobrask/eslint-plugin-sorting">eslint-plugin-sorting</a> which lets you sort your object properties alphabetically.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b15886b8fe4d90ec92125e7d372b0c53/href">https://medium.com/media/b15886b8fe4d90ec92125e7d372b0c53/href</a></iframe><p>Not only do you have a unit test that will test the following.</p><ul><li>Is your action list immutable?</li><li>Does each action have the same key and value?</li><li>Is each action tested?</li></ul><p>But you also have a unit test that scales.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc169faa98c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Asynchronous unit testing with MochaJS and ECMAScript 2016 (ES7) async/await]]></title>
            <link>https://medium.com/@rodoabad/asynchronous-unit-testing-with-mochajs-and-ecmascript-2016-es7-async-await-2d11de74932d?source=rss-8ea83dfb2b87------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d11de74932d</guid>
            <category><![CDATA[ecmascript-2016]]></category>
            <category><![CDATA[es7]]></category>
            <category><![CDATA[asynchronous]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[unit-testing]]></category>
            <dc:creator><![CDATA[Rodo Abad]]></dc:creator>
            <pubDate>Sun, 07 Aug 2016 03:59:50 GMT</pubDate>
            <atom:updated>2020-03-07T01:03:45.067Z</atom:updated>
            <content:encoded><![CDATA[<h4>This article assumes that the reader knows ECMAScript 2015 (ES6) syntax and MochaJS and is currently trying to refactor their asynchronous tests to ECMAScript 2016 (ES7).</h4><p>Let’s assume we already have a TDD’d method called <strong>getFruits</strong> and it calls <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch"><strong>fetch</strong></a><strong> </strong>to that will then respond with a collection (array) of fruits.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df5f26d3f4b06a32ddc1a53e20bcde3a/href">https://medium.com/media/df5f26d3f4b06a32ddc1a53e20bcde3a/href</a></iframe><p>The corresponding unit test for this looks like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/496b1d03bc857e7463a9c410a4617e6b/href">https://medium.com/media/496b1d03bc857e7463a9c410a4617e6b/href</a></iframe><p>Before we begin refactoring our unit test, let’s have a quick breakdown explaining why the fruits repository is being tested this way. You might also notice that I am using the BDD <a href="https://sites.google.com/site/unclebobconsultingllc/the-truth-about-bdd"><em>Given-When-Then</em></a> concept of writing test descriptions. This helps organize our test and makes it a lot easier to <a href="https://en.wikipedia.org/wiki/Grok">grok</a>.</p><p>We import four modules in our unit test file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/791d7648badb56eaa71f51b43d1e0c13/href">https://medium.com/media/791d7648badb56eaa71f51b43d1e0c13/href</a></iframe><p>We want to stub <strong>fetch</strong> with <strong>sinon</strong> because it is an external asynchronous call. We do this by stubbing the <strong>fetch</strong> method in the <strong>global</strong> object.</p><p>We will not stub <strong>fruits-repository</strong> because it is the <a href="https://en.wikipedia.org/wiki/System_under_test">System Under Test (SUT)</a>.</p><blockquote>Never stub the system that you are testing. Ever.</blockquote><p>You never stub the system that you are testing because by stubbing it you are then modifying the behaviour of the system that you want to test. By modifying the behaviour of your SUT, you are no longer able to test its actual behaviour which is the primary reason why you are writing a unit test anyway.</p><p>Before each test starts we will sandbox <strong>sinon</strong> stubs so that each stub that’s going to be used inside a test will be isolated. We then restore it to its original functionality after each test.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4bf0a0c421a4c21d8a119058081b958f/href">https://medium.com/media/4bf0a0c421a4c21d8a119058081b958f/href</a></iframe><p>Our first test is all about verifying that we actually call the <strong>fetch</strong> service every time we call <strong>getFruits</strong>.</p><blockquote>Given the fruits repository. When getting a collection of fruits. It should call fetch.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d6b591510e92be6689a7ce880b7b3dfc/href">https://medium.com/media/d6b591510e92be6689a7ce880b7b3dfc/href</a></iframe><p>Now that we’ve verified that we actually call <strong>fetch</strong> every time we try to get a collection of fruits, it’s time to find out if we get the data when the call is <em>successful.</em></p><p>Since we’ve stubbed <strong>fetch</strong> we need to stub some of the methods that we need inside of it like <a href="https://developer.mozilla.org/en-US/docs/Web/API/Body/json"><strong>json</strong></a>. By definition it returns a promise that resolves with an object literal containing the JSON data.</p><p>We also need to make sure that our resolving our promise will never run our <em>catch</em> clause. So we add a failing test where we check that <em>false</em> is equal to <em>true</em>.</p><blockquote>Given the fruits repository. When getting a collection of fruits and is successful. It should return an array of fruits.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a08d44e8cbefc8d2e085238cfc00979d/href">https://medium.com/media/a08d44e8cbefc8d2e085238cfc00979d/href</a></iframe><p>Now that we know that we’re getting the right data. We need to find out if we’re going to get the right error message when getting a collection of fruits is unsuccessful.</p><p>Just like our successful test, we need to make sure that rejecting the promise does not run the <em>then</em> clause.</p><blockquote>Given the fruits repository. When getting a collection of fruits and is unsuccessful. It should return an error object.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/92928f15aeae382b07453d30f9b557c5/href">https://medium.com/media/92928f15aeae382b07453d30f9b557c5/href</a></iframe><p>tl;dr</p><ul><li>Test if <strong>fetch</strong> is called with exactly the right arguments</li><li>Test the happy path — when service is successful</li><li>Test the sad path — when service is unsuccessful</li></ul><p>It’s now time to refactor our source file and its corresponding unit test.</p><blockquote>We already have <strong>Promise </strong>why do we need <strong>async/await</strong>?</blockquote><p><strong>async/await</strong> lets you feel like you’re writing synchronous code while still writing asynchronous code. For simple queries a <strong>Promise</strong> is easy to understand. However, as soon as requirements start getting more complex, having a synchronous feel greatly reduces complexity.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb368a18824d6b27b5529f3d8d341d0c/href">https://medium.com/media/fb368a18824d6b27b5529f3d8d341d0c/href</a></iframe><p>Now that we’re using <strong>async/await</strong> we can go back to using <strong>try/catch/finally</strong> which makes it feel like synchronous code.</p><p>Just like the source file we will refactor our unit test.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93d76f614120cabc7161d76cbdd4d6fc/href">https://medium.com/media/93d76f614120cabc7161d76cbdd4d6fc/href</a></iframe><p>Since can now use <strong>finally y</strong>ou will notice that our first test is now a lot easier to understand. The <strong>finally</strong> clause executes after the <strong>try</strong> and <strong>catch</strong> clauses execute. This is exactly what you need because regardless if your promise resolves or not, you want to know if <strong>fetch</strong> is called once and with exactly the right arguments.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e659eb543e622c1d8546ad38dd172604/href">https://medium.com/media/e659eb543e622c1d8546ad38dd172604/href</a></iframe><p>The same goes for our successful test expect instead of <em>finally</em> we’ll make sure that our <em>catch</em> clause never runs. And if it does, we should get alerted by a failing test.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/67e419a46053b01cc3a0296d688f61bf/href">https://medium.com/media/67e419a46053b01cc3a0296d688f61bf/href</a></iframe><p>As far as our unsuccessful test is concerned the <em>try</em> clause will always execute so there is no need to have an expected failing test.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a6d7d8896fa74adead3a3054fe84d7f/href">https://medium.com/media/6a6d7d8896fa74adead3a3054fe84d7f/href</a></iframe><p>And there you have it. You’ve refactored your asynchronous code to use <strong>async/await</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d11de74932d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Keeping your data models clean while still being able to extend it for your application with tcomb]]></title>
            <link>https://medium.com/@rodoabad/keeping-your-data-models-clean-while-still-being-able-to-extend-it-for-your-application-with-tcomb-eb8e72ec1777?source=rss-8ea83dfb2b87------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb8e72ec1777</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Rodo Abad]]></dc:creator>
            <pubDate>Sun, 05 Jun 2016 01:15:14 GMT</pubDate>
            <atom:updated>2016-06-08T03:26:51.346Z</atom:updated>
            <content:encoded><![CDATA[<h4>Sometimes our API data structure is not enough for our UI implementation because it is lacking properties and what not.</h4><p>Let’s assume that the data we’re getting from an API has the following structure — a list of employees that contain their first and last names.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee618007160c5595704fefa7b7967375/href">https://medium.com/media/ee618007160c5595704fefa7b7967375/href</a></iframe><p>Since we’re using <a href="https://github.com/gcanti/tcomb"><strong>tcomb</strong></a>, our data structure for this would be something like.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c13bda58cf414ee9f43c781ba4e1a0b9/href">https://medium.com/media/c13bda58cf414ee9f43c781ba4e1a0b9/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21172940656e2433a73efb6e1e3d4f8b/href">https://medium.com/media/21172940656e2433a73efb6e1e3d4f8b/href</a></iframe><p>However, we want to display these employees in a HTML list that contains checkboxes — each employee can be selected. So now we have to track if either an employee is selected or not.</p><p>The problem that we now have is that an Employee does not have a <em>selected</em> property that says whether the employee has been selected or not.</p><p>So why not just add a <em>selected</em> attribute to your Employee structure? Well, we can’t. That’s because the <em>struct </em>combinator drops additional properties when we add them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*7WuqV7cl_NXZTOnFT70xig.gif" /></figure><p>So how do we add additional properties without mutating the original data structure for an employee?</p><p>All <em>struct </em>constructors can be extended using the <em>extend</em> function. By using the extend function, we can now add an additional property to our employee.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db43499a4200ada2372d9ff77046946a/href">https://medium.com/media/db43499a4200ada2372d9ff77046946a/href</a></iframe><p>Here’s a working example of it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*I2luiGWJHRKcuNtHKo5ykg.gif" /></figure><p>So not only did we avoid mutating our original data structure for Employee but we’re also able to solve our problem of not having a property to track if an employee has been selected or not.</p><p>Now what if we need to send back a list of selected employees?</p><p>Sending back a data structure that is quite different from what you received should always be avoided. We want the back-end services to know exactly what type of structure they’re about to receive. Everything else should be discarded.</p><p><a href="https://github.com/gcanti/tcomb"><strong>tcomb</strong></a><strong> </strong>makes it easy to transform your data back to it’s original form. Since we know that passing unknown properties get discarded when using <em>struct</em>. All we have to do is use the Employee <em>struct</em> and pass <em>extendedEmployee</em> as the argument. By doing so, the Employee <em>struct</em> will discard all the extra properties that we’ve added in ExtendedEmployee.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/805119e9d932a266ac9e22ed892cd694/href">https://medium.com/media/805119e9d932a266ac9e22ed892cd694/href</a></iframe><p>If you prefer to see some animation…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*dd8yp3Ypn39ASrfoaq-CKg.gif" /></figure><p>Now you can send your list of employees back to your back-end without having to worry that you’ve changed the data structure.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb8e72ec1777" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>