<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Greggman</title>
    <description>The latest articles on DEV Community by Greggman (@greggman).</description>
    <link>https://dev.to/greggman</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F149349%2F7d97f206-e4e2-4fb5-9626-7802d9ac86cb.png</url>
      <title>DEV Community: Greggman</title>
      <link>https://dev.to/greggman</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/greggman"/>
    <language>en</language>
    <item>
      <title>[Rant] Github needs to fix their connections to Japan</title>
      <dc:creator>Greggman</dc:creator>
      <pubDate>Thu, 27 Aug 2020 09:11:35 +0000</pubDate>
      <link>https://dev.to/greggman/rant-github-needs-to-fix-their-connections-to-japan-4n93</link>
      <guid>https://dev.to/greggman/rant-github-needs-to-fix-their-connections-to-japan-4n93</guid>
      <description>&lt;p&gt;In particular downloading release files.&lt;/p&gt;

&lt;p&gt;Trying to install Electron it can often take &amp;gt; 10 minutes&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.stack.imgur.com/NPC4v.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1McTsTbm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.stack.imgur.com/NPC4v.png" alt="electron download progress"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That picture is after it said &amp;gt; 600 seconds and I thought to take a screenshot.&lt;/p&gt;

&lt;p&gt;It's not just at my home. I've seen this issue all over Japan on different machines over the last several years. I have even seen it using the free wifi at the Tokyo Amazon co-working space in the Amazon Tokyo headquarters (github release files are served from AWS!)&lt;/p&gt;

&lt;p&gt;When I bring it up with github they brush me off as "not our problem" but clearly it is their problem. &lt;/p&gt;

&lt;p&gt;I have a fast connection. I'm using NTT (the AT&amp;amp;T of Japan) with a 1gig fiber optic connection and So-Net (Sony's internet service). I can download games from Steam for example in quick. For example I just picked to install GTA5 in steam. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.stack.imgur.com/SZmy5.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gWzDsekZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.stack.imgur.com/SZmy5.png" alt="steam info"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see above it's going at 37.1 MB/s. Electron is only 72meg. If things were working correctly it should only take a few seconds, not &amp;gt; 10 minutes to download&lt;/p&gt;

&lt;p&gt;It's not just Steam. Most services are fast. &lt;a href="https://fast.com"&gt;Fast.com&lt;/a&gt;(netflix) reported 300Mbps last night. Right now it's at 160Mbps.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.imgur.com/eUcqlQO.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xxj0vBJb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/eUcqlQO.png" alt="netflix fast.com"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://projectstream.google.com/speedtest"&gt;Google's speedtest&lt;/a&gt; reports 198.27Mbps&lt;/p&gt;

&lt;p&gt;Google's Fiber test shows 30Mbps down, 199Mbps up from Tokyo to Los Angeles&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.imgur.com/VScGQL1.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1-baovfu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/VScGQL1.png" alt="google fiber speed"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'm bringing this here because it's a github related issue and github is a cornerstone of software development. The nice people staffed at github seem to be customer service reps reading from a customer service database instead of considering their impact on the devs around the world. It would be great if someone with the power to make stuff happen at github (or Microsoft) would give this issue more consideration.&lt;/p&gt;

&lt;p&gt;Ideally if they are going to be a backbone of development they need to mirror the files across the world instead of only serving from Seattle AWS (which is apparently what they are doing)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.blog/2014-01-07-faster-more-awesome-github-pages/"&gt;Github claims&lt;/a&gt; github pages are served by a "global content delivery network". Can that same network be used to speed up release files? Here's crossing my fingers. 🤞&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Forgetting to "npm install" solved...</title>
      <dc:creator>Greggman</dc:creator>
      <pubDate>Wed, 15 Jul 2020 20:51:03 +0000</pubDate>
      <link>https://dev.to/greggman/forgetting-to-npm-install-solved-1fa</link>
      <guid>https://dev.to/greggman/forgetting-to-npm-install-solved-1fa</guid>
      <description>&lt;p&gt;Does this sound familiar?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git pull upstream master
$ npm run build

ERROR! ERROR! ERROR! ERROR!
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;5 to 15 minutes of searching and finally&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm install
$ npm run build
build complete
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The dependencies changed, you didn't notice, and doh! Okay, maybe that only happens to me? 😊&lt;/p&gt;

&lt;p&gt;Well, you can fix that with &lt;a href="https://www.npmjs.com/package/ld-check-dependencies"&gt;&lt;code&gt;ld-check-dependencies&lt;/code&gt;&lt;/a&gt;. Just add it to your build script in your &lt;code&gt;package.json&lt;/code&gt; as in&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  ...
  "scripts": {
    "build": "ld-check-dependencies &amp;amp;&amp;amp; rollup ..."
  },
  ...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now when you build if your dependencies are out of date you'll get told to run &lt;code&gt;npm install&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The best part is &lt;code&gt;ld-check-dependencies&lt;/code&gt; is tiny. It's only 9 lines of code, 0 dependencies.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.flickr.com/photos/rikkis_refuge/417852540/in/photolist-CVB19-23yy9mP-7tvXnq-yH6zeh-88ajjg-aaG5fy-aaG5u3-aaDfMx-2fC8Cih-aaDg2a-6Nc2U5-4cBPUn-APXGL-akcjyG-KBhYrh-2eWvDdQ-QyWN5-6wf9X3-DjAUhY-wBGKb-6waXAB-7qiY5J-CxXcPy-6GsZNn-YyZXnb-VMEHRw-6waXxM-b8ihrP-JY2Esq-5RxZM-2cPtmLB-LXkbHK-apK3tG-533y9c-LJcyDA-2h8D7R4-21JLbaX-zVmx8v-dnwe8K-2cRot-z2vY47-2i7mp8R-2bPkvGr-29bL41A-bvWFYC-Le3Tbj-Kv52g6-MobcNj-2iSJTDd-2ehRrVk/"&gt;photo&lt;/a&gt; by: &lt;a href="https://www.flickr.com/photos/rikkis_refuge/"&gt;Rikki's Refuge&lt;/a&gt;&lt;/p&gt;

</description>
      <category>npm</category>
      <category>node</category>
    </item>
    <item>
      <title>Reduce Your Dependencies</title>
      <dc:creator>Greggman</dc:creator>
      <pubDate>Sat, 23 Nov 2019 03:47:29 +0000</pubDate>
      <link>https://dev.to/greggman/reduce-your-dependencies-1df6</link>
      <guid>https://dev.to/greggman/reduce-your-dependencies-1df6</guid>
      <description>&lt;p&gt;I recently wanted to add colored output to a terminal/command line program. I checked some other project that was outputting color and saw they were using a library called chalk.&lt;/p&gt;

&lt;p&gt;All else being equal I prefer smaller libraries to larger ones and I prefer to glue libraries together rather than take a library that tries to combine them for me. So, looking around I found &lt;a href="https://www.npmjs.com/package/chalk"&gt;chalk&lt;/a&gt;, &lt;a href="https://www.npmjs.com/package/colors"&gt;colors&lt;/a&gt;, and &lt;a href="https://www.npmjs.com/package/ansi-colors"&gt;ansi-colors&lt;/a&gt;. All popular libraries to provide colors in the terminal. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;chalk&lt;/strong&gt; is by far the largest with 5 dependencies totaling 3600 lines of code.&lt;/p&gt;

&lt;p&gt;Things it combines&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It combines checking whether or not the your output stream supports colors.  Because of this it has to add way to tell it don't check for me because I'll do the checking myself&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It peeks into your application's command line arguments magically looking for  &lt;code&gt;--color&lt;/code&gt; or &lt;code&gt;--no-color&lt;/code&gt; so without modifying your app or documenting what arguments are valid it will look at these arguments. If your app uses those arguments for something else you lose.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It combines all the named colors from HTML even though they are of  questionable usefulness in a terminal.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It includes 800 lines of code for color conversions so you can use rgb or hsl  or lab or cmyk etc.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next up is &lt;strong&gt;colors&lt;/strong&gt;. It's about 1500 lines of code.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It hacks the string prototype. The author seems to think this is not an issue.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It has a theme generator which works something like this&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setTheme&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;cool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;cold&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;hot&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And you can now do&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;the sun&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Like chalk it also spies on your command line arguments.&lt;/p&gt;

&lt;p&gt;Next up is &lt;strong&gt;ansi-color&lt;/strong&gt;. It's about 900 lines of code. It claims to be a clone of colors without the excess parts. No auto detecting support. No spying on your command line. It does include the theme function if only to try to match colors API.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why all these hacks and integrations?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Themes
&lt;/h3&gt;

&lt;p&gt;Starting with themes. chalk gets this one correct. They don't do anything. They just show you that it's trivial to do it yourself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;theme&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;cool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;chalk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;green&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;cold&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;chalk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;hot&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;chalk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;red&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;on fire&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Why add a function &lt;code&gt;setTheme&lt;/code&gt; just to do that? What happens if I go&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;colors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;red&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;green&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Yes you'd never do that but an API shouldn't be designed to fail. What was the point of cluttering this code with this feature when it's so trivial to do yourself?&lt;/p&gt;

&lt;p&gt;It gets worse though because a new user who sees &lt;code&gt;console.log(colors.hot(someMsg))&lt;/code&gt; will be effectively be taught that &lt;code&gt;colors.hot&lt;/code&gt; is an official API of &lt;code&gt;colors&lt;/code&gt;. Then'll then copy that to some other project and learn that in fact no, it's an app specific hack. If they had used more direct way it arguably becomes clear. I've had to help hundreds of users on stackoverflow where some example they saw had monkey patched on a non-standard feature to some object and then when they tried to use it in their own code they got an error and didn't understand why because it looked like part of the official API but wasn't.&lt;/p&gt;

&lt;h3&gt;
  
  
  Color Names
&lt;/h3&gt;

&lt;p&gt;It would arguably be better to just have them as separate libraries. Let's assume the color libraries have a function &lt;code&gt;rgb&lt;/code&gt; that takes an array of 3 values. Then you can do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pencil&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pencil&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;webColors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;color-name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;pencil&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;webColors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;burlywood&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;vs&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;chalk&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;chalk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;chalk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;keyword&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;burlywood&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some-string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In exchange for breaking the dependency you gain the ability to take the newest color set anytime color-name is updated rather than have to wait for chalk to update its deps. You also don't have 150 lines of unused JavaScript in your code if you're not using the feature which you weren't.&lt;/p&gt;

&lt;h3&gt;
  
  
  Color Conversion
&lt;/h3&gt;

&lt;p&gt;As above the same is true of color conversions&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pencil&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pencil&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;hsl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;color-convert&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hsl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;pencil&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;hsl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;))(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some-string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;vs&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;chalk&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;chalk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;chalk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hsl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some-string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Breaking the dependency 1500 lines are removed from the library that you&lt;br&gt;
probably weren't using anyway. You can update the conversion library if there are bugs or new features you want. You can also use &lt;a href="https://www.npmjs.com/package/chroma-js"&gt;other conversions&lt;/a&gt; and they won't have a different coding style.&lt;/p&gt;
&lt;h3&gt;
  
  
  Command Line hacks
&lt;/h3&gt;

&lt;p&gt;As mentioned above chalk looks at your command line behind the scenes. I don't know how to even describe how horrible that is.&lt;/p&gt;

&lt;p&gt;A library peeking at your command line behind the scenes seems like a really bad idea. To do this not only is it looking at your command line it's including another library to parse your command line. It has no idea how your command line works. Maybe you're shelling to another program and you have a &lt;code&gt;—-&lt;/code&gt; to separate arguments to your program from arguments meant for the program you spawn like Electron and npm. How would chalk know this? To fix this you have to hack around chalk using environment variables. But of course if the program you're shelling to also uses chalk it will inherit the environment variables requiring yet more workarounds. It's just simply a bad idea.&lt;/p&gt;

&lt;p&gt;Like the other examples, if your program takes command line arguments it's literally going to be 2 lines to do this yourself. One line to add &lt;code&gt;--color&lt;/code&gt; to your list of arguments and one line to use it to configure the color library. Bonus, your command line argument is now documented for your users instead of being some hidden secret.&lt;/p&gt;
&lt;h3&gt;
  
  
  Detecting a Color Terminal
&lt;/h3&gt;

&lt;p&gt;This is another one where the added dependency only detracts, not adds.&lt;/p&gt;

&lt;p&gt;We could just do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;colorSupport&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;color-support&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pencil&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pencil&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;pencil&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;enabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;colorSupport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hasBasic&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Was that so hard? Instead it chalk tries to guess on its own. There are plenty of situations where it will guess wrong which is why making the user add 2 lines of code is arguably a better design. Only they know when it's appropriate to auto detect. (PS: you may want to detect stderr separate from stdout via something like &lt;code&gt;colorSupport({stream: process.stderr}).hasBasic&lt;/code&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  Issues with Dependencies
&lt;/h2&gt;

&lt;p&gt;There are more issues with dependencies than just aesthetics and bloat though.&lt;/p&gt;

&lt;h3&gt;
  
  
  Dependencies = Less Flexible
&lt;/h3&gt;

&lt;p&gt;The library has chosen specific solutions. If you need different solutions you now have to work around the hard coded ones&lt;/p&gt;

&lt;h3&gt;
  
  
  Dependencies = More Risk
&lt;/h3&gt;

&lt;p&gt;Every dependency adds risks.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Risk there will be a security vulnerability&lt;/li&gt;
&lt;li&gt;Risk a dependency will be abandoned&lt;/li&gt;
&lt;li&gt;Risk the library you want to use will depend on a old outdated version of one of its dependencies&lt;/li&gt;
&lt;li&gt;Risk a malicious actor will compromise one of the dependencies&lt;/li&gt;
&lt;li&gt;Risk by expanding the number of people you have to trust.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You need to trust every contributor of every dependencies. A library with 5 dependencies probably has between 5 and 25 contributors. Assuming the high end that's 25 people you're trusting to always do the right thing each time the library is updated. Maybe &lt;a href="https://arstechnica.com/information-technology/2016/03/rage-quit-coder-unpublished-17-lines-of-javascript-and-broke-the-internet/"&gt;they got angry today and decided to take their ball  home&lt;/a&gt; or burn the world. Maybe they got offered $$$$$$$ to help &lt;a href="https://www.bleepingcomputer.com/news/security/npm-pulls-malicious-package-that-stole-login-passwords/"&gt;hack someone&lt;/a&gt;  and needed the money for their sick mom. Maybe they introduced a bug by accident or wrote a vulnerability by accident. Each dependency you add adds a larger surface area for these issues.&lt;/p&gt;

&lt;h3&gt;
  
  
  Dependencies = More Work for You
&lt;/h3&gt;

&lt;p&gt;Every dependency a library uses is one more you have to deal with. Library A gets discontinued. Library B has a security bug. Library C has a data leak. Library D doesn't run in the newest version of node, etc…&lt;/p&gt;

&lt;p&gt;If the library you were using didn't depend on A, B, C, and D all of those issues disappear. Less work for you. Less things to monitor. Less notifications of issues.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lower your Dependencies
&lt;/h2&gt;

&lt;p&gt;I picked on chalk and colors here because they're perfect examples of a poor tradeoffs. Their dependencies take at most 2 lines of code to provide the same functionality with out the dependencies so including them did nothing but add all the issues and risks listed above.&lt;/p&gt;

&lt;p&gt;It made more work for every user of chalk since they have to deal with the issues above. It even made more work for the developers of chalk who have to keep the dependencies up to date.&lt;/p&gt;

&lt;p&gt;For chalk, just like they have a small blurb in their readme on how to implement themes they could have just as easily shown how to do all the other things without the dependencies using &lt;strong&gt;just 2 lines of code!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I'm not saying you should never have dependencies. The point is you should evaluate if they are really needed. In the case of chalk it's abundantly clear they were not. If you're adding a library to npm please reduce your dependencies. If it only takes 1 to 3 lines to reproduce the feature without the dependency then just document what to do instead of adding a dep. Your library will be more flexible. You'll expose your users to less risks. You'll make less work for yourself because you won't have to keep updating your deps. You'll make less work for your users because they won't have to keep updating your library just to get new deps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Less dependencies = Everyone wins!&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>dependencies</category>
      <category>npm</category>
      <category>node</category>
    </item>
    <item>
      <title>Heavy Resource References in React</title>
      <dc:creator>Greggman</dc:creator>
      <pubDate>Tue, 26 Mar 2019 00:38:33 +0000</pubDate>
      <link>https://dev.to/greggman/heavy-resource-references-in-react-4466</link>
      <guid>https://dev.to/greggman/heavy-resource-references-in-react-4466</guid>
      <description>&lt;p&gt;I'm curious if there are any good examples or best practices of managing heavy resources with react. I'm not sure if I can give any good examples but I'll try.&lt;/p&gt;

&lt;p&gt;Typical heavy resources are images. Images seem to generally not be managed directly. They are referenced by URI and managed by magic behind the scenes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const MyComponent = () =&amp;gt; { return (
  &amp;lt;div class="recipe"&amp;gt;
    &amp;lt;div class="title"&amp;gt;Fruit Salad&amp;lt;/div&amp;gt;
    &amp;lt;div&amp;gt;
      &amp;lt;img src="images/banana.jpg" /&amp;gt;
      &amp;lt;img src="images/strawberry.jpg" /&amp;gt;
      &amp;lt;img src="images/grape.jpg" /&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
  &amp;lt;div class="recipe"&amp;gt;
    &amp;lt;div class="title"&amp;gt;Banana Split&amp;lt;/div&amp;gt;
    &amp;lt;div&amp;gt;
      &amp;lt;img src="images/ice-cream.jpg" /&amp;gt;
      &amp;lt;img src="images/banana.jpg" /&amp;gt;
      &amp;lt;img src="images/whipped-cream.jpg" /&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
)};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the example above react declares &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; tags but the resources themselves are managed by the browser. The browser magically looks at the &lt;code&gt;src&lt;/code&gt; property and loads the corresponding image. Even though both recipes refer to &lt;code&gt;banana.jpg&lt;/code&gt; the actual data for the image will only be loaded once. If this part of the tree of nodes is not part of the active DOM the browser is free to release all those images from memory.&lt;/p&gt;

&lt;p&gt;So, let's say we want to do something else just as resource intensive. I'm not sure what a good example is. Let's imagine it's a graph of sales.&lt;/p&gt;

&lt;p&gt;I see lots of libraries that do something like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const MyComponent = () =&amp;gt; { return (
  &amp;lt;MyGraphComponent xaxis="date" yaxis="amount"&amp;gt;
    &amp;lt;data&amp;gt;
      &amp;lt;datum xaxis="2012/01" yaxis="145" /&amp;gt;
      &amp;lt;datum xaxis="2012/02" yaxis="121" /&amp;gt;
      &amp;lt;datum xaxis="2012/03" yaxis="131" /&amp;gt;
      &amp;lt;datum xaxis="2012/04" yaxis="152" /&amp;gt;
      ... 2000 items ...
    &amp;lt;/data&amp;gt;
  &amp;lt;/MyGraphComponent&amp;gt;
)};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That seems wrong compared to the &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; example. Following the &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; example the data for the component should be external (orthogonal) to the &lt;code&gt;&amp;lt;MyGraphComponent&amp;gt;&lt;/code&gt;. Like &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; the data is not children in the graph rather it's something that should be referenced somehow so that multiple components can access the same data.&lt;/p&gt;

&lt;p&gt;Another example might be a 3D scene&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const MyComponent = () =&amp;gt; { return (
  &amp;lt;scene&amp;gt;
    &amp;lt;node transform="translate(10, 20, 30)"&amp;gt;
      &amp;lt;sphere radius="1" radialDivisions="100" verticalDivision="50" /&amp;gt;
      &amp;lt;material color="red"&amp;gt;
    &amp;lt;/node&amp;gt;
  &amp;lt;/scene&amp;gt;
)};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here again it looks innocent enough but again it's not following the example set by &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We can imagine a scene with multiple versions of the same sphere. Following the &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; example we'd imagine something more like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const MyComponent = () =&amp;gt; { return (
  &amp;lt;scene&amp;gt;
    &amp;lt;node transform="translateX(-5)" geometry="100-50-unit-sphere.geo" material="red-material" /&amp;gt;
    &amp;lt;node transform="translateX(0)"  geometry="100-50-unit-sphere.geo" material="red-material" /&amp;gt;
    &amp;lt;node transform="translateX(5)"  geometry="100-50-unit-sphere.geo" material="red-material" /&amp;gt;
  &amp;lt;/scene&amp;gt;
)};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;making it clearer the example above this one was probably the wrong model.&lt;/p&gt;

&lt;p&gt;We could try&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const MyComponent = () =&amp;gt; { return (
  const geometry = createSphere(100, 500);
  const material = createMaterial({color: 'red'});

  &amp;lt;scene&amp;gt;
    &amp;lt;node transform="translateX(-5)" geometry={geometry} material={material} /&amp;gt;
    &amp;lt;node transform="translateX(0)"  geometry={geometry} material={material} /&amp;gt;
    &amp;lt;node transform="translateX(5)"  geometry={geometry} material={material} /&amp;gt;
  &amp;lt;/scene&amp;gt;
)};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It's not clear how these would work. For &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; they are magically referenced by URIs but for other heavy resources it's much less clear what should happen and how they should be managed.&lt;/p&gt;

&lt;p&gt;Maybe by naming things?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const MyComponent = () =&amp;gt; { return (
  // only creates resource if resource for that name doesn't already exist
  createGeometry('100by500sphere', () =&amp;gt; { return new Sphere(100, 500); });
  createMaterial('redMaterial', () =&amp;gt; { return new Material({color: 'red'}); });

  &amp;lt;scene&amp;gt;
    &amp;lt;node transform="translateX(-5)" geometry="100by500sphere" material="redMaterial" /&amp;gt;
    &amp;lt;node transform="translateX(0)"  geometry="100by500sphere" material="redMaterial"  /&amp;gt;
    &amp;lt;node transform="translateX(5)"  geometry="100by500sphere" material="redMaterial"  /&amp;gt;
  &amp;lt;/scene&amp;gt;
)};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above has the strange property that we're making things by name and assuming no name conflicts. But, it does follow the &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; example and works just like &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; in that names (including path) have to be unique.&lt;/p&gt;

&lt;p&gt;Maybe another way would be to require declaring resources early like resource factories&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resourceManager.registerResources({
  '100by500sphere': () =&amp;gt; { return new Sphere(100, 500); },
  'redMaterial': () =&amp;gt; { return new Material({color: 'red'}); },
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;then elsewhere&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const MyComponent = () =&amp;gt; { return (
  &amp;lt;scene&amp;gt;
    &amp;lt;node transform="translateX(-5)" geometry="100by500sphere" material="redMaterial" /&amp;gt;
    &amp;lt;node transform="translateX(0)"  geometry="100by500sphere" material="redMaterial"  /&amp;gt;
    &amp;lt;node transform="translateX(5)"  geometry="100by500sphere" material="redMaterial"  /&amp;gt;
  &amp;lt;/scene&amp;gt;
)};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Assuming the registering of resources happens in one place the naming conflict issue disappears and like images resources are defined external to the part react is managing. Of course some would argue it's no fun to do it this way where you can't just declare stuff inline like the first 3D example&lt;/p&gt;

&lt;p&gt;And of course there is nothing saying the &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; way is the correct way. It's only the observation that the resources are not truly part of the tree of nodes being managed by React. They aren't children, they are orthogonal resources. And, that the only common similar examples in react are images, audio, and video, all of which are usually referenced by URI, not as children.&lt;/p&gt;

&lt;p&gt;Are there any good references for doing this in the true spirit of React?&lt;/p&gt;

</description>
      <category>react</category>
    </item>
  </channel>
</rss>
