<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
  xmlns:atom="http://www.w3.org/2005/Atom"
  xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Joe Zim&#39;s JavaScript Corner</title>
    <link>https://www.joezimjs.com/</link>
    <atom:link href="/feed/index.xml" rel="self" type="application/rss+xml"/>
    
    <description></description>
    <pubDate>Thu, 03 Jul 2025 04:08:31 GMT</pubDate>
    <generator>http://hexo.io/</generator>
    
    <item>
      <title>JavaScript&#39;s Tilde: Its Real Use Is No Mystery</title>
      <link>https://www.joezimjs.com/javascript/javascript-tilde-real-no-mystery/</link>
      <guid>https://www.joezimjs.com/javascript/javascript-tilde-real-no-mystery/</guid>
      <pubDate>Wed, 11 Apr 2018 05:00:00 GMT</pubDate>
      <description>
      
        The tilde is JavaScript operator that&#39;s not used very often. If you don&#39;t know what it is, you&#39;ve come to the right place to find out.
      
      </description>
      
      <content:encoded><![CDATA[<p>A while back I wrote an article titled <a href="/javascript/great-mystery-of-the-tilde/">“The Great Mystery of the Tilde”</a> where I tried to explain what the <code>~</code> (tilde) operator did in JavaScript. When trying to demystify what it was, I ended up perpetuating a lot of misinformation. I’m here to fix that today.<a id="more"></a></p><div style="text-align:center;"><!-- Ezoic - In Content - under_first_paragraph --><div id="ezoic-pub-ad-placeholder-107"><!-- JZJS - In Content Responsive --><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-0471240617528503" data-ad-slot="9785736525" data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div><!-- End Ezoic - In Content - under_first_paragraph --></div><h2 id="Setting-The-Facts-Straight"><a href="#Setting-The-Facts-Straight" class="headerlink" title="Setting The Facts Straight"></a>Setting The Facts Straight</h2><p>Normally, I don’t care too much about going back and updating old content, but my error was quite eggregious. Not only that: that post is the second most view post I had last year, so if I’m going to have that much traffic going to it, then I <strong><em>need</em></strong> to fix it, so I’ve added a paragraph to that post directing visitors to this new post, so that I can prevent future misinformation from spreading.</p><h2 id="So-What-Is-It"><a href="#So-What-Is-It" class="headerlink" title="So What Is It?"></a>So What Is It?</h2><p>The <code>~</code> operator in JavaScript is the <a href="https://en.wikipedia.org/wiki/Bitwise_operation#NOT" target="_blank" rel="noopener">Bitwise NOT operator</a>. If you don’t work with binary very often, then that probably doesn’t mean anything to you at all. Don’t worry, though, I’ll explain. If you have a number, say <code>8</code>, it looks like this in binary: <code>1000</code>. When you use the <code>~</code> on that number, it will convert each bit to the opposite value. That means, each <code>1</code> will become a <code>0</code> and vice versa. So <code>~8</code> would equal <code>7</code>, whose binary representation looks like this: <code>0111</code>. Or a <code>13</code> (<code>1101</code>) would become 2 (<code>0010</code>). The only problem is that JavaScript uses what is called <a href="https://en.wikipedia.org/wiki/Two%27s_complement" target="_blank" rel="noopener">“Two’s Complement”</a> in order to be able to represent positive and negative numbers in binary. So, because of this, in actuality, <code>~8</code> equals <code>-9</code>. If you want a better explanation than that, you’ll need to do some research on your own because I don’t feel adequate to explain it.</p><p>If you’re wondering what you would use this for (besides as a lame hack as I recommended in my previous article and that I no longer recommend)… so am I. I can find some examples on the internet for using bitwise operators, but I haven’t really seen a helpful example utilizing this particular operator. So, if you find a tilde in some JavaScript code you’re reading, then check out my old article linked above just to make sure they’re not using wrongly. If it doesn’t seem to be used hackily, then I guess you’ll have to let me know so I can see an example where it’s used correctly!</p><h2 id="Conclusion"><a href="#Conclusion" class="headerlink" title="Conclusion"></a>Conclusion</h2><p>So, now I hope this sets the record straight and that people being directed to the old post by Google will end up seeing this post. God bless and happy coding!</p>]]></content:encoded>
      
      <comments>https://www.joezimjs.com/javascript/javascript-tilde-real-no-mystery/#disqus_thread</comments>
    </item>
    
    <item>
      <title>How to Debug Android Chrome From Your Windows PC</title>
      <link>https://www.joezimjs.com/javascript/how-to-debug-android-chrome-from-your-windows-pc/</link>
      <guid>https://www.joezimjs.com/javascript/how-to-debug-android-chrome-from-your-windows-pc/</guid>
      <pubDate>Tue, 10 Apr 2018 05:00:00 GMT</pubDate>
      <description>
      
        Hook your Android phone up to your desktop Chrome&#39;s developer tools in order to more easily develop and debug mobile websites.
      
      </description>
      
      <content:encoded><![CDATA[<p>Debugging mobile websites is next to impossible when all you have is your phone, but if you have a Windows PC, you can use Google Chrome’s developer tools to connect to your Android phone and debug it from there, making the experience infinitely better. In this video, I’ll show you how to get set up to do that.<a id="more"></a></p><div style="text-align:center;"><!-- Ezoic - In Content - under_first_paragraph --><div id="ezoic-pub-ad-placeholder-107"><!-- JZJS - In Content Responsive --><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-0471240617528503" data-ad-slot="9785736525" data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div><!-- End Ezoic - In Content - under_first_paragraph --></div><h2 id="Video"><a href="#Video" class="headerlink" title="Video"></a>Video</h2><div class="video-container"><iframe src="//www.youtube.com/embed/9H6B-oIVYIA" frameborder="0" allowfullscreen></iframe></div><h2 id="Steps"><a href="#Steps" class="headerlink" title="Steps"></a>Steps</h2><p>You can find a fully fleshed out written tutorial on the <a href="https://raygun.com/blog/debug-android-chrome/" target="_blank" rel="noopener">Raygun blog</a>. Here, I’ll just list the steps out pretty quickly. You can also find everything you need for setting up your PC and Android phone for Chrome debugging in the video above.</p><ol><li>Turn on Developer Options and USB Debugging on your phone.</li><li><a href="https://developer.android.com/studio/run/oem-usb.html" target="_blank" rel="noopener">Install USB drivers</a> for your Android device on your PC.</li><li><a href="https://forum.xda-developers.com/showthread.php?t=2317790" target="_blank" rel="noopener">Install ADB server</a> and run it on your PC.</li><li>Enable Chrome developer tools to “Discover USB devices” in the “Remote devices” tab on your PC.</li><li>Connect your Android device to your PC via USB.</li><li>Allow USB debugging on your phone, when the popup shows up.<ul><li>If that popup doesn’t show up, change connection type to PTP on your phone first.</li></ul></li><li>Open the “Remote devices” tab in the dev tools and click on your Android device listed on the left.</li><li>Focus the tab you wish to inspect and then click the “Inspect” button for that tab.</li></ol><h2 id="Conclusion"><a href="#Conclusion" class="headerlink" title="Conclusion"></a>Conclusion</h2><p>And there you go! You’ve now got a remote debugging session running on your PC for your Android device. You should be able to do pretty much anything with it that you would normally do on a desktop website. God bless and happy coding!</p>]]></content:encoded>
      
      <comments>https://www.joezimjs.com/javascript/how-to-debug-android-chrome-from-your-windows-pc/#disqus_thread</comments>
    </item>
    
    <item>
      <title>Pure CSS Slide-Down Animation</title>
      <link>https://www.joezimjs.com/javascript/pure-css-slide-down-animation/</link>
      <guid>https://www.joezimjs.com/javascript/pure-css-slide-down-animation/</guid>
      <pubDate>Thu, 15 Feb 2018 12:00:00 GMT</pubDate>
      <description>
      
        Slide-down CSS animations are surprisingly difficult if you don&#39;t know the height of the element you want to animate. Here&#39;s a trick you can use instead.
      
      </description>
      
      <content:encoded><![CDATA[<p>Sometimes something seems like it should be really easy, but it turns out to be extremely difficult. The case we’ll be checking out today is creating a slide-down animation using purely CSS. What could be so hard about that, right? Note: I’m aware this is a JavaScript site, but we’re all front-end developers here, so I’m sure this will appeal to many of you.<a id="more"></a></p><div style="text-align:center;"><!-- Ezoic - In Content - under_first_paragraph --><div id="ezoic-pub-ad-placeholder-107"><!-- JZJS - In Content Responsive --><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-0471240617528503" data-ad-slot="9785736525" data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div><!-- End Ezoic - In Content - under_first_paragraph --></div><h2 id="What-Are-We-Talking-About"><a href="#What-Are-We-Talking-About" class="headerlink" title="What Are We Talking About?"></a>What Are We Talking About?</h2><p>If you’re not sure what I mean by a “slide-down animation”, check out the <a href="http://api.jquery.com/slideDown/" target="_blank" rel="noopener"><code>slideDown</code> method from jQuery</a>. This function will take a hidden element and make it visible by increasing the element’s height from 0 to whatever the height of the element should be. That shouldn’t be too hard, right?</p><h2 id="How-You-Might-Try-To-Do-It"><a href="#How-You-Might-Try-To-Do-It" class="headerlink" title="How You Might Try To Do It"></a>How You Might Try To Do It</h2><p>Let’s take a look at some quick ideas of how you might expect to be able to do this easily. If you simply go by what I said earlier, you’d just set the <code>height</code> to 0, and then to expand it, set the <code>height</code> to the number that shows the whole element (with a <code>transition</code> as well; this is assumed for all of them, otherwise it won’t be an animation). Something like this:</p><p data-height="300" data-theme-id="0" data-slug-hash="NygYJy" data-default-tab="css,result" data-user="joezimjs" data-embed-version="2" data-pen-title="Pure CSS Slide Down Animation 0" data-preview="true" class="codepen">See the Pen <a href="https://codepen.io/joezimjs/pen/NygYJy/" target="_blank" rel="noopener">Pure CSS Slide Down Animation 0</a> by Joe Zim (<a href="https://codepen.io/joezimjs" target="_blank" rel="noopener">@joezimjs</a>) on <a href="https://codepen.io" target="_blank" rel="noopener">CodePen</a>.</p><p><strong>Note</strong>: This is using <code>:target</code> and links to activate the animations, so the links aren’t toggles. You’ll need to go back in the frame’s history or press “Rerun” to toggle them off.</p><p>Note that it works perfectly! Problem solved right? Yes and no. This works perfectly if you know the height of the element, but what if you don’t know the height. We’ll need a generic animation that will work no matter what height the element is. This is especially true on a responsive site, where the height can change depending on screen size.</p><p>In this case, the seemingly obvious solutions is to just set the <code>height</code> to <code>auto</code> in the expanded version’s styles.</p><p data-height="300" data-theme-id="0" data-slug-hash="qxjYqN" data-default-tab="css,result" data-user="joezimjs" data-embed-version="2" data-pen-title="Pure CSS Slide Down Animation 1" data-preview="true" class="codepen">See the Pen <a href="https://codepen.io/joezimjs/pen/qxjYqN/" target="_blank" rel="noopener">Pure CSS Slide Down Animation 1</a> by Joe Zim (<a href="https://codepen.io/joezimjs" target="_blank" rel="noopener">@joezimjs</a>) on <a href="https://codepen.io" target="_blank" rel="noopener">CodePen</a>.</p><p>Oh how I wish this worked. This would make everything so much easier, but sadly transitions only work on numeric values. Sure, <code>auto</code> does eventually compute to a numeric value, but that message doesn’t seem to get to <code>transition</code>, so it just pops right open instead of doing a nice animation.</p><p>So what can we do? How about CSS Transforms? We’ll set <code>scaleY</code> to zero and then set it to one when it should be expanded. Will that work?</p><p data-height="300" data-theme-id="0" data-slug-hash="zRzjzG" data-default-tab="css,result" data-user="joezimjs" data-embed-version="2" data-pen-title="Pure CSS Slide Down Animation 2" data-preview="true" class="codepen">See the Pen <a href="https://codepen.io/joezimjs/pen/zRzjzG/" target="_blank" rel="noopener">Pure CSS Slide Down Animation 2</a> by Joe Zim (<a href="https://codepen.io/joezimjs" target="_blank" rel="noopener">@joezimjs</a>) on <a href="https://codepen.io" target="_blank" rel="noopener">CodePen</a>.</p><p>When you use a transform, it doesn’t actually change the amount of space it takes up, so there are big gaps between the links instead of making that area appear at the same time the element starts expanding. So this isn’t working either. So how about we take a look at the method that I discovered.</p><h2 id="The-Answer"><a href="#The-Answer" class="headerlink" title="The Answer"></a>The Answer</h2><p data-height="300" data-theme-id="0" data-slug-hash="bLRMom" data-default-tab="result" data-user="joezimjs" data-embed-version="2" data-pen-title="Pure CSS Slide Down Animation 3" data-preview="true" class="codepen">See the Pen <a href="https://codepen.io/joezimjs/pen/bLRMom/" target="_blank" rel="noopener">Pure CSS Slide Down Animation 3</a> by Joe Zim (<a href="https://codepen.io/joezimjs" target="_blank" rel="noopener">@joezimjs</a>) on <a href="https://codepen.io" target="_blank" rel="noopener">CodePen</a>.</p><p>The answer is to set everything that can affect height (e.g. vertical padding, line-height, etc.) to 0 and then set it to the value you’d like when expanded. You need to be careful with this because there are lots of things that can affect height. For example, if there were multiple paragraphs of text inside the element, you’d need to adjust the margins between those paragraphs. If you have any images, you’ll need to make sure the height and vertical margins around it are also set to 0. This works better than just using height since you’re far more likely to know the values of each of these properties than you are to know the height of the expandable element.</p><p><strong>Note</strong>: I also set the text color to toggle between transparent and black to give it a fading look. This is not necessary, but looks a little nicer. You can also accomplish this with <code>opacity</code>.</p><h2 id="Conclusion"><a href="#Conclusion" class="headerlink" title="Conclusion"></a>Conclusion</h2><p>I’ve spend days trying to figure this out in the past. There just had to be a way! But aside from using JavaScript, which is also pretty complicated, I just couldn’t figure it out for the longest time. Now that I have it figured out, I hope it can help you as well. God bless and happy coding!</p><script async src="https://production-assets.codepen.io/assets/embed/ei.js"></script>]]></content:encoded>
      
      <comments>https://www.joezimjs.com/javascript/pure-css-slide-down-animation/#disqus_thread</comments>
    </item>
    
    <item>
      <title>How to Make Drag-and-Drop File Uploaders</title>
      <link>https://www.joezimjs.com/javascript/vue-test-coverage-and-drag-and-drop/</link>
      <guid>https://www.joezimjs.com/javascript/vue-test-coverage-and-drag-and-drop/</guid>
      <pubDate>Wed, 24 Jan 2018 22:42:23 GMT</pubDate>
      <description>
      
        I&#39;ve done a lot of writing lately. Topics cover Vue, unit testing, dev tools, test coverage, drag and drop, and more. Which are you looking for?
      
      </description>
      
      <content:encoded><![CDATA[<p>In keeping with the latest trend for this website, I’ve been writing for other blogs instead of this one. Here’s some that I’ve done for Smashing Magazine on Drag and Drop File Uploaders.<a id="more"></a></p><div style="text-align:center;"><!-- Ezoic - In Content - under_first_paragraph --><div id="ezoic-pub-ad-placeholder-107"><!-- JZJS - In Content Responsive --><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-0471240617528503" data-ad-slot="9785736525" data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div><!-- End Ezoic - In Content - under_first_paragraph --></div><h2 id="How-To-Make-A-Drag-and-Drop-File-Uploader-With-Vanilla-JavaScript"><a href="#How-To-Make-A-Drag-and-Drop-File-Uploader-With-Vanilla-JavaScript" class="headerlink" title="How To Make A Drag-and-Drop File Uploader With Vanilla JavaScript"></a>How To Make A Drag-and-Drop File Uploader With Vanilla JavaScript</h2><p><em><a href="https://www.smashingmagazine.com/2018/01/drag-drop-file-uploader-vanilla-js/" target="_blank" rel="noopener">How To Make A Drag-and-Drop File Uploader With Vanilla JavaScript</a></em> is a tutorial on exactly what it says it is. Without using a single library or framework, we learn how to build a drag-and-drop file uploader. We also cover how to use fallbacks for older or less capable browsers while also exploring some extra features that can be added to the uploader to enhance the user experience.</p><h2 id="How-To-Make-A-Drag-and-Drop-File-Uploader-With-Vue-js-3"><a href="#How-To-Make-A-Drag-and-Drop-File-Uploader-With-Vue-js-3" class="headerlink" title="How To Make A Drag-and-Drop File Uploader With Vue.js 3"></a>How To Make A Drag-and-Drop File Uploader With Vue.js 3</h2><p><em><a href="https://www.smashingmagazine.com/2022/03/drag-drop-file-uploader-vuejs-3/" target="_blank" rel="noopener">How To Make A Drag-and-Drop File Uploader With Vue.js 3</a></em> takes that previous tutorial and converts it to use Vue, which, because of its declarative nature, actually looks quite different despite doing essentially the same things. It also upgrades the uploader to have a more informative and prettier interface, because why not?</p><h2 id="What’s-Coming-To-VueX"><a href="#What’s-Coming-To-VueX" class="headerlink" title="What’s Coming To VueX?"></a>What’s Coming To VueX?</h2><p><em><a href="https://www.smashingmagazine.com/2020/12/vuex-library/" target="_blank" rel="noopener">What’s Coming To VueX?</a></em> looks at the big plans for changes in Vuex version 5 (what later ended up becoming <a href="https://pinia.vuejs.org/" target="_blank" rel="noopener">Pinia</a> instead of a new version of Vuex) that make it more intuitive to use with fewer hoops to jump through. This article ended up getting me invited to be a guest on the <a href="https://topenddevs.com/podcasts/views-on-vue/episodes/the-future-of-vue-stores-with-joseph-zimmerman-vue-151" target="_blank" rel="noopener">Views on Vue podcast</a>.</p><h2 id="Using-Slots-In-Vue-js"><a href="#Using-Slots-In-Vue-js" class="headerlink" title="Using Slots In Vue.js"></a>Using Slots In Vue.js</h2><p>*<a href="https://www.smashingmagazine.com/2019/07/using-slots-vue-js/" target="_blank" rel="noopener">Using Slots In Vue.js</a> discusses how to use slots in Vue, especially focusing on the changes made in Vue 2.6 to simplify the use of slots.</p><h2 id="Conclusion"><a href="#Conclusion" class="headerlink" title="Conclusion"></a>Conclusion</h2><p>That’s all for now. If there’s something you’d like me to write about, whether it’s directly on this blog or on a different blog, leave me a comment below! God bless and happy coding!</p>]]></content:encoded>
      
      <comments>https://www.joezimjs.com/javascript/vue-test-coverage-and-drag-and-drop/#disqus_thread</comments>
    </item>
    
    <item>
      <title>Teaching Kids JavaScript</title>
      <link>https://www.joezimjs.com/javascript/teaching-kids-javascript/</link>
      <guid>https://www.joezimjs.com/javascript/teaching-kids-javascript/</guid>
      <pubDate>Wed, 04 Oct 2017 18:00:00 GMT</pubDate>
      <description>
      
        Some ideas and places to get starting if you want to teach your children JavaScript or general programming.
      
      </description>
      
      <content:encoded><![CDATA[<p>Lots of kids are starting to learn to code these days, and I’m proud to join the movement to get even more kids coding. While <a href="https://scratch.mit.edu" target="_blank" rel="noopener">Scratch</a> is a popular starter language for younger kids, we’ve seen that when kids get to about 10-11, transitioning them to Javascript is a great next step.<a id="more"></a></p><div style="text-align:center;"><!-- Ezoic - In Content - under_first_paragraph --><div id="ezoic-pub-ad-placeholder-107"><!-- JZJS - In Content Responsive --><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-0471240617528503" data-ad-slot="9785736525" data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div><!-- End Ezoic - In Content - under_first_paragraph --></div><h2 id="Transitioning-with-Code-Combat"><a href="#Transitioning-with-Code-Combat" class="headerlink" title="Transitioning with Code Combat"></a>Transitioning with Code Combat</h2><p><img src="https://server.thecoderschool.com/images/blog/code combat.png" alt="Code Combat"></p><p>A fairly structured way to get a young student to their first typed language is <a href="https://codecombat.com" target="_blank" rel="noopener">Code Combat</a>, which supports Javascript (and Python). The platform is a great game-ified way to learn to code, as kids solve puzzles and defeat enemies through Javascript code. Fun for even some of us more seasoned coders! While the graphics and game play are addicting and fun, we’ve found Code Combat to be more of a short-term solution for exposure, so we tend to use it in short bursts. After all, nothing beats unrestricted straight up Javascript coding!</p><h2 id="Unstructured-JS-Coding"><a href="#Unstructured-JS-Coding" class="headerlink" title="Unstructured JS Coding"></a>Unstructured JS Coding</h2><p>To start kids off on their first Javascript “apps”, we’ll often use <a href="https://codepen.io" target="_blank" rel="noopener">Codepen</a> or a similar online IDE like <a href="https://jsfiddle.net" target="_blank" rel="noopener">JS Fiddle</a>. Most Javascript coders know and use these platforms often, so we’ll leave it at that. We might start kids off with some simple stuff like DOM manipulation - number generators, simple calculators, etc. Kids tend to like interactive things, graphical things - kinda perfect for Javascript in the browser!</p><h2 id="Advanced-JS-with-PlayCanvas"><a href="#Advanced-JS-with-PlayCanvas" class="headerlink" title="Advanced JS with PlayCanvas"></a>Advanced JS with PlayCanvas</h2><p><img src="https://server.thecoderschool.com/images/blog/PlayCanvas Project.png" alt="PlayCanvas Screen"></p><p>For our more advanced students (with our more advanced Coaches), one cool option is a 3D Engine called <a href="https://playcanvas.com" target="_blank" rel="noopener">Play Canvas</a>. By the time you say “3D”, you’ve hook 90% of the kids, and if you add “game engine”, you’re done! PlayCanvas supports rigid-body physics simulation, handling three-dimensional audio (yeah!), 3D animations, and a boatload of other stuff if you have the time to look through it. It’s got a great set of <a href="https://developer.playcanvas.com/en/tutorials/" target="_blank" rel="noopener">tutorials</a> you can check out too.</p><p>Quick caveat, take a quick click through to <a href="https://playcanvas.com" target="_blank" rel="noopener">Play Canvas</a> or even just read some of the functionality above, and you’ll sense right away that this isn’t easy-breezy stuff for kids. The tool itself can be a steep rampup especially for kids, so we’re always careful with balancing tool learning vs. Javascript learning. The instructor (what we call a Code Coach) may need to do some pre-setup for some kids - creating a 3D app from scratch is often quite hard for most kids.</p><h3 id="PlayCanvas-Project-Ideas"><a href="#PlayCanvas-Project-Ideas" class="headerlink" title="PlayCanvas Project Ideas"></a>PlayCanvas Project Ideas</h3><p><img src="https://server.thecoderschool.com/images/blog/PC Asteroids.png" alt="3D Asteroids"></p><p>PlayCanvas comes with a basic tutorial that kids can use to change up a little. One of our students created a <a href="https://playcanv.as/p/a0a4520e/" target="_blank" rel="noopener">cool little challenge</a> by turning the ball into a watermelon and adding some deadly spikes as an obstacle. I’ve tried about 50 times and still can’t get the watermelon across the spikes! We’ve also defaulted to good old spaceship games, like this one a student of ours created of a <a href="http://playcanv.as/p/x1pI7UXC/" target="_blank" rel="noopener">3D Asteroids game</a>.</p><p><img src="https://server.thecoderschool.com/images/blog/blender spinner.png" alt="Spinner on Blender"></p><p>Another project idea that we’ve done is to allow your student to design and even 3D print out their own fidget spinner. A little past the trend, but hey, kids still love the stuff! For the actual 3D print, we used <a href="https://www.blender.org" target="_blank" rel="noopener">Blender</a>, but in PlayCanvas you can recreate it with a student, and get it spinning just like in real life. The Instructor/Code Coach might need to get a basic spinner ready to go, along with a rotation script, allowing the kids to change rotation speeds or even chuck balls at it - but when you’re talking fidget spinners, you’ll get any kid engaged and having fun!</p><p>There’s lots of great platforms out there to help kids code JavaScript and other languages, such as <a href="https://junilearning.com/blog/guide/why-every-kid-should-learn-to-code/" target="_blank" rel="noopener">Juni Learning</a>. PlayCanvas happens to be one of the cool ones we use, but it’s really only one of many. Don’t forget, in the end it’s about balancing kids’ engagement and fun with hardcore coding. Don’t stray too far in either direction! Happy Coding! (ps, high five to Joe for letting me jump in on a guest post!)</p><hr><p>For more resources on how to teach coding to your kids, feel free to visit <a href="https://blogging.com/kids-coding/" target="_blank" rel="noopener">Coding For Kids</a>.</p>]]></content:encoded>
      
      <comments>https://www.joezimjs.com/javascript/teaching-kids-javascript/#disqus_thread</comments>
    </item>
    
    <item>
      <title>Presenting: Optimizing JavaScript Web App Performance With Webpack</title>
      <link>https://www.joezimjs.com/javascript/presenting-optimizing-js-web-app-performance-webpack/</link>
      <guid>https://www.joezimjs.com/javascript/presenting-optimizing-js-web-app-performance-webpack/</guid>
      <pubDate>Tue, 28 Mar 2017 19:00:00 GMT</pubDate>
      <description>
      
        Bundling is far from the only thing that webpack can do to improve the performance of your web applications. Wanna hear about it?
      
      </description>
      
      <content:encoded><![CDATA[<p>Bundling is far from the only thing that webpack can do to improve the performance of your web applications. Wanna hear about it?<a id="more"></a></p><h2 id="Speaking"><a href="#Speaking" class="headerlink" title="Speaking"></a>Speaking</h2><p>I actually already talked about it at <a href="http://newcodecamp.com/" target="_blank" rel="noopener">NEW Code Camp</a> in Appleton, Wisconsin last Saturday. I spent some late nights preparing for it and didn’t feel as ready as I wanted to, but it went off alright.</p><p>Today and tomorrow, I’ll be refining the presentation some more and will be presenting it again at the <a href="https://www.meetup.com/Central-WI-Developers-Group/" target="_blank" rel="noopener">Central Wisconsin Developer’s Group</a> on March 30 at 6PM. If you want to hear the presentation, you can find all the details on that meetup page I linked to.</p><p>At some point in the future I plan to write an article about it. And I hope I can do it soon. I want to be able to put some content on here other than letting you know what I’ve done recently and what I plan on doing in the future.</p><div style="text-align:center;"><!-- Ezoic - In Content - under_first_paragraph --><div id="ezoic-pub-ad-placeholder-107"><!-- JZJS - In Content Responsive --><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-0471240617528503" data-ad-slot="9785736525" data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div><!-- End Ezoic - In Content - under_first_paragraph --></div><h2 id="Comprehensive-Guide-to-webpack-Course"><a href="#Comprehensive-Guide-to-webpack-Course" class="headerlink" title="Comprehensive Guide to webpack Course"></a>Comprehensive Guide to webpack Course</h2><p>That doesn’t mean I don’t still have things I want to say about the future! I just wanted to remind you (assuming you’ve already read it in a previous article) or inform you (if you were unaware) that I’m currently working an a course that will exhaustively cover webpack’s capabilities. It won’t obviously cover many of the more obscure plugins and such, but it’ll show you everything you really need to know.</p><p>To sign up to receive updates about the progress and to get 50% off when the course is released, click the link below:</p><blockquote><p><del><a href="#">Click Here to Sign Up</a>.</del></p></blockquote><p>I’ve already written 8,000 words just <a href="https://www.smashingmagazine.com/2017/02/a-detailed-introduction-to-webpack/" target="_blank" rel="noopener">introducing the core concepts of webpack on Smashing Magazine</a>, so I’m sure I’ll have plenty to teach you if I really get into everything important to know about webpack.</p><h2 id="Vue-js-Courses"><a href="#Vue-js-Courses" class="headerlink" title="Vue.js Courses"></a>Vue.js Courses</h2><p>Another thing holding me back from writing on this blog has been my work for <a href="http://appendto.com" target="_blank" rel="noopener">AppendTo</a>. My most recent pieces have been outlines for Vue.js Courses, or rather <a href="https://appendto.com/course/javascript-training-courses/managing-state-in-vue-js-with-vuex/" target="_blank" rel="noopener">Vuex</a> and <a href="https://appendto.com/course/javascript-training-courses/advanced-routing-in-vue-js-with-vue-router/" target="_blank" rel="noopener">Vue-Router</a> courses. I’m not actually teaching these courses right now, but I’m working towards qualifying to work for Develop Intelligence (the company that owns the AppendTo blog) as a training consulant some day, so maybe I will in the future. And of course I want to be making more web development courses online as well.</p><p>So, that was all my announcements this time around. Thanks for checking in on me. I promise my next post will be a tutorial of some sort. God bless and happy coding.</p>]]></content:encoded>
      
      <comments>https://www.joezimjs.com/javascript/presenting-optimizing-js-web-app-performance-webpack/#disqus_thread</comments>
    </item>
    
    <item>
      <title>Where Did Vue.js Come From?</title>
      <link>https://www.joezimjs.com/javascript/where-did-vuejs-come-from/</link>
      <guid>https://www.joezimjs.com/javascript/where-did-vuejs-come-from/</guid>
      <pubDate>Thu, 16 Mar 2017 22:05:29 GMT</pubDate>
      <description>
      
        Vue.js has seemingly come out of nowhere. What is causing Vue.js to rise so quickly? What does Vue.js offer JavaScript developers?
      
      </description>
      
      <content:encoded><![CDATA[<p>The popularity of Vue.js has been climbing pretty fast. It hasn’t reached the levels of Angular or React yet, but in the year that the <a href="https://github.com/vuejs/vue" target="_blank" rel="noopener">current VueJS repo</a> has existed on Github, it has garnered approximately 2,700 watchers (more than <a href="https://github.com/angular/angular" target="_blank" rel="noopener">Angular</a>), 47,000 stars (more than twice as many as Angular and more than 3/4 of <a href="https://github.com/facebook/react" target="_blank" rel="noopener">React’s</a>). They also have more closed issues than React and only a tiny 58 open issues (compared to over 500 for React and over 1,000 for Angular).<a id="more"></a></p><p>This obvious growth in popularity begs the question, “Why is Vue.js gaining so much ground despite having several great frameworks already?”, and likewise, “What does Vue.js offer that the other frameworks and libraries don’t?” You’d think that if you can answer the 2nd question, you’d have the answer to the first question, right? Well, the quick answer to the 2nd question is</p><blockquote><p>“nothing”</p></blockquote><p>What? If it’s not offering anything new, why wasn’t it just ignored? Well, let’s try a <em>long</em> answer to the second question, then: </p><blockquote><p>“Technically it does not have any great new features. However, it does offer a unique combination of features.”</p></blockquote><p>So, it’s not really the features themselves, but the combination of features that Vue.js employs that is drawing the development community in. So what are these features, and where did Vue.js steal them from? Well, that information is on my guest post at AppendTo with the familiar title of <em><a href="https://appendto.com/2017/03/where-did-vue-js-come-from/" target="_blank" rel="noopener">Where Did Vue.js Come From?</a></em>.</p><p>However, I have some exclusive features right here that I couldn’t fit into that article (they limited me to 1000 words). You should read the article on AppendTo first, though.</p><div style="text-align:center;"><!-- Ezoic - In Content - under_first_paragraph --><div id="ezoic-pub-ad-placeholder-107"><!-- JZJS - In Content Responsive --><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-0471240617528503" data-ad-slot="9785736525" data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div><!-- End Ezoic - In Content - under_first_paragraph --></div><h2 id="Virtual-DOM"><a href="#Virtual-DOM" class="headerlink" title="Virtual DOM"></a>Virtual DOM</h2><p>This feature is probably one of the best features that React introduced to the world (though I’m still quite partial to how they changed the way we think by making React focus so much on composable and nestable components rather than views, which I talk about in the article on AppendTo). Virtual DOM revolutionized the way we render our views/components so that we don’t have to worry about the logic of only updating the few pieces that need to be updated but also don’t incur a huge performance hit due to re-rendering the entire view. </p><p>Vue’s rendering algorithm is generally faster than React’s, and because all state and props are “reactive” in Vue, and they handle detecting what changes take place, it’s even simpler to work with because you’ll never need to implement <code>shouldcomponentupdate</code> to optimize it. So Vue not only “stole” this feature, they improved it in multiple ways (though technically they used someone else’s virtual DOM implementation rather than creating their own)! I’m curious if reactivity was taken from something else though. I know Angular 1 does something similar with scope, but it’s “dirty checked”, rather than applying </p><h2 id="CLI-Tool-For-Quickly-Bootstrapping-New-Projects"><a href="#CLI-Tool-For-Quickly-Bootstrapping-New-Projects" class="headerlink" title="CLI Tool For Quickly Bootstrapping New Projects"></a>CLI Tool For Quickly Bootstrapping New Projects</h2><p><a href="https://github.com/vuejs/vue-cli" target="_blank" rel="noopener">Vue-CLI</a> enables you to easily grab a base project structure, answer a few questions, and be immediately set up and ready to start a new Vue project in seconds. I believe Ember was the first to release their own CLI tool as a companion to their framework (feel free to correct me if I’m wrong), and while Ember’s community hasn’t reached the size of the other top frameworks, this is definitely a great reason to consider Ember (and Vue). It’s awesome to see that <a href="https://github.com/angular/angular-cli" target="_blank" rel="noopener">Angular has followed suit</a> as well (it’s currently in Release Candidate status).</p><p>Vue’s CLI tool doesn’t quite have as many features, though, because it is only designed to initialize a project and to build the project, but that’s primarily because there’s nothing for Vue to scaffold out except components, and there are multiple perfectly acceptable ways to create components, so you can do what you want in this case.</p><h2 id="That’s-It"><a href="#That’s-It" class="headerlink" title="That’s It"></a>That’s It</h2><p>Do you know of any other features that should be on this list? Vue.js seems so simple in my mind that it’s difficult to come up with features for it. Let me know in the comments below what you like best about Vue, or whatever you can think of to tell me (hopefully it’s at least relatively on topic). :) God bless and happy coding!</p>]]></content:encoded>
      
      <comments>https://www.joezimjs.com/javascript/where-did-vuejs-come-from/#disqus_thread</comments>
    </item>
    
    <item>
      <title>Getting Back Into JavaScript Writing</title>
      <link>https://www.joezimjs.com/javascript/back-into-javascript-writing/</link>
      <guid>https://www.joezimjs.com/javascript/back-into-javascript-writing/</guid>
      <pubDate>Wed, 22 Feb 2017 14:00:00 GMT</pubDate>
      <description>
      
        Took a while, but I&#39;m really getting back into the swing of things. JavaScript tutorials all over the place for webpack, Vue.js, and ES2015
      
      </description>
      
      <content:encoded><![CDATA[<p>I’m back! Did you miss me? I missed you guys. Sadly, though I’ve gotten back into writing about JavaScript, I haven’t been doing it on this blog. But I have written three posts for other blogs and they’ve all gone live this month. I’ve also got an announcement to make at the end.<a id="more"></a></p><h2 id="ES2015-Tagged-Template-Literals"><a href="#ES2015-Tagged-Template-Literals" class="headerlink" title="ES2015 Tagged Template Literals"></a>ES2015 Tagged Template Literals</h2><p>The first post that went live was on AppendTo.com. It was a tutorial on how to use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals" target="_blank" rel="noopener">tagged template literals</a> (released in ES2016, AKA ES6) in order to maximize the potential use of template strings. While the applications tend to be rather limited, they can be pretty powerful.</p><p>Read <a href="Advanced JavaScript ES2015 Template Strings with Tagged Templates">Advanced JavaScript ES2015 Template Strings with Tagged Templates</a>.</p><div style="text-align:center;"><!-- Ezoic - In Content - under_first_paragraph --><div id="ezoic-pub-ad-placeholder-107"><!-- JZJS - In Content Responsive --><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-0471240617528503" data-ad-slot="9785736525" data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div><!-- End Ezoic - In Content - under_first_paragraph --></div><h2 id="Vue-js’s-Single-File-Components"><a href="#Vue-js’s-Single-File-Components" class="headerlink" title="Vue.js’s Single File Components"></a>Vue.js’s Single File Components</h2><p>Recently I’ve been diving into learning about <a href="https://vuejs.org/" target="_blank" rel="noopener">Vue.js</a>. Why Vue.js? Well it was either that, React, Angular, or Ember. I was sick of being stuck on Backbone and MarionetteJS, so I needed to learn something new. I was planning on learning React, but there are already so many good articles out there that I felt like I might not be adding much to the community if I learned React and wrote about it, so I decided to take a look at the other options a bit first.</p><p>Vue.js was jumping up the popularity polls, so I took a look at it. I found out that it was pretty similar to React (component-based view layers with virtual-DOM-based rendering, and not much else without additional library support). Once I knew that, I basically just looked around to try to find what made it different from React. The biggest thing I found, and it’s the big feature that hooked me, was <a href="https://vuejs.org/v2/guide/single-file-components.html" target="_blank" rel="noopener">Single File Components</a>. So I latched onto Vue.js and decided to write an article about what I love about Single File Components, once again it was published by AppendTo.com.</p><p>Read <a href="https://appendto.com/2017/02/vue-jss-single-file-components-keeping-it-all-in-one-place-2/" target="_blank" rel="noopener">Vue.js’s Single File Components: Keeping It All In One Place</a>.</p><h2 id="Introduction-to-webpack"><a href="#Introduction-to-webpack" class="headerlink" title="Introduction to webpack"></a>Introduction to webpack</h2><p>The final guest post I wrote was for Smashing Magazine. I actually finished the first draft back in September, but SM does a thorough job of editing and they have lots of posts coming in, so it takes a long time for the posts to get published. Also, the post was over 8000 words(!!!), so it took some time for everyone to read through it. Anyway, the post was a beginners introduction to using <a href="https://webpack.js.org/" target="_blank" rel="noopener">webpack</a>. Interestingly, version 2 came out while waiting for the publish date to be ready, so I had to make edits to the post after it had already been edited and proofread. It finally released yesterday, though, so I can rejoice that it’s all done with!</p><p>Read <a href="https://www.smashingmagazine.com/2017/02/a-detailed-introduction-to-webpack/" target="_blank" rel="noopener">A Detailed Introduction to webpack</a></p><h2 id="A-webpack-Course"><a href="#A-webpack-Course" class="headerlink" title="A webpack Course"></a>A webpack Course</h2><p>My final announcement is that I’ve decided to make a large, in-depth tutorial, something akin to my old <a href="https://www.joezimjs.com/javascript/introduction-to-backbone-js-part-1-models-video-tutorial/">Backbone series</a>. However, I’ve had a lot more experience with video tutorial making, so it should be much higher quality. It should also be more in-depth, because, as you could see from an 8k word <em>introductory</em> tutorial to webpack, there is tons to learn. Due to this, I’ve decided to sell access to my course (not sure where yet; might just host them here). However, since you guys are all so cool (because you’re on my site), I’m giving you the opportunity to get 50% off the course once it is released.</p><blockquote><p><del><a href="#">Click here to go to the signup form</a>.</del></p></blockquote><p>If you fill that out, I will send you emails with updates about the progress of the course, give you access to some free samples of the course as some parts get finished up, and finally, when the course is released, you’ll be the first to know because a coupon code will arrive in your inbox.</p>]]></content:encoded>
      
      <comments>https://www.joezimjs.com/javascript/back-into-javascript-writing/#disqus_thread</comments>
    </item>
    
    <item>
      <title>Get Started With JavaScript Arrays</title>
      <link>https://www.joezimjs.com/javascript/get-started-javascript-arrays/</link>
      <guid>https://www.joezimjs.com/javascript/get-started-javascript-arrays/</guid>
      <pubDate>Mon, 26 Sep 2016 17:00:00 GMT</pubDate>
      <description>
      
        A beginner&#39;s guide to using arrays in JavaScript. They&#39;re simple but without an introduction, they can prove difficult to use sometimes.
      
      </description>
      
      <content:encoded><![CDATA[<p>Practically all programming languages have an in-built array data type. JavaScript is no different. They store the data you need to run scripts for an application, which, from a developer’s perspective, means you’ll be writing less code, making you more productive. That’s why it’s worth knowing your way around them.<a id="more"></a></p><div style="text-align:center;"><!-- Ezoic - In Content - under_first_paragraph --><div id="ezoic-pub-ad-placeholder-107"><!-- JZJS - In Content Responsive --><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-0471240617528503" data-ad-slot="9785736525" data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div><!-- End Ezoic - In Content - under_first_paragraph --></div><p>In this tutorial, taken from the second edition of <strong><a href="https://www.packtpub.com/web-development/learning-javascript-data-structures-and-algorithms-second-edition" target="_blank" rel="noopener">Learning JavaScript Data Structures and Algorithms</a>,</strong> by <strong>Loiane Groner</strong> we’ll take you through the key principles behind using arrays and show you how to put the theory into practice.</p><h2 id="Why-Should-We-Use-Arrays"><a href="#Why-Should-We-Use-Arrays" class="headerlink" title="Why Should We Use Arrays?"></a>Why Should We Use Arrays?</h2><p>Let’s consider that we need to store the average temperature of each month of the year of the city that we live in. We could use something similar to the following to store this information:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> averageTempJan = <span class="number">31.9</span>;</span><br><span class="line"><span class="keyword">var</span> averageTempFeb = <span class="number">35.3</span>;</span><br><span class="line"><span class="keyword">var</span> averageTempMar = <span class="number">42.4</span>;</span><br><span class="line"><span class="keyword">var</span> averageTempApr = <span class="number">52</span>;</span><br><span class="line"><span class="keyword">var</span> averageTempMay = <span class="number">60.8</span>;</span><br></pre></td></tr></table></figure><p>However, this is not the best approach. If we store the temperature for only 1 year, we could manage 12 variables. However, what if we need to store the average temperature for more than 1 year? Fortunately, this is why arrays were created, and we can easily represent the same information mentioned earlier as follows:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">averageTemp[<span class="number">0</span>] = <span class="number">31.9</span>;</span><br><span class="line">averageTemp[<span class="number">1</span>] = <span class="number">35.3</span>;</span><br><span class="line">averageTemp[<span class="number">2</span>] = <span class="number">42.4</span>;</span><br><span class="line">averageTemp[<span class="number">3</span>] = <span class="number">52</span>;</span><br><span class="line">averageTemp[<span class="number">4</span>] = <span class="number">60.8</span>;</span><br></pre></td></tr></table></figure><p>We can also represent the <code>averageTemp</code> array graphically:</p><p><img src="/wp-content/uploads/average-temp-array.png" alt="Graphical Representation of the averageTemp array"></p><h2 id="Creating-and-Initializing-Arrays"><a href="#Creating-and-Initializing-Arrays" class="headerlink" title="Creating and Initializing Arrays"></a>Creating and Initializing Arrays</h2><p>Declaring, creating, and initializing an array in JavaScript is as simple, as shown by the following:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> daysOfWeek = <span class="keyword">new</span> <span class="built_in">Array</span>(); <span class="comment">//&#123;1&#125;</span></span><br><span class="line"><span class="keyword">var</span> daysOfWeek = <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="number">7</span>); <span class="comment">//&#123;2&#125;</span></span><br><span class="line"><span class="keyword">var</span> daysOfWeek = <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="string">'Sunday'</span>, <span class="string">'Monday'</span>, <span class="string">'Tuesday'</span>, <span class="string">'Wednesday'</span>, <span class="string">'Thursday'</span>, <span class="string">'Friday'</span>, <span class="string">'Saturday'</span>); <span class="comment">//&#123;3&#125;</span></span><br></pre></td></tr></table></figure><p>We can simply declare and instantiate a new array using the keyword new (line {1}). Also, using the keyword new, we can create a new array specifying the length of the array (line{2}). A third option would be passing the array elements directly to its constructor (line {3}).</p><p>However, using the new keyword is not best practice. If you want to create an array in JavaScript, we can assign empty brackets (<code>[]</code>),as in the following example:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> daysOfWeek = [];</span><br></pre></td></tr></table></figure><p>We can also initialize the array with some elements, as follows:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> daysOfWeek = [<span class="string">'Sunday'</span>, <span class="string">'Monday'</span>, <span class="string">'Tuesday'</span>, <span class="string">'Wednesday'</span>, <span class="string">'Thursday'</span>, <span class="string">'Friday'</span>, <span class="string">'Saturday'</span>];</span><br></pre></td></tr></table></figure><p>If we want to know how many elements are in the array (its size), we can use the <code>length</code> property. The following code will give an output of 7:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(daysOfWeek.length);</span><br></pre></td></tr></table></figure><h2 id="Accessing-Elements-and-Iterating-an-Array"><a href="#Accessing-Elements-and-Iterating-an-Array" class="headerlink" title="Accessing Elements and Iterating an Array"></a>Accessing Elements and Iterating an Array</h2><p>To access a particular position of the array, we can also use brackets, passing the index of the position we would like to access. For example, let’s say we want to output all the elements from the <code>daysOfWeek</code> array. To do so, we need to loop the array and print the elements, as follows:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> (<span class="keyword">var</span> i=<span class="number">0</span>; i &lt; daysOfWeek.length; i++)&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(daysOfWeek[i]);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>Let’s take a look at another example. Let’s say that we want to find out the first 20 numbers of the Fibonacci sequence. The first two numbers of the Fibonacci sequence are 1 and 2, and each subsequent number is the sum of the previous two numbers:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> fibonacci = []; <span class="comment">//&#123;1&#125;</span></span><br><span class="line"></span><br><span class="line">fibonacci[<span class="number">1</span>] = <span class="number">1</span>; <span class="comment">//&#123;2&#125;</span></span><br><span class="line">fibonacci[<span class="number">2</span>] = <span class="number">1</span>; <span class="comment">//&#123;3&#125;</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">var</span> i = <span class="number">3</span>; i &lt; <span class="number">20</span>; i++)&#123;</span><br><span class="line">  fibonacci[i] = fibonacci[i<span class="number">-1</span>] + fibonacci[i<span class="number">-2</span>]; <span class="comment">////&#123;4&#125;</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">var</span> i = <span class="number">1</span>; i &lt; fibonacci.length; i++)&#123; <span class="comment">//&#123;5&#125;</span></span><br><span class="line">  <span class="built_in">console</span>.log(fibonacci[i]);           <span class="comment">//&#123;6&#125;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><ul><li>So, in line {1}, we declared and created an array.</li><li>In lines {2} and {3}, we assigned the first two numbers of the Fibonacci sequence to the second and third positions of the array (in JavaScript, the first position of the array is always referenced by 0, and as there is no 0 in the Fibonacci sequence, we will skip it).</li><li>Then, all we have to do is create the third to the twentieth number of the sequence (as we know the first two numbers already). To do so, we can use a loop and assign the sum of the previous two positions of the array to the current position (line {4}, starting from index 3 of the array to the 19th index).</li><li>Then, to take a look at the output (line {6}), we just need to loop the array from its first position to its length (line {5}).</li></ul><p>We can use <code>console.log</code> to output each index of the array (lines {5} and {6}), or we can also use <code>console.log(fibonacci)</code> to output the array itself. Most browsers have a nice array representation in the console.</p><p>If you would like to generate more than 20 numbers of the Fibonacci sequence, just change the number 20 to whatever number you like.</p><h2 id="Adding-Elements"><a href="#Adding-Elements" class="headerlink" title="Adding Elements"></a>Adding Elements</h2><p>Adding and removing elements from an array is not that difficult, however, it can be tricky. For the examples we will use in this section, let’s consider that we have the following numbers array initialized with numbers from 0 to 9:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> numbers = [<span class="number">0</span>,<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>,<span class="number">7</span>,<span class="number">8</span>,<span class="number">9</span>];</span><br></pre></td></tr></table></figure><p>If we want to add a new element to this array (for example, the number 10), all we have to do is reference the latest free position of the array and assign a value to it:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">numbers[numbers.length] = <span class="number">10</span>;</span><br></pre></td></tr></table></figure><p>In JavaScript, an array is a mutable object. We can easily add new elements to it. The object will grow dynamically as we add new elements to it. In many other languages, such as C and Java, we need to determine the size of the array, and if we need to add more elements to the array, we need to create a completely new array; we cannot simply add new elements to it as we need them.</p><h2 id="Using-the-push-Method"><a href="#Using-the-push-Method" class="headerlink" title="Using the push Method"></a>Using the <code>push</code> Method</h2><p>However, there is also a method called <code>push</code> that allows us to add new elements to the end of the array. We can add as many elements as we want as arguments to the <code>push</code> method:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">numbers.push(<span class="number">11</span>);</span><br><span class="line">numbers.push(<span class="number">12</span>, <span class="number">13</span>);</span><br></pre></td></tr></table></figure><p>The output of the numbers array will be the numbers from 0 to 13.</p><h3 id="Inserting-an-Element-in-the-First-Position"><a href="#Inserting-an-Element-in-the-First-Position" class="headerlink" title="Inserting an Element in the First Position"></a>Inserting an Element in the First Position</h3><p>Now, let’s say we need to add a new element to the array and would like to insert it in the first position, not the last one. To do so, first, we need to free the first position by shifting all the elements to the right. We can loop all the elements of the array, starting from the last position + 1 (<code>length</code>) and shifting the previous element to the new position to finally assign the new value we want to the first position (-1). Run the following code for this:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> (<span class="keyword">var</span> i=numbers.length; i&gt;=<span class="number">0</span>; i--)&#123;</span><br><span class="line">  numbers[i] = numbers[i<span class="number">-1</span>];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">numbers[<span class="number">0</span>] = <span class="number">-1</span>;</span><br></pre></td></tr></table></figure><p>We can represent this action with the following diagram:</p><h3 id="Using-the-unshift-Method"><a href="#Using-the-unshift-Method" class="headerlink" title="Using the unshift Method"></a>Using the <code>unshift</code> Method</h3><p>The JavaScript array class also has a method called <code>unshift</code>, which inserts the values passed in the method’s arguments at the start of the array:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">numbers.unshift(<span class="number">-2</span>);</span><br><span class="line">numbers.unshift(<span class="number">-4</span>, <span class="number">-3</span>);</span><br></pre></td></tr></table></figure><p>So, using the <code>unshift</code> method, we can add the value -2 and then -3 and -4 to the beginning of the numbers array. The output of this array will be the numbers from -4 to 13.</p><h2 id="Removing-Elements"><a href="#Removing-Elements" class="headerlink" title="Removing Elements"></a>Removing Elements</h2><p>So far, you have learned how to add values to the end and at the beginning of an array. Let’s take a look at how we can remove a value from an array.</p><p>To remove a value from the end of an array, we can use the <code>pop</code> method:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">numbers.pop();</span><br></pre></td></tr></table></figure><p><em>NB: The push and pop methods allow an array to emulate a basic stack data structure.</em></p><p>The output of our array will be the numbers from -4 to 12. The length of our array is 17.</p><p>Hopefully you’ve now got a solid understanding of how to make use of JavaScript arrays – put it into practice and see how much of an impact it has on the way you develop. If you want to learn more, you can purchase Learning JavaScript Data Structures and Algorithms 2nd Edition<a href="https://www.packtpub.com/web-development/learning-javascript-data-structures-and-algorithms-second-edition" target="_blank" rel="noopener">here</a>.</p><p>Alternatively, you can find a wealth of JavaScript content in one of our web development Skill Plans featured on <a href="https://www.packtpub.com/mapt/skill-plans" target="_blank" rel="noopener">Mapt</a>. Sign up for free – subscribe for $29.99 to access an entire library of content.</p>]]></content:encoded>
      
      <comments>https://www.joezimjs.com/javascript/get-started-javascript-arrays/#disqus_thread</comments>
    </item>
    
    <item>
      <title>Composition Is King</title>
      <link>https://www.joezimjs.com/javascript/composition-is-king/</link>
      <guid>https://www.joezimjs.com/javascript/composition-is-king/</guid>
      <pubDate>Thu, 25 Aug 2016 17:05:01 GMT</pubDate>
      <description>
      
        Composition is an extremely useful and powerful pattern that can be used in place of funky inheritance, which can struggle in certain situations.
      
      </description>
      
      <content:encoded><![CDATA[<p>The JavaScript community is becoming flooded with articles pushing to move toward functional programming or at least more toward composition over inheritance. For a long time we’ve tried to standardize inheritance without the huge mess that comes with the verbosity of the prototype syntax, and now that we have a standard <code>class</code> keyword in ES2015, people are trying harder than ever to tell us we don’t need it. Those people are, for the most part, correct.<a id="more"></a></p><div style="text-align:center;"><!-- Ezoic - In Content - under_first_paragraph --><div id="ezoic-pub-ad-placeholder-107"><!-- JZJS - In Content Responsive --><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-0471240617528503" data-ad-slot="9785736525" data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div><!-- End Ezoic - In Content - under_first_paragraph --></div><p>Of course, they can’t be wrong. The source of truth for all Object-Oriented programmers is <em>Design Patterns: Elements of Reusable Object-Oriented Software</em> by the “Gang of Four”, which itself says to prefer composition over inheritance. It seems like most people don’t understand that though. They’re taught about inheritance and then try to do everything with that, but that’s not nearly as powerful or scaleable.</p><p>Back to JavaScript, which can take lessons from the design patterns book, but it’s a much different language than the one that that book was written for. Besides using prototypes rather than true classes, it is also filled with many bits of functional programming features. I’m not going to say “don’t use the new <code>class</code> keyword or inheritance,” or anything like that. I just want you to use the best tool for the job that you understand how to use. I want to say that going all out functional can be a great way to program, however, it’s not the simplest concept (at least, not if you dive in deep), so please just do what makes sense for you.</p><p>That being said, I’d like to show you some great examples of composition to help you learn how to use it and to show you where it can be helpful.</p><h2 id="Function-Composition"><a href="#Function-Composition" class="headerlink" title="Function Composition"></a>Function Composition</h2><p>We’ll start with composition of functions, cuz why not? Let’s say you have the following very simple functions:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">addAndLog</span> (<span class="params">a, b</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">let</span> result = a + b;</span><br><span class="line">    <span class="built_in">console</span>.log(result);</span><br><span class="line">    <span class="keyword">return</span> result;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>This seems quite simple, but it can actually broken down into 2 completely operations: retrieving the result of an operation and logging the result. This means that if you want to just get the result of the operation without logging it, you’re out of luck, so let’s split the operation into a separate function:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">add</span> (<span class="params">a, b</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> a + b;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">addAndLog</span> (<span class="params">a, b</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">let</span> result = add(a, b);</span><br><span class="line">    <span class="built_in">console</span>.log(result);</span><br><span class="line">    <span class="keyword">return</span> result;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>Great, now the addition operation can be used anywhere apart from the logging, but that addAndLog is still hard coded to log the result of the  <code>add</code> operation rather than being generalized to use the result of any operation. So let’s split the logging functionality out into its own function:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">log</span> (<span class="params">value</span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(value);</span><br><span class="line">    <span class="keyword">return</span> value;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>I added the <code>return</code> statement at the end so that we can add, e.g.:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">add(<span class="number">1</span>,<span class="number">2</span>); <span class="comment">// returns 3... but we want to log the result too</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// so we wrap it:</span></span><br><span class="line">log(add(<span class="number">1</span>,<span class="number">2</span>)); <span class="comment">// logs 3 AND returns 3 so the result can still be used elsewhere</span></span><br></pre></td></tr></table></figure><p>Heck, one of the biggest reasons we can’t just stick with using <code>console.log</code> in this case is because it simply returns <code>undefined</code>. Anyway, these nested invocations of functions are one of the things I like least about functional programming practices because it is essentially read from right to left, which is now how we westerners tend to read.</p><p>So, one of the things we can do about it is convert <code>log</code> into a higher order function. A higher order function is a function that returns a function (simplified definition). The new function, which we’ll call <code>logWrapper</code> will be able to accept a function as an argument, then return a new function that invokes the function you passed in, plus do the logging, plus return the result.</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">logWrapper</span> (<span class="params">operation</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="function"><span class="keyword">function</span> (<span class="params">...args</span>) </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> log(operation(...args));</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>So now we can create our old <code>addAndLog</code> function like this:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> addAndLog = logWrapper(add);</span><br><span class="line"></span><br><span class="line">addAndLog(<span class="number">1</span>,<span class="number">2</span>); <span class="comment">// logs 3 and returns 3</span></span><br></pre></td></tr></table></figure><p>Or we can combine it with any other operation, so it’s nice and generic.</p><p>That’s composition! You created flexibility by allowing the log function to be composed of any operation plus the logging functionality. Of course, now <code>logWrapper</code> is stuck with the logging functionality. There are several ways to generalize this even further by making a function that can take any number of functions and compose them together for you, but I think you get the idea. There are plenty of other tutorials out there about chaining or currying or piping or composing out there. I just wanted to give you an example.</p><h2 id="View-Component-Composition"><a href="#View-Component-Composition" class="headerlink" title="View / Component Composition"></a>View / Component Composition</h2><p>I could just talk about normal object composition, but everybody has done that already. Instead let’s talk about composition of views and components (as in React components). Why views and components? Mostly just because everyone is using some sort of framework with views and/or components in them, so it can be more relevant.</p><h3 id="React-Component-Composition"><a href="#React-Component-Composition" class="headerlink" title="React Component Composition"></a>React Component Composition</h3><p>Let’s start with React, despite the fact that I’ve never written about React on this blog. A common example used for mixins is modals or overlays, whatever you want to call them. I think modals can be handled better with composition though:</p><figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> Modal = React.createClass(&#123;</span><br><span class="line">    render() &#123;</span><br><span class="line">        <span class="keyword">return</span> (</span><br><span class="line">            &lt;div <span class="class"><span class="keyword">class</span></span>=<span class="string">"modal"</span>&gt;</span><br><span class="line">                &lt;div <span class="class"><span class="keyword">class</span></span>=<span class="string">"modal-header"</span>&gt;</span><br><span class="line">                    &lt;button type=<span class="string">"button"</span> <span class="class"><span class="keyword">class</span></span>=<span class="string">"close"</span> data-dismiss=<span class="string">"modal"</span> aria-hidden=<span class="string">"true"</span>&gt;×&lt;<span class="regexp">/button&gt;</span></span><br><span class="line"><span class="regexp">                    &lt;h3&gt;this.props.title&lt;/</span>h3&gt;</span><br><span class="line">                &lt;<span class="regexp">/div&gt;</span></span><br><span class="line"><span class="regexp">                &lt;div class="modal-body"&gt;</span></span><br><span class="line"><span class="regexp">                    &#123;this.props.children&#125;</span></span><br><span class="line"><span class="regexp">                &lt;/</span>div&gt;</span><br><span class="line">            &lt;<span class="regexp">/div&gt;</span></span><br><span class="line"><span class="regexp">        );</span></span><br><span class="line"><span class="regexp">    &#125;,</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">    ... /</span><span class="regexp">/ all the life-cycle stuff</span></span><br><span class="line"><span class="regexp">&#125;);</span></span><br></pre></td></tr></table></figure><p>Since you are using <code>props.children</code>, you can just nest your view directly inside the <code>Modal</code> component:</p><figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ReactDOM.render(<span class="xml"><span class="tag">&lt;<span class="name">Modal</span>&gt;</span> <span class="tag">&lt;<span class="name">MyView</span>/&gt;</span> <span class="tag">&lt;/<span class="name">Modal</span>&gt;</span></span>, mountNode);</span><br></pre></td></tr></table></figure><p>Or you can use what is called a “higher order component”, which is a function that returns a component that wraps your component for you:</p><figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">modalify</span>(<span class="params">WrappedComponent</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> React.createClass(&#123;</span><br><span class="line">        render: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> (</span><br><span class="line">                &lt;div <span class="class"><span class="keyword">class</span></span>=<span class="string">"modal"</span>&gt;</span><br><span class="line">                    &lt;div <span class="class"><span class="keyword">class</span></span>=<span class="string">"modal-header"</span>&gt;</span><br><span class="line">                        &lt;button type=<span class="string">"button"</span> <span class="class"><span class="keyword">class</span></span>=<span class="string">"close"</span> data-dismiss=<span class="string">"modal"</span> aria-hidden=<span class="string">"true"</span>&gt;×&lt;<span class="regexp">/button&gt;</span></span><br><span class="line"><span class="regexp">                        &lt;h3&gt;this.props.title&lt;/</span>h3&gt;</span><br><span class="line">                    &lt;<span class="regexp">/div&gt;</span></span><br><span class="line"><span class="regexp">                    &lt;div class="modal-body"&gt;</span></span><br><span class="line"><span class="regexp">                        &lt;WrappedComponent &#123;...this.props&#125; &#123;...this.state&#125; /</span>&gt;</span><br><span class="line">                    &lt;<span class="regexp">/div&gt;</span></span><br><span class="line"><span class="regexp">                &lt;/</span>div&gt;</span><br><span class="line">            )</span><br><span class="line">        &#125;,</span><br><span class="line"></span><br><span class="line">        ... <span class="comment">// all the life-cycle stuff</span></span><br><span class="line">  &#125;);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>Now if you want your component to be inside a modal, you can pass your component into a call to <code>modalify</code> and you’ll receive a modal component that will display your component.</p><figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ReactDOM.render(modalify(<span class="xml"><span class="tag">&lt;<span class="name">MyView</span>/&gt;</span></span>), mountNode);</span><br></pre></td></tr></table></figure><p><code>modalify</code> uses the JSX spread syntax to pass all props and state down automatically, though it may be more useful to use something like Lodash’s <a href="https://lodash.com/docs#omit" target="_blank" rel="noopener"><code>omit</code></a> function to strip out the modal-specific properties. The interesting thing about this higher order component pattern is that you can the wrapped component access to the life-cycle methods, or any other functionality that the modal has access to. For example, if the wrapped component is a form, you may want to close the modal once the form is submitted successfully, so you can pass the <code>closeModal</code> (not actually shown in the example code above) method to <code>WrappedComponent</code> as a property so it can call <code>closeModal</code> once the form is submitted.</p><p>You can technically pass access to those methods to <code>MyView</code> in the first nested components example like this:</p><figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> Modal = React.createClass(&#123;</span><br><span class="line">    render() &#123;</span><br><span class="line">        <span class="keyword">return</span> (</span><br><span class="line">            &lt;div <span class="class"><span class="keyword">class</span></span>=<span class="string">"modal"</span>&gt;</span><br><span class="line">                &lt;div <span class="class"><span class="keyword">class</span></span>=<span class="string">"modal-header"</span>&gt;</span><br><span class="line">                    &lt;button type=<span class="string">"button"</span> <span class="class"><span class="keyword">class</span></span>=<span class="string">"close"</span> data-dismiss=<span class="string">"modal"</span> aria-hidden=<span class="string">"true"</span>&gt;×&lt;<span class="regexp">/button&gt;</span></span><br><span class="line"><span class="regexp">                    &lt;h3&gt;this.props.title&lt;/</span>h3&gt;</span><br><span class="line">                &lt;<span class="regexp">/div&gt;</span></span><br><span class="line"><span class="regexp">                &lt;div class="modal-body"&gt;</span></span><br><span class="line"><span class="regexp">                    &#123;</span></span><br><span class="line"><span class="regexp">                        React.Children.map(this.props.children, child =&gt; &#123;</span></span><br><span class="line"><span class="regexp">                            return React.cloneElement(child, &#123;</span></span><br><span class="line"><span class="regexp">                                closeModal: this.closeModal,</span></span><br><span class="line"><span class="regexp">                                ...</span></span><br><span class="line"><span class="regexp">                            &#125;);</span></span><br><span class="line"><span class="regexp">                        &#125;)</span></span><br><span class="line"><span class="regexp">                    &#125;</span></span><br><span class="line"><span class="regexp">                &lt;/</span>div&gt;</span><br><span class="line">            &lt;<span class="regexp">/div&gt;</span></span><br><span class="line"><span class="regexp">        );</span></span><br><span class="line"><span class="regexp">    &#125;,</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">    ... /</span><span class="regexp">/ all the life-cycle stuff</span></span><br><span class="line"><span class="regexp">&#125;);</span></span><br></pre></td></tr></table></figure><p>Instead of just using <code>{this.props.children}</code>, we use <code>React.Children.map</code> and <code>React.cloneElement</code> to augment the child views with modal functionality.</p><p>If you’d like some more examples of ways React can be composed rather than using inheritance or mixins, check out the post titled <a href="https://facebook.github.io/react/blog/2016/07/13/mixins-considered-harmful.html" target="_blank" rel="noopener">“Mixins Considered Harmful”</a> by Dan Abramov. That post is actually what gave me inspiration for this post, since it primarily dealt with React and I wanted to go further and demonstrate it with Backbone too, which is what we’ll do now.</p><h3 id="Backbone-View-Composition"><a href="#Backbone-View-Composition" class="headerlink" title="Backbone View Composition"></a>Backbone View Composition</h3><p>You can do pretty much the same thing with Backbone as what we did with React, except Backbone doesn’t have that JSX syntax or as clean a way to pass child views around, but we can still do the same thing with <code>options</code>.</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> ModalView = Backbone.view.extend(&#123;</span><br><span class="line">    attributes: &#123;</span><br><span class="line">        class: 'modal'</span><br><span class="line">    &#125;,</span><br><span class="line"></span><br><span class="line">    init: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">        _.extend(<span class="keyword">this</span>.options.childView, &#123;</span><br><span class="line">            closeModal: <span class="keyword">this</span>.closeModal,</span><br><span class="line">            ...</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;,</span><br><span class="line"></span><br><span class="line">    render: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">        <span class="comment">// Ignore the fact that I'm not using a template. Please!</span></span><br><span class="line">        <span class="keyword">this</span>.$el.html(</span><br><span class="line">            <span class="string">'&lt;div class="modal-header"&gt;'</span> +</span><br><span class="line">                <span class="string">'&lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;×&lt;/button&gt;'</span> +</span><br><span class="line">                <span class="string">'&lt;h3&gt;'</span> + <span class="keyword">this</span>.options.title +<span class="xml"><span class="tag">&lt;/<span class="name">h3</span>&gt;</span></span><span class="string">' +</span></span><br><span class="line"><span class="string">            '</span>&lt;<span class="regexp">/div&gt;' +</span></span><br><span class="line"><span class="regexp">            '&lt;div class="modal-body"&gt;&lt;/</span>div&gt;<span class="string">'</span></span><br><span class="line"><span class="string">        )</span></span><br><span class="line"><span class="string">        .find('</span>.modal-body<span class="string">').append(this.options.childView.render());</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        return this.$el; // Assume this practice for all `render` methods</span></span><br><span class="line"><span class="string">    &#125;,</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">    ... // all the life-cycle stuff</span></span><br><span class="line"><span class="string">&#125;);</span></span><br></pre></td></tr></table></figure><p>Then you can use it like this:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> myView = <span class="keyword">new</span> MyView();</span><br><span class="line"><span class="keyword">let</span> modal = <span class="keyword">new</span> ModalView(&#123;<span class="attr">childView</span>: myView&#125;);</span><br><span class="line">$(<span class="string">'body'</span>).append(modal.render());</span><br></pre></td></tr></table></figure><p>You could also use a “higher order view” pattern like we did with React, but I personally believe that nested views make more sense in this case. The higher order view and higher order component patterns is generally more useful if you’re only adding functionality without wrapping the component in more HTML, such as adding an <code>moveTo(x,y)</code> method that animates the positioning of the wrapped component:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">makeAnimatable</span>(<span class="params">WrappedView</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> Backbone.View.extend(&#123;</span><br><span class="line">        initialize: <span class="function"><span class="keyword">function</span>(<span class="params">options</span>) </span>&#123;</span><br><span class="line">            <span class="keyword">this</span>.wrapped = <span class="keyword">new</span> WrappedView(options);</span><br><span class="line">        &#125;,</span><br><span class="line"></span><br><span class="line">        moveTo: <span class="function"><span class="keyword">function</span>(<span class="params">x, y</span>) </span>&#123;</span><br><span class="line">            <span class="keyword">this</span>.wrapped.$el.animate(&#123;</span><br><span class="line">                top: y,</span><br><span class="line">                left: x</span><br><span class="line">            &#125;);</span><br><span class="line">        &#125;,</span><br><span class="line"></span><br><span class="line">        render: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">this</span>.wrapped.render();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>This pretty much does it. You’ll probably want to find a way to delegate all method calls to <code>this.wrapped</code>, though. Probably a simple way of doing this, though would be to just create a utility function that can be called from anywhere, rather than making <code>moveTo</code> a method:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">moveTo</span>(<span class="params">view, x, y</span>) </span>&#123;</span><br><span class="line">    view.$el.animate(&#123;</span><br><span class="line">        top: y,</span><br><span class="line">        left: x</span><br><span class="line">    &#125;);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>But that would be too easy. ;) This is actually one of the advantages to having a language that is both object-oriented (not class-based in the traditional sense, but still object-oriented) and functional. Lone functions can often significantly reduce complexity versus trying to accomplish things with wrappers or inheritance or mixins, etc.</p><h2 id="Conclusion"><a href="#Conclusion" class="headerlink" title="Conclusion"></a>Conclusion</h2><p>That’s all I’ve got for you today. I hope you’ve learned something useful: Composition, or even just plain functions as shown at the end, can be used to untangle some of the nastiest patterns in object-oriented programming. Just remember: composition over inheritance… and keep is simple, no matter which way you go. God bless and happy coding!</p>]]></content:encoded>
      
      <comments>https://www.joezimjs.com/javascript/composition-is-king/#disqus_thread</comments>
    </item>
    
    <item>
      <title>The Complete-Ish Guide to Upgrading to Gulp 4</title>
      <link>https://www.joezimjs.com/javascript/complete-guide-upgrading-gulp-4/</link>
      <guid>https://www.joezimjs.com/javascript/complete-guide-upgrading-gulp-4/</guid>
      <pubDate>Wed, 25 May 2016 11:00:00 GMT</pubDate>
      <description>
      
        Gulp 4 isn&#39;t officially released at time of publishing, but don&#39;t let that stop you from being prepared with this handy guide.
      
      </description>
      
      <content:encoded><![CDATA[<p>Gulp 4 has been in the works for far too long, but it’s practically inevitable that it’ll be released… some day. I’m here to help you out for when that fateful day arrives by showing you the differences between Gulp 3.x and Gulp 4 and how you can make the migration to the new version relatively painless.<a id="more"></a></p><div style="text-align:center;"><!-- Ezoic - In Content - under_first_paragraph --><div id="ezoic-pub-ad-placeholder-107"><!-- JZJS - In Content Responsive --><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-0471240617528503" data-ad-slot="9785736525" data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div><!-- End Ezoic - In Content - under_first_paragraph --></div><p><em>Just a note to prevent potential confusion, and to calm those who are sticklers for correct usage of terms (I’m one of those people), I use the word “compose” throughout this article; I’m using it in the general sense, not in the functional programming sense. “Compose” sounds more elegant than “combine” and its meaning is slightly closer to the idea I’m trying to convey.</em></p><h2 id="Installation"><a href="#Installation" class="headerlink" title="Installation"></a>Installation</h2><p>Before you can start using the latest version of Gulp, you’ll need to get rid of your current version of Gulp. Normally, you can just update the version number in you <code>package.json</code> file, but there are a few things preventing you from upgrading quite so easily. The most obvious reason is that you probably have Gulp installed locally in the project <em>and</em> globally on your machine (If you’re one of the people who follows <a href="http://www.joezimjs.com/javascript/no-more-global-npm-packages/">the practice of using npm scripts to access the locally installed version of CLI’s</a>, great! But that still won’t help you much here). So, first make sure you uninstall Gulp locally, and if you have it installed globally, uninstall it there as well.</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">npm uninstall gulp --save-dev</span><br><span class="line">npm uninstall gulp -g</span><br></pre></td></tr></table></figure><p>Now we need to install Gulp 4 locally. Since it’s not officially released, we’ll need to get it straight from Github:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install gulpjs/gulp.git<span class="comment">#4.0  --save-dev</span></span><br></pre></td></tr></table></figure><p>Once it’s released, you can just use the normal <code>npm install gulp --save-dev</code>. Also, when it’s finally released, we’ll need to update our projects to remove the Github version and install the npm version. For right now, there’s another thing we need to install: the CLI tool. With version 4, Gulp is separating the CLI tool from the actual Gulp code, much like Grunt does today. This separate CLI tool will actually work for both Gulp 3 and Gulp 4 right now.</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install gulp-cli --save-dev</span><br></pre></td></tr></table></figure><p>If you don’t use npm scripts, then you’ll need to use <code>-g</code> instead of <code>--save-dev</code> to install it globally. Now you can use the same <code>gulp</code> command that you had previously, but you’re going to see errors because you’ll need to update your <code>Gulpfile.js</code> to be compatible with the new version of Gulp.</p><h2 id="Tasks-Refactored"><a href="#Tasks-Refactored" class="headerlink" title="Tasks Refactored"></a>Tasks Refactored</h2><p>If you’re doing simple tasks that have no dependencies whatsoever, you’re in luck! You don’t have to make any changes! Sadly, real people have to make changes. The big change here is that Gulp now only supports the 2-parameter version of <code>gulp.task</code>. When you use 2 parameters, it takes a string as the name of the task, and a function to run for that task. e.g. the following task would remain the same between version 3.x and 4:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">gulp.task(<span class="string">'clean'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;...&#125;)</span><br></pre></td></tr></table></figure><p>But what about the 3-parameter signature? How do we specify a dependency task? You will do so by using the new <code>gulp.series</code> and <code>gulp.parallel</code> functions. Each of these functions will take a list of functions or task name strings and return anothe function. In the case of <code>gulp.series</code>, it’ll return a function that runs each of the given tasks/functions sequentially in the order they were provided whereas <code>gulp.parallel</code> will return a function that runs each of the given tasks/function in parallel. Finally, Gulp has given us the ability to choose between sequential and parallel execution of tasks without the need of another dependency (traditionally <a href="https://www.npmjs.com/package/run-sequence" target="_blank" rel="noopener">run-sequence</a>) or a bunch of crazy task dependency arrangement.</p><p>So, if you have this task before:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">gulp.task(<span class="string">'styles'</span>, [<span class="string">'clean'</span>], <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    ...</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure><p>It would be changed to</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">gulp.task(<span class="string">'styles'</span>, gulp.series(<span class="string">'clean'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    ...</span><br><span class="line">&#125;));</span><br></pre></td></tr></table></figure><p>When making the swap, don’t forget that your task’s main function is now inside the <code>gulp.series</code> call, so you’ll need the extra parenthesis at the end. This can be easy to miss.</p><p>Note that since <code>gulp.series</code> and <code>gulp.parallel</code> return functions, they can be nested, and you’ll probably need to nest them often if your tasks tend to have multiple dependency tasks, e.g. this common pattern</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">gulp.task(<span class="string">'default'</span>, [<span class="string">'scripts'</span>, <span class="string">'styles'</span>], <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    ...</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure><p>would be changed to</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">gulp.task(<span class="string">'default'</span>, gulp.series(gulp.parallel(<span class="string">'scripts'</span>, <span class="string">'styles'</span>), <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    ...</span><br><span class="line">&#125;));</span><br></pre></td></tr></table></figure><p>Sadly, this is often a bit messier to read than the old ways, but it’s a small price to pay for greater flexibility and control. You can also write some helper/alias function to make this more terse if that’s your preference, but I won’t get into that.</p><h2 id="Dependency-Gotchas"><a href="#Dependency-Gotchas" class="headerlink" title="Dependency Gotchas"></a>Dependency Gotchas</h2><p>In Gulp 3, if you specified several tasks that had the same dependency task, and each of these tasks was run, Gulp would recognize that all of these tasks depended on the same task and only run that depended-upon task once. Since we’re no longer specifying “dependencies”, rather we’re combining several functions together using <code>series</code> or <code>parallel</code>, Gulp can’t determine which tasks will be run multiple times when it should only be run once, so we’ll need to change the way we work with dependencies.</p><p>That’s a lot of abstract jargon being thrown around, so how about an example to clarify things? This example is adapted from an <a href="http://fettblog.eu/gulp-4-parallel-and-series/" target="_blank" rel="noopener">article on the Front-End Technology Talk about Gulp 4’s new task execution system</a>, and they spend most of that article on this topic, so if I’m not clear enough, that article should bring some clarity.</p><p>Take a look at this example from Gulp 3:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// Per default, start scripts and styles</span></span><br><span class="line">gulp.task(<span class="string">'default'</span>, [<span class="string">'scripts'</span>, <span class="string">'styles'</span>], <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;...&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// Both scripts and styles call clean</span></span><br><span class="line">gulp.task(<span class="string">'styles'</span>, [<span class="string">'clean'</span>], <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;...&#125;);</span><br><span class="line">gulp.task(<span class="string">'scripts'</span>, [<span class="string">'clean'</span>], <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;...&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// Clean wipes out the build directory</span></span><br><span class="line">gulp.task(<span class="string">'clean'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;...&#125;);</span><br></pre></td></tr></table></figure><p>Note that the <code>styles</code> and <code>scripts</code> tasks both depend on the <code>clean</code> task. When you run the default task, it’ll try to run both <code>styles</code> and <code>scripts</code>, see that they have dependencies, try to run each of the dependencies first, realize that both tasks depend on the <code>clean</code> task, and ensure that the <code>clean</code> task is run only once before coming back to the <code>styles</code> and <code>scripts</code> tasks. That’s a very helpful feature! Sadly, it could not be ported to the new way of doing things. If you just naively make the simple changes to Gulp 4 like I do in the following example, <code>clean</code> will be run twice.</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">gulp.task(<span class="string">'clean'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;...&#125;);</span><br><span class="line">gulp.task(<span class="string">'styles'</span>, gulp.series(<span class="string">'clean'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;...&#125;));</span><br><span class="line">gulp.task(<span class="string">'scripts'</span>, gulp.series(<span class="string">'clean'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;...&#125;));</span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">'default'</span>, gulp.parallel(<span class="string">'scripts'</span>, <span class="string">'styles'</span>));</span><br></pre></td></tr></table></figure><p>This is because <code>parallel</code> and <code>series</code> do not specify dependencies; they simply combine multiple functions into a single function. So we’ll need to pull dependencies out of each task, and specify the dependencies as a series in the larger “parent” task:</p><p><strong><em>Important note</em></strong>: You cannot define <code>default</code> before you define any of the smaller tasks it composes. When you call <code>gulp.series(&quot;taskName&quot;)</code>, the task with the name <code>&quot;taskName&quot;</code> <strong><em>needs</em></strong> to be defined already. This is why we moved <code>default</code> to the bottom for Gulp 4 whereas it could be anywhere in Gulp 3.</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// The tasks don't have any dependencies anymore</span></span><br><span class="line">gulp.task(<span class="string">'styles'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;...&#125;);</span><br><span class="line">gulp.task(<span class="string">'scripts'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;...&#125;);</span><br><span class="line">gulp.task(<span class="string">'clean'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;...&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// Per default, start scripts and styles</span></span><br><span class="line">gulp.task(<span class="string">'default'</span>, gulp.series(<span class="string">'clean'</span>, gulp.parallel(<span class="string">'scripts'</span>, <span class="string">'styles'</span>)));</span><br></pre></td></tr></table></figure><p>This of course means that you can’t just call the <code>styles</code> or <code>scripts</code> task independently while getting the prerequisite <code>clean</code> done, however, the way this was set up, <code>clean</code> would clean out the scripts and styles areas, so I’m not sure you would have been calling them independently anyway.</p><h2 id="Asynchronous-Task-Support"><a href="#Asynchronous-Task-Support" class="headerlink" title="Asynchronous Task Support"></a>Asynchronous Task Support</h2><p>In Gulp 3, if the code you ran inside a task function was synchronous, there was nothing special that needed to be done. That’s changed in Gulp 4: now you need to use the <code>done</code> callback (which I’ll get to shortly). Also, for asynchronous tasks, you had 3 options for making sure Gulp was able to recognize when your task finished, which were:</p><h3 id="1-Callback"><a href="#1-Callback" class="headerlink" title="1) Callback"></a>1) Callback</h3><p>You can provide a callback parameter to your task’s function and then call it when the task is complete:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> del = <span class="built_in">require</span>(<span class="string">'del'</span>);</span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">'clean'</span>, <span class="function"><span class="keyword">function</span>(<span class="params">done</span>) </span>&#123;</span><br><span class="line">    del([<span class="string">'.build/'</span>], done);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure><h3 id="2-Return-a-Stream"><a href="#2-Return-a-Stream" class="headerlink" title="2) Return a Stream"></a>2) Return a Stream</h3><p>You can also return a stream, usually made via <code>gulp.src</code> or even by using the <a href="https://www.npmjs.com/package/vinyl-source-stream" target="_blank" rel="noopener">vinyl-source-stream</a> package directly. This will likely be the most common way of doing things.</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">gulp.task(<span class="string">'somename'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> gulp.src(<span class="string">'client/**/*.js'</span>)</span><br><span class="line">        .pipe(minify())</span><br><span class="line">        .pipe(gulp.dest(<span class="string">'build'</span>));</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure><h3 id="3-Return-a-Promise"><a href="#3-Return-a-Promise" class="headerlink" title="3) Return a Promise"></a>3) Return a Promise</h3><p>Promises have been growing in prominence and are now even being implemented directly into Node, so this is a very helpful option. Just return the promise and Gulp will know when it’s finished:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> promisedDel = <span class="built_in">require</span>(<span class="string">'promised-del'</span>);</span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">'clean'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> promisedDel([<span class="string">'.build/'</span>]);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure><h2 id="New-Asynchronous-Task-Support"><a href="#New-Asynchronous-Task-Support" class="headerlink" title="New Asynchronous Task Support"></a>New Asynchronous Task Support</h2><p>Now, thanks to Gulp’s use of the <a href="https://www.npmjs.com/package/async-done" target="_blank" rel="noopener">async-done</a> package and its latest updates we have support for even more ways of signalling a finished asynchronous task.</p><h3 id="4-Return-a-Child-Process"><a href="#4-Return-a-Child-Process" class="headerlink" title="4) Return a Child Process"></a>4) Return a Child Process</h3><p>You now spawn child processes and just return them! You can essentially move your npm scripts into Gulp with this if you’re not really a fan of loading up your <code>package.json</code> file with a million commands or using a lot of Gulp plugins that can get out of date with the packages they’re wrapping. Might look a bit like an anti-pattern, though, and there are other ways to do this as well.</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> spawn = <span class="built_in">require</span>(<span class="string">'child_process'</span>).spawn;</span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">'clean'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="keyword">return</span> spawn(<span class="string">'rm'</span>, [<span class="string">'-rf'</span>, path.join(__dirname, <span class="string">'build'</span>)]);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure><h3 id="5-Return-a-RxJS-observable"><a href="#5-Return-a-RxJS-observable" class="headerlink" title="5) Return a RxJS observable"></a>5) Return a RxJS observable</h3><p>I have never used RxJS, and it seems kinda niche, but for those who love this library to death, you may be very pleased to just be able to return an observable!</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> Observable = <span class="built_in">require</span>(<span class="string">'rx'</span>).Observable;</span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">'sometask'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> Observable.return(<span class="number">42</span>);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure><h2 id="Watching"><a href="#Watching" class="headerlink" title="Watching"></a>Watching</h2><p>The API for watching the file system and reacting to changes has had a bit of a makeover as well. Previously, after passing a glob pattern and optionally passing some options in, you were able to either pass in an array of tasks or a callback function that got some event data passed to it. Now, since tasks are specified via <code>series</code> or <code>parallel</code> which simply return a function, there’s no way to distinguish tasks from a callback, so they’ve removed the signature with a callback. Instead, like before, <code>gulp.watch</code> will return a “watcher” object that you can assign listeners to:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// OLD VERSION</span></span><br><span class="line">gulp.watch(<span class="string">'js/**/*.js'</span>, <span class="function"><span class="keyword">function</span>(<span class="params">event</span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">'File '</span> + event.path + <span class="string">' was '</span> + event.type + <span class="string">', running tasks...'</span>);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// WILL CHANGE TO:</span></span><br><span class="line"><span class="keyword">var</span> watcher = gulp.watch(<span class="string">'js/**/*.js'</span> <span class="comment">/* You can also pass options and/or a task function here */</span>);</span><br><span class="line">watcher.on(<span class="string">'all'</span>, <span class="function"><span class="keyword">function</span>(<span class="params">event, path, stats</span>) </span>&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">'File '</span> + path + <span class="string">' was '</span> + event + <span class="string">', running tasks...'</span>);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// OR LISTEN TO INDIVIDUAL EVENT TYPES</span></span><br><span class="line">watcher.on(<span class="string">'change'</span>, <span class="function"><span class="keyword">function</span>(<span class="params">path, stats</span>) </span>&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">'File '</span> + path + <span class="string">' was changed, running tasks...'</span>);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">watcher.on(<span class="string">'add'</span>, <span class="function"><span class="keyword">function</span>(<span class="params">path</span>) </span>&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">'File '</span> + path + <span class="string">' was added, running tasks...'</span>);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">watcher.on(<span class="string">'unlink'</span>, <span class="function"><span class="keyword">function</span>(<span class="params">path</span>) </span>&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">'File '</span> + path + <span class="string">' was removed, running tasks...'</span>);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure><p>As seen in the <code>any</code> and <code>change</code> handlers, you <em>may</em> also receive a <a href="https://nodejs.org/api/fs.html#fs_class_fs_stats" target="_blank" rel="noopener">file stats</a> object. The stats only show up with their available (not sure when they would or would not be), but you can set the <code>alwaysStat</code> option to <code>true</code> if you always want it to show up. Gulp is using <a href="https://github.com/paulmillr/chokidar" target="_blank" rel="noopener">chokidar</a> under the hood so you can look at their documentation for greater details, though it doesn’t accept the third argument for a function to run on every event.</p><h2 id="Using-Plain-Functions"><a href="#Using-Plain-Functions" class="headerlink" title="Using Plain Functions"></a>Using Plain Functions</h2><p>Since every task is essentially just a function now, with no dependencies or anything special, other than the fact that they need a special task runner to determine when asynchronous tasks finish, we can move away from using <code>gulp.task</code> for everything and start embracing independent functions rather than functions merely as callbacks being passed to <code>gulp.task</code>. For example, I would change the end result of the example we came to in the “Dependency Gotchas” section above from this:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">gulp.task(<span class="string">'styles'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;...&#125;);</span><br><span class="line">gulp.task(<span class="string">'scripts'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;...&#125;);</span><br><span class="line">gulp.task(<span class="string">'clean'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;...&#125;);</span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">'default'</span>, gulp.series(<span class="string">'clean'</span>, gulp.parallel(<span class="string">'scripts'</span>, <span class="string">'styles'</span>)));</span><br></pre></td></tr></table></figure><p>to this:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// Just use function names with `series` and `parallel` to compose a task</span></span><br><span class="line">gulp.task(<span class="string">'default'</span>, gulp.series(clean, gulp.parallel(scripts, styles)));</span><br><span class="line"></span><br><span class="line"><span class="comment">// Change individual tasks to plain functions</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">styles</span>(<span class="params"></span>) </span>&#123;...&#125;</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">scripts</span>(<span class="params"></span>) </span>&#123;...&#125;</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">clean</span>(<span class="params"></span>) </span>&#123;...&#125;</span><br></pre></td></tr></table></figure><p>There are a few things to note here:</p><ol><li>Thanks to hoisting, the functions can be defined below the definition of the <code>default</code> task, unlike before where the tasks that it composes together need to be defined beforehand. This allows you to define the actual runnable tasks at the top for people to find more easily, rather than defining the pieces of the tasks first and hiding the runnable task in the mess at the bottom.</li><li><code>styles</code>, <code>scripts</code>, and <code>clean</code> are now “private” tasks, so they cannot be run using the Gulp command line.</li><li>No more anonymous functions.</li><li>No more wrapping “task” names in quotes, which also means that you’re using an identifier that your code editor/IDE can recognize is not defined if you mispell it, instead of needing to wait until you run Gulp to get the error.</li><li>The “tasks” can be split into multiple files and easily imported into a single file that uses <code>gulp.task</code> to define the runnable tasks.</li><li>Each of these tasks is independently testable (if you feel the need) without needing Gulp at all.</li></ol><p>Of course, #2 can be rectified if you want them to be runnable by the Gulp command line:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">gulp.task(styles);</span><br></pre></td></tr></table></figure><p>This will make the new task called “styles” that you can run from the command line. Note that I never specified a task name here. <code>gulp.task</code> is smart enough to grab the name right off of the function. This won’t work with an anonymous function, of course: Gulp throws an error if you try to assign an anonymous function as a task without providing a name.</p><p>If you want to give the function a custom name, you can use the function’s <code>displayName</code> property.</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">styles</span>(<span class="params"></span>)</span>&#123;...&#125;</span><br><span class="line">styles.displayName = <span class="string">"pseudoStyles"</span>;</span><br><span class="line">gulp.task(styles);</span><br></pre></td></tr></table></figure><p>Now the task’s name will be “pseudoStyles” instead of “styles”. You can also use the <code>description</code> property to give details about what the task does. You can view these details with the <code>gulp --tasks</code> command.</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">styles</span>(<span class="params"></span>)</span>&#123;...&#125;</span><br><span class="line">styles.displayName = <span class="string">"pseudoStyles"</span>;</span><br><span class="line">styles.description = <span class="string">"Does something with the stylesheets."</span></span><br><span class="line">gulp.task(styles);</span><br></pre></td></tr></table></figure><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ gulp --tasks</span><br><span class="line">[12:00:00] Tasks <span class="keyword">for</span> ~/project/gulpfile.js</span><br><span class="line">[12:00:00] └── pseudoStyles  Does something with the stylesheets.</span><br></pre></td></tr></table></figure><p>You can even add descriptions to other tasks that have been registered like <code>default</code>. You’ll first have to use <code>gulp.task(&#39;taskName&#39;)</code> to retrieve the task that was already assigned, then give it a description:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">gulp.task(<span class="string">'default'</span>, gulp.series(clean, gulp.parallel(scripts, styles)));</span><br><span class="line"></span><br><span class="line"><span class="comment">// Use gulp.task to retrieve the task</span></span><br><span class="line"><span class="keyword">var</span> defaultTask = gulp.task(<span class="string">'default'</span>);</span><br><span class="line"><span class="comment">// give it a description</span></span><br><span class="line">defaultTask.description = <span class="string">"Does Default Stuff"</span>;</span><br></pre></td></tr></table></figure><p>Or to make it shorter and not add another variable:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">gulp.task(<span class="string">'default'</span>, gulp.series(clean, gulp.parallel(scripts, styles)));</span><br><span class="line">gulp.task(<span class="string">'default'</span>).description = <span class="string">"Does Default Stuff"</span>;</span><br></pre></td></tr></table></figure><p>These descriptions can be very helpful to people who aren’t familiar with your project, so I recommend using them wherever applicable: it can be more useful and accessible than normal comments sometimes. In the end, this is the pattern I recommend as the best practice for Gulp 4:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">gulp.task(<span class="string">'default'</span>, gulp.series(clean, gulp.parallel(scripts, styles)));</span><br><span class="line">gulp.task(<span class="string">'default'</span>).description = <span class="string">"This is the default task and it does certain things"</span>;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">styles</span>(<span class="params"></span>) </span>&#123;...&#125;</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">scripts</span>(<span class="params"></span>) </span>&#123;...&#125;</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">clean</span>(<span class="params"></span>) </span>&#123;...&#125;</span><br></pre></td></tr></table></figure><p>If you run <code>gulp --tasks</code> on this you’ll see this:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">$ gulp --tasks</span><br><span class="line">[12:00:00] Tasks <span class="keyword">for</span> ~\localhost\gulp4test\gulpfile.js</span><br><span class="line">[12:00:00] └─┬ default  This is the default task and it does certain things</span><br><span class="line">[12:00:00]   └─┬ &lt;series&gt;</span><br><span class="line">[12:00:00]     ├── clean</span><br><span class="line">[12:00:00]     └─┬ &lt;parallel&gt;</span><br><span class="line">[12:00:00]       ├── scripts</span><br><span class="line">[12:00:00]       └── styles</span><br></pre></td></tr></table></figure><p>Not only does your description do the talking, the names of the functions that make up the task will give plenty of insight as well. If you disagree that the above pattern is the way it should be done, fine with me. That should really be a discussion you have with your team.</p><p>In any case, I see some helpful improvements coming with Gulp, but it’s different enough to cause some potential headaches during migration. I pray this guide is enough for you to migrate over to Gulp 4 when the time comes (some days…). God bless and happy coding.</p>]]></content:encoded>
      
      <comments>https://www.joezimjs.com/javascript/complete-guide-upgrading-gulp-4/#disqus_thread</comments>
    </item>
    
    <item>
      <title>UnixStickers Review: Where to Fulfill Your Geeky Needs</title>
      <link>https://www.joezimjs.com/uncategorized/unixstickers-review/</link>
      <guid>https://www.joezimjs.com/uncategorized/unixstickers-review/</guid>
      <pubDate>Thu, 14 Apr 2016 05:00:00 GMT</pubDate>
      <description>
      
        UnixStickers.com has tons of geeky merchandise for the geek in all of use, but do these products hold up to scrutiny and testing?
      
      </description>
      
      <content:encoded><![CDATA[<p>I don’t tend to be a person who spends a lot of money on decorative things, even if the decoration is on a piece of clothing that I’m going to be buying anyway. Because of that, I was slightly hesitant when <a href="http://unixstickers.refr.cc/6J9XHVV" target="_blank" rel="noopener">unixstickers.com</a> contacted me and asked me to do a review. I decided to do it anyway, and that’s what you’re going to see from me today. <em>Full Disclosure: they are not paying me to right this review, but I did receive some items for free in order to review them.</em><a id="more"></a></p><div style="text-align:center;"><!-- Ezoic - In Content - under_first_paragraph --><div id="ezoic-pub-ad-placeholder-107"><!-- JZJS - In Content Responsive --><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-0471240617528503" data-ad-slot="9785736525" data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div><!-- End Ezoic - In Content - under_first_paragraph --></div><h2 id="Whatcha-Got"><a href="#Whatcha-Got" class="headerlink" title="Whatcha Got?"></a>Whatcha Got?</h2><p>The first thing to discuss is what they sell. If we’re talking about merchandise types, then they have stickers of many sizes, t-shirt, hoodies, mugs, 50x70 cm posters, and pins. That list will satisfy most people looking for a bit of merchandise to show off their love for their geeky passion. But which passions do they support? I really don’t want to write them all out here, so here’s a screen shot of their “Browse By Passion” section at the bottom of their site:</p><p><img src="/wp-content/uploads/unixstickers-passions.png" alt="Browse by Passion: Lots of Programming languages and tools, as well as Linux distros"></p><p>That’s getting there, and they’ll be adding more soon, which is good because this is by no means a full representation of all geek passions, right? If you want to have some input into what they have on the site, go to <a href="https://trello.com/b/WcWf6kdF/unixstickers-public-roadmap" target="_blank" rel="noopener">their Trello board</a> and make a request or vote for your favorites.</p><p style="text-align:center;"><a href="http://unixstickers.refr.cc/6J9XHVV" target="_blank" rel="noopener"><img src="/wp-content/uploads/unixstickers-banner.png" alt="Get $5 off your UnixStickers.com purchase"></a><em>Get $5 off your UnixStickers.com purchase</em></p><h2 id="For-a-Cause"><a href="#For-a-Cause" class="headerlink" title="For a Cause"></a>For a Cause</h2><p>They don’t just sell you this stuff in order to earn a pretty penny for themselves, they also give some of their earnings away to open source projects! Straight from their <a href="http://www.unixstickers.com/donations" target="_blank" rel="noopener">donations page</a>:</p><blockquote><p>We decided to donate a significant part of our revenues to supporting FOSS projects</p><p>This is the most important decision we made since the day Unixstickers got started.</p><p>Being developers and fans of open source and free software is what motivated us to start this adventure in the first place, and we would have never got this far without passion.</p><p>We also recognize that our job, our business, and that of most of you would never exist without the existence of those very projects, foundations, organizations and individuals that make open source and free software possible.</p><p>How does it work?</p><p>At each purchase, you’ll be able to view from your cart how much we’ll donate, with the detail of what will be donated to whom. A significant part will be donated to the projects referring to your cart’s items, while the rest will be donated to a different initiative each month.</p></blockquote><p>At the time of this writing, they’ve given away over $5000 <abbr title="Free and Open Source Software">FOSS</abbr> projects, and they’ve only been doing this for about 2 and half months! So if you want to more than wear a logo on your chest in support of your favorite project, this is a great place to go!</p><h2 id="How-Does-It-Hold-Up"><a href="#How-Does-It-Hold-Up" class="headerlink" title="How Does It Hold Up?"></a>How Does It Hold Up?</h2><p>Now comes the important question: is their stuff worth buying? I asked them for a t-shirt to test because I didn’t think that reviewing stickers would be very useful. Well, along with the t-shirt I requested, they also sent a myriad of stickers and pins, so I have a few things to talk about.</p><p>The t-shirt has a bit of mixed review, but that’s mostly due to my size and the sizes they have available. The shirt itself is a very soft fabric, even after the first washing (so far I’ve only washed it once). In addition, it doesn’t feel terribly thin, so it doesn’t seem like it’ll tear after just a few weeks or anything (I cannot be held responsible if you tear your shirt). The one issue is that the max size they sell is 2XL (just XL for many shirts). This wouldn’t be terrible, but the 2XL that I received felt like an XL; in fact, according to the size charts on each site, UnixSticker’s 2XL t-shirts are smaller than the XL t-shirts on <a href="https://www.teepublic.com/stores/joezimjs" title="My Tee Public Store" target="_blank" rel="noopener">Tee Public</a>. So, I would order a shirt size larger than you normally would. I wish now that I had also asked for a hoodie so I could give you an honest review about them as well, because I think t-shirts would at least stretch better than a hoodie.</p><p>The stickers I received, despite my original thinking that stickers wouldn’t be worth reviewing, really beat my expectations. They’re not like the stickers play with that come with an activity book or anything. These stickers are “printed from a sheet vinyl, covered by a layer of top quality transparent film to protect the ink and improve durability and beauty, then finely cut to follow the shape.” These suckers are heavy duty! They won’t tear without some serious effort, and they won’t fall off most surfaces. The nice thing about their sturdiness and materials is the fact they won’t leave a thin layer of paper if you try to peel them off, but they may still leave some adhesive. They also have what they call “Badge Stickers”. These are tiny stickers (.67in x 1.02in or 1.7cm x 2.6cm) that are meant to be placed on a laptop near the keyboard (like where you normally get stickers that say which OS and CPU come with your PC).</p><p><img src="https://www.unixstickers.com/image/cache/data/badge_dimension_unixstickers-600x600.png" alt="Badge Sticker Example Image"></p><p>Finally we come to the pins. There is nothing spectacular about them, but I can tell you that I’ve definitely seen pins of worse quality, so we can at least buy from UnixStickers knowing that you’re not getting the worst pins! (I’m so helpful, right?)</p><h2 id="Conclusion"><a href="#Conclusion" class="headerlink" title="Conclusion"></a>Conclusion</h2><p>UnixStickers seems like a great place to fulfill your geeky merchandise needs. So go fulfill them today! You can even <a href="http://unixstickers.refr.cc/6J9XHVV" target="_blank" rel="noopener">use this link to unixstickers.com</a> to get $5 off of your first purchase, as well as support me with a meager commission. I’m not recommending them because I want that commission. I’m recommending them because they’re a great company and the commission is just a nice bonus for those who trust and value my opinion. :)</p>]]></content:encoded>
      
      <comments>https://www.joezimjs.com/uncategorized/unixstickers-review/#disqus_thread</comments>
    </item>
    
    <item>
      <title>Integrating Your Development Workflow Into Sublime With Build Systems - Part 4: Project-Specific Builds</title>
      <link>https://www.joezimjs.com/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-4/</link>
      <guid>https://www.joezimjs.com/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-4/</guid>
      <pubDate>Fri, 11 Mar 2016 06:00:00 GMT</pubDate>
      <description>
      
        We&#39;re finally going to make build systems as efficient and useful as possible by bundling them in with our projects for shareability and switching.
      
      </description>
      
      <content:encoded><![CDATA[<p>We come to the final episode in this series where we take everything we’ve learned so far and apply it in a useful way by creating build systems that are specific to your projects! This allows you to hide build systems you only need for certain projects, and allows you to easily share the build systems by saving them in your project’s repository.<a id="more"></a></p><div style="text-align:center;"><!-- Ezoic - In Content - under_first_paragraph --><div id="ezoic-pub-ad-placeholder-107"><!-- JZJS - In Content Responsive --><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-0471240617528503" data-ad-slot="9785736525" data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div><!-- End Ezoic - In Content - under_first_paragraph --></div><h2>Series</h2><ul><li><a href="/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-1/">Part 1: Basic Build Systems</a></li><li><a href="/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-2/">Part 2: Options and Variables</a></li><li><a href="/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-3/">Part 3: Organizing with Variants</a></li><li><a href="/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-4/">Part 4: Project-Specific Builds</a></li></ul><h2 id="Part-4-Project-Specific-Builds"><a href="#Part-4-Project-Specific-Builds" class="headerlink" title="Part 4: Project-Specific Builds"></a>Part 4: Project-Specific Builds</h2><div class="video-container"><iframe src="//www.youtube.com/embed/fWHQktiz5zY" frameborder="0" allowfullscreen></iframe></div><h2 id="Transcript"><a href="#Transcript" class="headerlink" title="Transcript"></a>Transcript</h2><p>Welcome to part 4 of this video series. In the last video we showed you how to organize your Sublime build systems using variants. This time around, we’re going to show you how to make project-specific build systems. With project-specific build systems, you can keep all the build systems that only pertain to certain projects out of your list of build systems until you’re actually working on a project that uses those build systems. Also, the file that contains your build systems can be placed in your project’s repository, so it’s easily shared with the rest of the team! Let’s get started!</p><p>We’ll start off by creating a project in Sublime. It’s simple to create a project. First, make sure you have the folder or folders that pertain to your project opened in the sidebar. Then, just go to the Project menu and select Save Project As. The best idea is to save the project file somewhere within the project repository, so that it’s available for every team member working on the project.</p><p>We’ll just save this project as ‘example’. There, now we have a project… you can’t tell much difference, though, can you?</p><p>The best way to know if you’re in a project and which project you’re in, is to look at the title bar. The project name will be in parenthesis near the end.</p><p>Now, let’s close this project, so I can show you how to open up the project.</p><p>If you go to <code>Project &gt; Open Project</code>, you can find the sublime project file you just saved and open that to open the project up.</p><p>You can also find projects you’ve recently worked on under <code>Project &gt; Open Recent</code>.</p><p>Finally, you can use <code>Project &gt; Quick Switch Project</code> to bring up a little palette with all of your recent projects in it. This is really only useful vs <code>Open Recent</code> because you can bind a keyboard shortcut to this. Mac and Linux should already have a shortcut bound, but with the latest release of Sublime, they turned off the default binding because it often conflicted with other shortcuts.</p><p>If you want to set up the shortcut or change it, you can go into your key binding preferences and create one as I have on my machine.</p><p>Now that we know how to open a project and we have one open, let’s edit our project file. You can do that by going to Project &gt; Edit Project.</p><p>You could also just find the project file in the file explorer and open it from there, but I tend to alter my settings to hide these files because they clutter up the file list.</p><p>If you take a look at the project file, you won’t find much: just a JSON file with the list of the folders in the sidebar, their paths relative to the project file.</p><p>There are several things you can do a in a project file. You can control what files do and do not show up in the sidebar with the <code>file_exclude_patterns</code> options, which is how I prevent the project file from showing up on the left. You can also use the <code>settings</code> property to override your Sublime user settings. This allows for some settings, like tab size, to specified for the project to guarantee that each member is using the same rules. Sadly, most setting don’t really make sense to be in here. I’ve linked to <a href="http://sublime-text-unofficial-documentation.readthedocs.org/en/latest/file_management/file_management.html#projects" target="_blank" rel="noopener">the documentation</a> in the description below the video if you want to learn more about what you can do with projects.</p><p>What we’re here to focus on is Build systems, so let’s take a look at that. First, we need to add a property called <code>build_systems</code>, which is an array of build system objects.</p><p>Each of these object is just like the contents of one the build files we’ve done before, but since we don’t have individual files, they’re going to need names. So we give it a name, and a simple command, then save the project file.</p><p>Now if we take a look at our build systems, you’ll see our “hi” build system listed near the top, above a separator line that splits the project-specific build systems from the machine-specific build systems. If we had multiple build systems defined in that array in the project file, they’d each appear up here. Now let’s select our build system, and run it, wand we’ll see our expected results below.</p><p>Now let’s take a closer look at how we can put these build systems to work in real life situations. I’m going to copy a few premade build systems over to I don’t need to type them up.</p><p>As you can see, I actually have all of my build systems set up as variants of a single parent build system. Like I showed in video 3, these variants allow me to choose a single build system under the Tools menu, and then just use a keyboard shortcut to quickly choose which of the variants I would like to run.</p><p>The other thing of note here is that most of these are using npm scripts. I highly recommend this. It keeps your project’s build systems simple and clear, and it also allows you to easily run your builds without requiring you to be in Sublime Text or having to write out any long, complicated commands in the command line.</p><p>You may also notice that I’m using <code>-s</code> in all of the npm scripts. This is the “silent” option. Normally when you run an npm script, it’ll show a little message telling you what npm scripts you’re running and such. This <code>-s</code> just hides that message.</p><p>This last build system also has an <code>env</code> propery defined. This allows you to set environment variables so you can control your build process based on those as well. Finally, as you can see, there are no working directories specified. This is because the default working directory is the directory that the project file is saved in. If you’re paranoid, or if you need a different working directory for some build systems, you can still add them in here, just like with any build system.</p><h2 id="Conclusion"><a href="#Conclusion" class="headerlink" title="Conclusion"></a>Conclusion</h2><p>Well, that’s all I have for you guys in this video series. I hope you learned a bit about how to use Sublime Text more efficiently, and as always: God Bless and Happy Coding!</p>]]></content:encoded>
      
      <comments>https://www.joezimjs.com/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-4/#disqus_thread</comments>
    </item>
    
    <item>
      <title>Integrating Your Development Workflow Into Sublime With Build Systems - Part 3: Organizing With Variants</title>
      <link>https://www.joezimjs.com/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-3/</link>
      <guid>https://www.joezimjs.com/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-3/</guid>
      <pubDate>Thu, 10 Mar 2016 06:00:00 GMT</pubDate>
      <description>
      
        We pretty much have build systems down now, but we want to be more efficient about how we use them. That&#39;s where variants come in.
      
      </description>
      
      <content:encoded><![CDATA[<p>In the <a href="/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-2/">previous episode</a> you learned how to customize build systems so they can do pretty much whatever you want, but now we’ll help you become more efficient with using your build systems by organizing them and making it possible to easily switch between different build systems with a few key presses.<a id="more"></a></p><div style="text-align:center;"><!-- Ezoic - In Content - under_first_paragraph --><div id="ezoic-pub-ad-placeholder-107"><!-- JZJS - In Content Responsive --><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-0471240617528503" data-ad-slot="9785736525" data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div><!-- End Ezoic - In Content - under_first_paragraph --></div><h2>Series</h2><ul><li><a href="/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-1/">Part 1: Basic Build Systems</a></li><li><a href="/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-2/">Part 2: Options and Variables</a></li><li><a href="/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-3/">Part 3: Organizing with Variants</a></li><li><a href="/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-4/">Part 4: Project-Specific Builds</a></li></ul><h2 id="Part-3-Organizing-with-Variants"><a href="#Part-3-Organizing-with-Variants" class="headerlink" title="Part 3: Organizing with Variants"></a>Part 3: Organizing with Variants</h2><div class="video-container"><iframe src="//www.youtube.com/embed/IMF3R1b8blg" frameborder="0" allowfullscreen></iframe></div><h2 id="Transcript"><a href="#Transcript" class="headerlink" title="Transcript"></a>Transcript</h2><p>Welcome to Part 3 of <em>Integrating Your Development Workflow Into Sublime with Build Systems</em>. In the last episode we saw how to use other build system options and variables to create more powerful and dynamic build systems. This time around, we’ll be using something called variants in order to group multiple build systems into a single file. This allows us to switch between different related build systems with a simple keyboard shortcut, and prevents our list of build systems from getting unruly.</p><p>We’ll start by creating a new build system as we have before.</p><p>This time, though, instead of writing the command we want to use for this build system, we’ll create a property called <code>variants</code>, which holds an array of child build systems. We’ll add the same Node command that we’ve already used, but this time we also need to give it a <code>name</code>, since the name of the file refers to the parent build system, and if no name is given, the build system won’t be listed, so it’ll be impossible to run. We’ll also create a similar build system to the Node one, but this one will use <code>babel-node</code> which is similar to Node, but it uses a tool called Babel to convert future or alternative syntaxes, such as ES2015, to ES5 on the fly just before it runs the code using Node. It’s an npm package that I have installed globally, so it’s in my PATH and will run just by calling <code>babel-node</code>.</p><p>Now, before you go wasting your time trying it, you cannot add variants under a variant. I mean you <em>can</em>, but there’s no way to select a sub-variant, so it’s completely pointless.</p><p>Now we’ll save this as “Run JavaScript”. Then we’ll select it as the current build system and open up that JavaScript file.</p><p>This time, though, instead of just using Build, we’ll use “Build With…”, which has its own keyboard shortcut. It brings up a list of the sub-builds for you to choose. At this time, we’ll choose Node again. This gives us the expected results.</p><p>Now, if we choose to just Build, it’ll use the last sub-build system we chose, which was the node sub-build of Run JavaScript, as you can see.</p><p>Now let’s open a file with some ES2015 code in there and then choose “Build With…” again. This time we’ll select the Babel sub-build and run it.</p><p>And, once again, if we choose to just Build again, it’ll run the Babel sub-build once more.</p><p>Now we know how to make our own builds, but some of these build systems may only be useful on one project, and they are stuck on our individual machines. If they are specific to a project, then every person working on the project needs to make a copy of them. There is a better way, though, which is what we’ll be talking about in the next video.</p><h2 id="Conclusion"><a href="#Conclusion" class="headerlink" title="Conclusion"></a>Conclusion</h2><p>Pretty much every build system I write these days is in a variant because there are always related things to do, and as you’ll see in part 4, most of my build systems are stored somewhere else… God bless and happy coding.</p>]]></content:encoded>
      
      <comments>https://www.joezimjs.com/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-3/#disqus_thread</comments>
    </item>
    
    <item>
      <title>Integrating Your Development Workflow Into Sublime With Build Systems - Part 2: Options and Variables</title>
      <link>https://www.joezimjs.com/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-2/</link>
      <guid>https://www.joezimjs.com/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-2/</guid>
      <pubDate>Tue, 08 Mar 2016 06:00:00 GMT</pubDate>
      <description>
      
        Now we have a basic understanding of how to use Sublime&#39;s build systems, so we&#39;ll take a look at what else they can do with options and variables.
      
      </description>
      
      <content:encoded><![CDATA[<p>Now that you’ve had your <a href="/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-1/">introduction to Sublime’s build systems</a>, let’s go a step further and introduce you to some of the more useful other options available and variables to help customize your build systems on toward a life a true usefulness.<a id="more"></a></p><div style="text-align:center;"><!-- Ezoic - In Content - under_first_paragraph --><div id="ezoic-pub-ad-placeholder-107"><!-- JZJS - In Content Responsive --><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-0471240617528503" data-ad-slot="9785736525" data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div><!-- End Ezoic - In Content - under_first_paragraph --></div><h2>Series</h2><ul><li><a href="/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-1/">Part 1: Basic Build Systems</a></li><li><a href="/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-2/">Part 2: Options and Variables</a></li><li><a href="/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-3/">Part 3: Organizing with Variants</a></li><li><a href="/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-4/">Part 4: Project-Specific Builds</a></li></ul><h2 id="Part-2-Options-and-Variables"><a href="#Part-2-Options-and-Variables" class="headerlink" title="Part 2: Options and Variables"></a>Part 2: Options and Variables</h2><div class="video-container"><iframe src="//www.youtube.com/embed/e8YxihD-BT8" frameborder="0" allowfullscreen></iframe></div><h2 id="Transcript"><a href="#Transcript" class="headerlink" title="Transcript"></a>Transcript</h2><p>If you watched part 1, you’ll know we finished off after running our first build system, and we saw that it listed the contents of the User Packages directory. This was because, by default, the build command’s working directory is the directory that the build file is saved in. In this episode we’re going to see how we can change this from the default as well as take a look at some of the other features that build systems give us.</p><p>So we’ll go back to our little build system file and make one quick edit.</p><p>All we’re going to do right now is add a working directory option in here, which, for right now we’ll simply set the it to the root of my C drive for simplicity’s sake and save the file.</p><p>If we run it again, we can see that the results show the contents of my <code>C</code> drive instead of my User Packages directory. As you can see, by adding options to our build, we can gain greater control over how our commands run, and I highly recommend you check out <a href="http://sublime-text-unofficial-documentation.readthedocs.org/en/latest/reference/build_systems.html" target="_blank" rel="noopener">the documentation</a> to see what all the possible options are. But we can do more than just set some options. What if we don’t want the working directory to be hard-coded, but instead be based off of what I’m working on? Well, for that sort of thing, we need variables.</p><p>To demonstrate variables, we’re actually going to abandon this LS build system, and instead we’re going to create a new one that is actually somewhat useful. We’re going to create a build system that will execute JavaScript files using NodeJS. Of course I’m assuming that you already have NodeJS installed, otherwise this won’t work.</p><p>For this build system we’ll set the command as <code>&quot;node&quot;</code>, but that will just run the Node REPL since we haven’t given Node a script to run. Actually, let’s see what that looks like since we’re talking about it. We’ll save this as <code>node.sublime-build</code>.</p><p>Then we’ll select node as our active build system, and run it.</p><p>You’ll notice the results panel shows up, but we’re not seeing any output. That’s because we’re in the REPL, and it’s waiting for our input. Sadly, we can’t give it any input from here, nor can we hit <code>ctrl+c</code> to kill the process, so how are we going to stop it?</p><p>We do that with <code>Tools &gt; Cancel Build</code>. There, now it says it was cancelled which means the process is no longer running.</p><p>Now we’ll give Node a file to run, which we’ll do by using the <code>$file</code> variable and putting it in the shell command. This variable refers to the full file path, including file name, of the file that is in focus in Sublime. Since we’re using the reference to the file directly, we won’t need to set a working directory or anything like that, so this is good. Let’s save it. If we try to run the build now, we’ll get an error because we have a non-JavaScript file open. If we closed all of the files so that there was no active file, we’d end up running the REPL again because the <code>$file</code> variable would be empty.</p><p>So let’s just open up a JavaScript file we can run. I have one such file here with an extremely simple bit of JavaScript in it, so let’s open it up.</p><p>Now let’s run the build (we don’t need to select the build system to run, since it should still be selected) and we get an error. What happened? Well, if you look up here, it’s saying that a module is missing, that usually means that Node is trying to load a file and can’t find it. In this case, we’re only trying to load the one file that we specified, so we’re not missing any dependencies. Now look at the path it’s looking for. That’s odd. That’s the correct <em>start</em> to our path, but it’s cut off. Turns out, the path we’re using has a space in it!</p><p>We’ll need to make sure that the file’s path is wrapped in quotes in order to avoid this problem.</p><p>Now let’s save it, run it, and we can see that the script we had open was run and the expected output can be seen.</p><p>If you want to see more of the variables that you can use in your build systems, you can read the <a href="http://sublime-text-unofficial-documentation.readthedocs.org/en/latest/reference/build_systems/configuration.html#build-system-variables" target="_blank" rel="noopener">documentation</a>, which I’ve linked to in the description below the video. In the next video, we’ll combine multiple build systems into one file to organize related builds, simplify how we switch build systems (since there is no simple keyboard shortcut to choose a different build system), and keep the list of build systems from getting absurdly long.</p><h2 id="Conclusion"><a href="#Conclusion" class="headerlink" title="Conclusion"></a>Conclusion</h2><p>It was great seeing you all again for this tutorial. Keep watching to get through the rest of the series in order to get to Build System paradise…ish. God Bless and happy coding!</p>]]></content:encoded>
      
      <comments>https://www.joezimjs.com/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-2/#disqus_thread</comments>
    </item>
    
    <item>
      <title>Integrating Your Development Workflow Into Sublime With Build Systems - Part 1: Basic Build Systems</title>
      <link>https://www.joezimjs.com/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-1/</link>
      <guid>https://www.joezimjs.com/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-1/</guid>
      <pubDate>Mon, 07 Mar 2016 06:00:00 GMT</pubDate>
      <description>
      
        Sublime is a great, lightweight code editor, but without a console, we&#39;ll need to find a different way to integrate our projects&#39; workflows better.
      
      </description>
      
      <content:encoded><![CDATA[<p>Sublime Text is a lightweight, but capable code editor that is greatly loved by many developers, but if you’re anything like me, you’re saddened a bit by the fact that Sublime doesn’t have an integrated system console. For many tasks that you use in the console, Sublime Text actually has a decent alternative: build systems. They allow you to run any console commands straight from Sublime. In this series I’ll be giving you the low-down on how to use Sublime’s build systems to their greatest potential.<a id="more"></a></p><div style="text-align:center;"><!-- Ezoic - In Content - under_first_paragraph --><div id="ezoic-pub-ad-placeholder-107"><!-- JZJS - In Content Responsive --><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-0471240617528503" data-ad-slot="9785736525" data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div><!-- End Ezoic - In Content - under_first_paragraph --></div><h2>Series</h2><ul><li><a href="/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-1/">Part 1: Basic Build Systems</a></li><li><a href="/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-2/">Part 2: Options and Variables</a></li><li><a href="/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-3/">Part 3: Organizing with Variants</a></li><li><a href="/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-4/">Part 4: Project-Specific Builds</a></li></ul><h2 id="Part-1-Basic-Build-Systems"><a href="#Part-1-Basic-Build-Systems" class="headerlink" title="Part 1: Basic Build Systems"></a>Part 1: Basic Build Systems</h2><div class="video-container"><iframe src="//www.youtube.com/embed/1LVFVDj4wak" frameborder="0" allowfullscreen></iframe></div><h2 id="Transcript"><a href="#Transcript" class="headerlink" title="Transcript"></a>Transcript</h2><p>Hey there folks! I’m Joe Zim and I’m here to talk to you a bit about making your life a little bit simpler by integrating your projects’ development work flow into your favorite code editor: Sublime Text. Without integrating your workflow into your editor, you’ll end up doing what I used to do: constantly switching back and forth between my editor and my console in order to run my commands for builds and such. I kept exploring ways to integrate a console into Sublime Text, but none of them worked to my satisfaction.</p><p>Sublime does have a built-in console, but it may not be exactly what you’d expect. It’s more of a Python REPL. As you can see, normal console commands don’t work, but python code runs, and you can run Sublime-specific commands from in here, but that doesn’t really help me at all. However, I did finally find a solution that I am satisfied with and it’s built right into Sublime: build systems.</p><p>You can find all the build systems that come with Sublime and the ones you’ve created under <code>Tools &gt; Build System</code>. This is where you select a build system to use, but right now, we’re actually going to create a new one.</p><p>Click the New Build System menu item and it’ll open up a new file with the most basic bits. You may see <code>shell_cmd</code> or just <code>cmd</code>. There are some differences between the two, but I’ve always found <code>shell_cmd</code> does what I want and seems to be easier to work with, so I don’t really know much about <code>cmd</code>. If you’re more curious about it than I am, you can look at <a href="http://sublime-text-unofficial-documentation.readthedocs.org/en/latest/reference/build_systems.html" target="_blank" rel="noopener">the documentation</a> linked to below the video to find out more.</p><p>Let’s change this <code>make</code> command to <code>ls</code> as a simple example of a command that we can use in our build systems to see how they work. Then we’ll save the build system. Notice that it automatically takes you to the user packages folder for your Sublime Text installation, which is where you want to save these so that Sublime can find them. We’ll save the file as <code>ls.sublime-build</code>, and then Sublime will use the file name as the name of the build system.</p><p>If we go to the <code>Tools</code> menu and look at Build Systems, we’ll see our new build system is now listed there. Sweet! Let’s select it as our current build system…</p><p>Now we need to tell Sublime to actually run the build. You’ll notice that I’m using the mouse and the menus instead of keyboard shortcuts. This is entirely for your sake, so you can see what I’m doing. If you’re a keyboard user, you can always look at the menus to figure out the keyboard shortcuts for yourself, or customize them to your liking with the Key Binding preferences. Returning from our tiny tangent, though, let’s run this build.</p><p>And there you have it! We ran a shell command without leaving Sublime and the output showed up in a panel at the bottom of the screen. You may have noticed that we never specified which directory this command should be run in, but it listed the contents of the User Packages directory. In part 2 of these videos, I’ll show you some more options we can give to the build system so we can make these build systems a little bit more useful!</p><h2 id="Conclusion"><a href="#Conclusion" class="headerlink" title="Conclusion"></a>Conclusion</h2><p>This isn’t the end of these tutorials. This is only part 1 of 4. I’ll be releasing these articles one day at a time, but all of the videos are already available on Youtube. Feel free to click through the annotations or cards to make your way through the series, or just work your way through <a href="https://www.youtube.com/playlist?list=PLGKeVI6nA3PCxOFFZ4gcf9QJCVLTwjR-P" target="_blank" rel="noopener">the playlist</a>. God bless and happy coding!</p>]]></content:encoded>
      
      <comments>https://www.joezimjs.com/javascript/integrating-your-dev-workflow-into-sublime-with-build-systems-1/#disqus_thread</comments>
    </item>
    
    <item>
      <title>No More Global Npm Packages (Part 2)</title>
      <link>https://www.joezimjs.com/javascript/no-more-global-npm-packages-2/</link>
      <guid>https://www.joezimjs.com/javascript/no-more-global-npm-packages-2/</guid>
      <pubDate>Mon, 01 Feb 2016 06:00:00 GMT</pubDate>
      <description>
      
        I&#39;ve talked on this before, but we need to stop depending on global npm Packages for our public projects. Here&#39;s a way to work without the globals.
      
      </description>
      
      <content:encoded><![CDATA[<p>In a <a href="http://www.joezimjs.com/javascript/no-more-global-npm-packages/">previous article</a> that I wrote earlier this year, I talked about eliminating project dependencies that needed to be installed globally, such as Grunt, Gulp, Browserify, WebPack, etc. Of course, I didn’t argue for eliminating these packages, just replacing the <code>-g</code> flag with a <code>--save</code> or <code>--save-dev</code> flag when installing them with <code>npm install</code> and then using npm scripts to execute the binaries. Well, there’s more…<a id="more"></a></p><div style="text-align:center;"><!-- Ezoic - In Content - under_first_paragraph --><div id="ezoic-pub-ad-placeholder-107"><!-- JZJS - In Content Responsive --><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-0471240617528503" data-ad-slot="9785736525" data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div><!-- End Ezoic - In Content - under_first_paragraph --></div><h2 id="Another-Solution"><a href="#Another-Solution" class="headerlink" title="Another Solution"></a>Another Solution</h2><p>This issue has been rattling around in my head a lot lately, and rattling hard enough to convince me to write 2 more posts (3 more if you count this one) about this subject on other blogs. The first went live September 4th on Sitepoint and is called <em><a href="http://www.sitepoint.com/solve-global-npm-module-dependency-problem/" target="_blank" rel="noopener">How to Solve the Global npm Module Dependency Problem</a></em> and the second was just published on Smashing Magazine as <em><a href="https://www.smashingmagazine.com/2016/01/issue-with-global-node-npm-packages/" target="_blank" rel="noopener">The Issue With Global Node Packages</a></em>.</p><p><img src="/wp-content/uploads/npm-logo.svg" alt="npm"></p><p>Those other 2 articles had something that my Part 1 article didn’t have: an alternative to just using npm scripts. Now, I must say that I still whole-heartedly advocate for using npm scripts if only to help out other people who pick up and use your project or even for yourself if your call to Browserify has several transforms or plugins that you don’t want to type in every time, but sometimes, you just want to type “grunt” or “gulp” or whatever the tool is and make something happen.</p><p>Before I reveal the “secret” that a fraction of you may be unaware of, I need to give credit to Gabriel Falkenberg for his <a href="http://www.joezimjs.com/javascript/no-more-global-npm-packages/#comment-1973106779">comment on my previous post</a>. He’s the one that introduced me to this trick.</p><p>So, the trick is that you can add relative paths to your PATH environment variable. For those who may not know, the PATH environment variable is what your console looks at when trying to find the executable file that matches the command you entered. So, for this, specifically, we can add <code>./node_modules/.bin/</code> to our PATH, preferrably before the path to the npm globals, but after practically everything else (for security reasons, see the comments by Francesco; you may also want to consider <a href="http://direnv.net/" target="_blank" rel="noopener">direnv</a> if you’re on a Unix-based machine) so the local binaries will be prioritized over the global npm packages.</p><p>Personally, I also added <code>../node_modules/.bin</code>, and <code>../../node_modules/.bin</code> to my PATH so that I can be deeper into my project’s file structure and still be able to execute the commands I need. If you’re not sure how to change your PATH, check <a href="http://www.computerhope.com/issues/ch000549.htm" target="_blank" rel="noopener">here</a> if you’re on Windows and <a href="http://www.wikihow.com/Change-the-Path-Variable-in-Linux" target="_blank" rel="noopener">here</a> if you’re using a Unix-based machine.</p><h2 id="Conclusion"><a href="#Conclusion" class="headerlink" title="Conclusion"></a>Conclusion</h2><p>This made things much simpler for me, at least when I’m just getting started with a new tool. Generally, after experimenting for a while, everything will end up in npm scripts anyway. However you do it, I hope this helps you to start saving those modules as dependencies for the sake of everyone else who may work on your project. God bless and Happy Coding!</p><p><em>P.S. You can also just set up your code editor to run your scripts at the press of a button instead of only using the command line directly. I tend to use Sublime Text’s build tools on my projects so that I can just use a couple keystrokes to fire off my most commonly used scripts.</em></p>]]></content:encoded>
      
      <comments>https://www.joezimjs.com/javascript/no-more-global-npm-packages-2/#disqus_thread</comments>
    </item>
    
    <item>
      <title>The Future of JZJS Is Now...ish</title>
      <link>https://www.joezimjs.com/javascript/future-jz-javascript-now-ish/</link>
      <guid>https://www.joezimjs.com/javascript/future-jz-javascript-now-ish/</guid>
      <pubDate>Thu, 28 Jan 2016 06:00:00 GMT</pubDate>
      <description>
      
        My site has gotten an &#39;upgrade&#39;! New (temporary) look, but more importantly a new system running behind it: static files! Better performance is good.
      
      </description>
      
      <content:encoded><![CDATA[<p>Take a look around. Notice anything different? Yes, the theme has changed! That’s the obvious thing, and it’s actually going to change again, hopefully some time in the next few months. There’s a lot of work being done behind the scenes for this site, so let’s take a look.<a id="more"></a></p><div style="text-align:center;"><!-- Ezoic - In Content - under_first_paragraph --><div id="ezoic-pub-ad-placeholder-107"><!-- JZJS - In Content Responsive --><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-0471240617528503" data-ad-slot="9785736525" data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div><!-- End Ezoic - In Content - under_first_paragraph --></div><h2 id="Recreation-of-the-Blog"><a href="#Recreation-of-the-Blog" class="headerlink" title="Recreation of the Blog"></a>Recreation of the Blog</h2><p>As I said, you probably noticed the redesign. Heck, I’ve been using <a href="http://www.ezoic.com/" target="_blank" rel="noopener">Ezoic</a> to experiment with layouts and ad placement to create the best possible income from the site while also providing a great experience for you guys as readers, so you may have noticed changes beforehand, but those weren’t “really” changes because they were being applied by some really cool software from Ezoic. I’ve temporarily turned off their experiments, so I can push my own changes forward, which is what you see right now.</p><p><img src="https://cloud.githubusercontent.com/assets/8849362/12326809/da2012c0-bb0d-11e5-8f7f-0b12cf0c2113.jpg" alt="Hueman Hexo Theme"></p><p>The theme you see is a slightly modified version of <a href="https://github.com/ppoffice/hexo-theme-hueman" target="_blank" rel="noopener">Hueman</a>. I needed something that was beautiful that I could get working quickly, and this was it. The reason I <em>needed</em> to change was because of a huge change to the back end of the site: I’ve moved from WordPress to a static generated site. In case you don’t know what that means, a static generated site is a site that let’s you author your pages and posts, etc. using something like markdown or plain HTML, but then you run a generator program that takes that content that you’ve written, and, combines it with a theme and creates an entire website filled with .html files.</p><p>Recently I’ve noticed that my site was being slow, plus WordPress was giving me inexplicable errors in the admin. The performance got so bad that my host (I’m on a shared hosting plan through HostGator) shut down my website’s account because it was using more than its allotted CPU and RAM resources way too often. I worked for days uninstalling and reconfiguring plugins to help the performance improve, which made it acceptable to my host, but it still wasn’t acceptable to me. So, static site it is!</p><p>I chose <a href="http://hexo.io/" target="_blank" rel="noopener">Hexo</a> as my generator because I went on <a href="https://www.staticgen.com/" target="_blank" rel="noopener">StaticGen.com</a> and chose the JavaScript-powered (Node-powered) site generator with the most stars and took off. The site is now significantly faster, though it could still be improved. Note, though, I no longer support IE&lt;9, which is freeing and helps me use a smaller version of jQuery. *smiles*</p><p>Now that it’s up and running, the next project is to create my own theme for it. Over 2 years ago <a href="http://www.joezimjs.com/javascript/rebranding-for-the-future/">I talked about rebranding the site</a> and I’m finally going to do it, though it could still take several months or more. I’m going to do my best to make the site beautiful and focus on the reading, but still let me afford to keep the site up and running through ads.</p><h2 id="Making-It-Better-for-You"><a href="#Making-It-Better-for-You" class="headerlink" title="Making It Better for You"></a>Making It Better for You</h2><p>I also have a few more changes in mind that will improve your experience on this site even more:</p><ol><li>Back to writing some more: I’ll be attempting to get back to a <em>more regular</em> schedule for writing. No guarantees, since I’m actually running a couple other sites now as well plus my 4th child was just born, but I at least hope to bump the number above the 4 that I wrote last year, 1 of which wasn’t actually written by me.</li><li>Better Performance: I mentioned that I got a performance gain by switching to a static generated site, now I hope to make it even better, by…<ul><li>taking more control over scripts/css to make sure there’s nothing being loaded that doesn’t need to be (mainly using a customized build of jQuery or even moving away from jQuery)</li><li>switching hosts to either Amazon S3 or Azure plus a more powerful CDN (this could also be a cheaper option than my current host)</li></ul></li><li>Remove ads altogether! This one depends on you guys, though. Some time soon-ish, I’ll be starting up a Patreon account and if you guys can support me enough, I’ll drop the ads, which will make loading faster and remove all the ugly bits of the site.</li></ol><h2 id="Conclusion"><a href="#Conclusion" class="headerlink" title="Conclusion"></a>Conclusion</h2><p>This site may have been largely dormant for the past year and a half or so, but I promise a better future. Let me know if you have any other suggestions in the comments or on social media. I really want to get this site in tip-top shape so your input can be <em>very important</em> to me. Thanks everyone!</p>]]></content:encoded>
      
      <comments>https://www.joezimjs.com/javascript/future-jz-javascript-now-ish/#disqus_thread</comments>
    </item>
    
    <item>
      <title>JavaScript Charting Made Easy With JSCharting</title>
      <link>https://www.joezimjs.com/javascript/javascript-charting-made-easy-with-js-charting/</link>
      <guid>https://www.joezimjs.com/javascript/javascript-charting-made-easy-with-js-charting/</guid>
      <pubDate>Mon, 19 Oct 2015 11:00:49 GMT</pubDate>
      <description>
      
        Doing visualizations in JavaScript is difficult, but JSCharting is a powerful library that can significantly improve development of visualizations, maps, and charts.
      
      </description>
      
      <content:encoded><![CDATA[<p>JSCharting is a capable JavaScript charting library with some advanced features and great rendering output.  It utilizes SVG, though as an end user developer, you don’t need to be familiar with or code SVG.  There is also some fallback in VML for backward compatibility with older versions of IE browsers. A free trial is available from <a href="http://jscharting.com/" target="_blank" rel="noopener">their site</a> if you wish to run the samples or follow along locally.  Online samples using codepen will also be embedded below.<a id="more"></a></p><div style="text-align:center;"><!-- Ezoic - In Content - under_first_paragraph --><div id="ezoic-pub-ad-placeholder-107"><!-- JZJS - In Content Responsive --><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-0471240617528503" data-ad-slot="9785736525" data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div><!-- End Ezoic - In Content - under_first_paragraph --></div><p>Here is an example demonstrating a number of interactive features.  Hover over the values to see tooltips and the legend adjust in real-time.</p><p data-height="468" data-theme-id="0" data-slug-hash="XmRJLj" data-default-tab="result" data-user="jsblog" class="codepen">See the Pen <a href="http://codepen.io/jsblog/pen/XmRJLj/" target="_blank" rel="noopener">Weather Patterns</a> (<a href="http://codepen.io/jsblog" target="_blank" rel="noopener">@jsblog</a>) on <a href="http://codepen.io" target="_blank" rel="noopener">CodePen</a>.</p><h3 id="Setting-Up"><a href="#Setting-Up" class="headerlink" title="Setting Up"></a>Setting Up</h3><p>JSCharting is easy to setup and work with. The following steps were used to get a chart up and running from scratch.  There are also a huge set of samples included you can use as a base for customization for a given visualization requirement.</p><p>First include jQuery and the JSCharting library files in your page:</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span> <span class="attr">src</span>=<span class="string">"/JSC/jquery-latest.min.js"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">"text/javascript"</span> <span class="attr">src</span>=<span class="string">"/JSC/JSCharting.js"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure><p>Next create an HTML <code>div</code> element to hold the chart:</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"chartDiv"</span> <span class="attr">style</span>=<span class="string">"width: 540px; height: 325px"</span>&gt;</span></span><br></pre></td></tr></table></figure><p>And use jQuery to select the DOM element and populate it with a chart through the jQuery plugin API:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$(<span class="string">'#chartDiv'</span>).JSC(chartOptions);</span><br></pre></td></tr></table></figure><p>The chart options define a series with four points using the following code:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> chartOptions = &#123;</span><br><span class="line">  series: [&#123;</span><br><span class="line">    name: <span class="string">'Saw'</span>,</span><br><span class="line">    type:<span class="string">'column'</span>,</span><br><span class="line">    points: [</span><br><span class="line">        &#123; <span class="attr">name</span>: <span class="string">'Q1'</span>, <span class="attr">y</span>: <span class="number">230</span>  &#125;,</span><br><span class="line">        &#123; <span class="attr">name</span>: <span class="string">'Q2'</span>, <span class="attr">y</span>: <span class="number">240</span>  &#125;,</span><br><span class="line">        &#123; <span class="attr">name</span>: <span class="string">'Q3'</span>, <span class="attr">y</span>: <span class="number">267</span>  &#125;,</span><br><span class="line">        &#123; <span class="attr">name</span>: <span class="string">'Q4'</span>, <span class="attr">y</span>: <span class="number">238</span>  &#125;</span><br><span class="line">    ]</span><br><span class="line">  &#125;]</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure><p>You can get a reference to the chart object itself by calling the <code>JSC()</code> function on the jQuery element bound to the chart without any parameters.</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> chart = $(<span class="string">'#chartDiv'</span>).JSC();</span><br></pre></td></tr></table></figure><h3 id="Chart-Types"><a href="#Chart-Types" class="headerlink" title="Chart Types"></a>Chart Types</h3><p>To specify a chart type, a simple setting such as <code>{type:&#39;column&#39;}</code>can be used. This can be set at the chart options level or at the series level. There are many chart types available in the library and some cases can be complex to set, however, JSCharting uses an interesting approach to simplify this configuration. All of the different chart types and options are defined within a hierarchy of chart types allowing settings such as <code>{type:&#39;funnelSquareInverted&#39;}</code> which traditionally would require separate settings such as <code>{ type:&#39;funnel&#39;, funnelShape:&#39;square&#39;, funnelOrientation:&#39;inverted&#39;}</code>.</p><p>JSCharting offers a large number of chart types which can be explored through <a href="http://jscharting.com/typeGallery.htm" title="JSCharting chart type Gallery" target="_blank" rel="noopener">their gallery</a>.</p><h3 id="Label-Tokens"><a href="#Label-Tokens" class="headerlink" title="Label Tokens"></a>Label Tokens</h3><p>A nice feature that makes the charts more dynamic are label tokens. These are predefined tokens at various levels which apply to the entire chart, to a series, or to individual points. For example, the chart title allows chart level tokens to be used as such:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#123; <span class="attr">titleLabelText</span>: <span class="string">'Acme Tool Sales Total: %sum Best Seller: %maxSeriesName'</span> &#125;</span><br></pre></td></tr></table></figure><p>At the series level, we can specify tokens for the legend entries as follows:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#123; <span class="attr">defaultSeriesLegendEntryText</span>: <span class="string">' %name  %sum'</span> &#125;</span><br></pre></td></tr></table></figure><p>These tokens work automatically in most labels, tooltips, urls, and other text associated with the chart, series, or point. The following example demonstrates these two property settings.</p><p data-height="380" data-theme-id="0" data-slug-hash="vNmEqj" data-default-tab="result" data-user="jsblog" class="codepen">See the Pen <a href="http://codepen.io/jsblog/pen/vNmEqj" target="_blank" rel="noopener">vNmEqj</a> (<a href="http://codepen.io/jsblog" target="_blank" rel="noopener">@jsblog</a>) on <a href="http://codepen.io" target="_blank" rel="noopener">CodePen</a>.</p><h3 id="Code"><a href="#Code" class="headerlink" title="Code"></a>Code</h3><p>The chart options are coded using a well organized declarative API which separates the internal functionality and programming concepts from charting concepts and settings.  The end result is a solution that enables developers to do what they need, with less time, less code and less confusion.</p><p>The library has the ability to identify a misspelled option setting and warn the developer before a chart goes live. This internal API database has been leveraged in another interesting way. There is a setting used in the example above: <code>{ defaultSeriesLegendEntryText: &#39; %name  %sum&#39; }</code>. However, this is not an actual property name within the API. This is defined as <code>defaultSeries:{ legendEntry:{ text:&#39;%name  %sum&#39;}}</code>. Yet, the chart can recognize that defaultSeries is a property, and that legendEntry is a property of it, and that legendEntry contains a text property. Therefore, it allows this setting to be used. Developers are free to use this shortcut syntax or utilize the fully expanded syntax based on their preferences.</p><h3 id="Smart-Tooltips"><a href="#Smart-Tooltips" class="headerlink" title="Smart Tooltips"></a>Smart Tooltips</h3><p>The automatic tooltips are well suited to annotate data without any specific settings in most cases. The chart examines the axis labels and formatting to create a descriptive tooltip for each point by default. For example, when we define a y axis label and formatting with this code:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">yAxis: &#123;</span><br><span class="line">  labelText: <span class="string">'Sales (USD)'</span>,</span><br><span class="line">  formatString: <span class="string">'c'</span> <span class="comment">/*Currency Formatting*/</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>The tooltip automatically describes the y value of the point with text such as “<strong>Sales (USD)</strong>: $434.22”</p><p>JSCharting often surprises you with little details that save developers time and extra code to get a polished result.</p><h3 id="Mapping"><a href="#Mapping" class="headerlink" title="Mapping"></a>Mapping</h3><p>The new mapping chart type offers an integrated set of world countries and their states / provinces. These maps can be viewed through the following sample <a href="http://jscharting.com/Samples/Javascript_MapDataBrowser_Chart.htm" title="JS World Country Maps" target="_blank" rel="noopener">JS Maps of all world countries</a>.</p><p>It’s nice that you don’t have to find shapefiles or geoJSON source files to make a map as the various geographic areas are pre-optimized and ready to use. You also don’t need to learn a new mapping based configuration API and can continue to leverage the standard series and points you are already familiar with.</p><p>Drawing a simple map of the US is possible with only these few chart options:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  type: <span class="string">'map'</span>,</span><br><span class="line">  series: [</span><br><span class="line">    &#123;<span class="attr">map</span>: <span class="string">'US'</span>&#125;</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>Modifying this chart to show Illinois in red is accomplished by adding a point the the US series bound to IL and a color setting as follows:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  type: <span class="string">'map'</span>,</span><br><span class="line">  series: [&#123;</span><br><span class="line">    map: <span class="string">'US'</span>,</span><br><span class="line">    points:[</span><br><span class="line">      &#123;<span class="attr">map</span>: <span class="string">'US.IL'</span>, <span class="attr">color</span>: <span class="string">'red'</span>&#125;</span><br><span class="line">    ]</span><br><span class="line">  &#125;]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p data-height="410" data-theme-id="0" data-slug-hash="NGjaQr" data-default-tab="result" data-user="jsblog" class="codepen">See the Pen <a href="http://codepen.io/jsblog/pen/NGjaQr/" target="_blank" rel="noopener">Weather Patterns</a> (<a href="http://codepen.io/jsblog" target="_blank" rel="noopener">@jsblog</a>) on <a href="http://codepen.io" target="_blank" rel="noopener">CodePen</a>.</p><p>JSCharting provides a context feature for its geographic mapping charts that automatically offers context for the primary map through an optional list of areas to draw in the background. For example, if my series only showed a point for <code>US.IL</code>, using this setting would draw the rest of the US around it, but without having any other effect on the chart like adjusting the zoom or view portal to the full extent of the US map boundary.  Context mapping areas are also drawn in neutral tones to not draw attention away from the primary area of interest.</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#123; <span class="attr">mappingBaseLayers</span>: <span class="string">'US'</span> &#125;</span><br></pre></td></tr></table></figure><p>Maps can also be loaded dynamically (in real-time) and zoomed interactively.<br>After a chart is initialized, adding a country map is as easy as:</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chart.addSeries(&#123; <span class="attr">map</span>:<span class="string">'US'</span> &#125;);</span><br></pre></td></tr></table></figure><p>This codepen illustrates the flexibility of the mapping component of JSCharting quite well along with the aforementioned dynamic loading features:</p><p data-height="450" data-theme-id="0" data-slug-hash="LpyEoz" data-default-tab="result" data-user="jsblog" class="codepen">See the Pen <a href="http://codepen.io/jsblog/pen/LpyEoz/" target="_blank" rel="noopener">Click to load maps.</a>  (<a href="http://codepen.io/jsblog" target="_blank" rel="noopener">@jsblog</a>) on <a href="http://codepen.io" target="_blank" rel="noopener">CodePen</a>.</p><p>For more examples of mapping ease of use and functionality, check out their <a href="http://jscharting.com/Javascript_Map_Charts.htm" title="JS Map Features" target="_blank" rel="noopener">map feature gallery</a>.</p><h3 id="Conclusion"><a href="#Conclusion" class="headerlink" title="Conclusion"></a>Conclusion</h3><p>JSCharting gets you up and running quickly with a full set of vector and resolution independent chart types to meet your visualization needs.  With such a crowded field of charting tools that all claim to do the same job, JSCharting aims to do the same with a more intuitive API and less code while generating a result that gets more things right by default (which in turn, saves more code).  For developers, more code equals more time and the reason we choose to use a charting library in the first place is to save time (vs hacking away with D3 or building something from the ground up)!  JSCharting has a level of polish and the more you work with it, the more niceties you discover.</p><script async src="//assets.codepen.io/assets/embed/ei.js"></script>]]></content:encoded>
      
      <comments>https://www.joezimjs.com/javascript/javascript-charting-made-easy-with-js-charting/#disqus_thread</comments>
    </item>
    
    <item>
      <title>Making Up for Misplaced Passion</title>
      <link>https://www.joezimjs.com/uncategorized/making-up-for-misplaced-passion/</link>
      <guid>https://www.joezimjs.com/uncategorized/making-up-for-misplaced-passion/</guid>
      <pubDate>Tue, 28 Apr 2015 11:00:11 GMT</pubDate>
      <description>
      
        I have shown a lot of passion for my profession, which is a good thing, but I need to also show an even greater passion for a God who is far more important.
      
      </description>
      
      <content:encoded><![CDATA[<p>I love JavaScript. I love programming in general, but despite its numerous downsides, I have enjoyed JavaScript more than any other language, especially with the recent developments coming in ES2015. There is just one problem: God is supposed to be my primary love and JavaScript shouldn’t even be in the top 3, and I have shown very little love for God in a way that the masses could distinguish.<a id="more"></a></p><div style="text-align:center;"><!-- Ezoic - In Content - under_first_paragraph --><div id="ezoic-pub-ad-placeholder-107"><!-- JZJS - In Content Responsive --><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-0471240617528503" data-ad-slot="9785736525" data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div><!-- End Ezoic - In Content - under_first_paragraph --></div><h2 id="Why-Should-I-Love-God"><a href="#Why-Should-I-Love-God" class="headerlink" title="Why Should I Love God"></a>Why Should I Love God</h2><p>First off, I know for a fact that God is real and that He also loves me. Don’t bother debating me on that because you’ll either lose (and therefore potentially win in the best way), or we’ll have a stalemate due to stubbornness. Anyway, He has done so much for me.</p><p>Specifically:</p><ul><li>He created me.</li><li>He humbled himself from the ultimate being of the universe down to being a poor human for our sake.</li><li>He was sinless so that I didn’t have to be.</li><li>He gave up his life in the most excruciating way physically and spiritually so that I would be able to draw near to him, blameless, and spend eternity with my creator instead of spending eternity in a place of torment.</li></ul><p>Why wouldn’t I want to love such a wonderful God?</p><h2 id="Passion-Redirection"><a href="#Passion-Redirection" class="headerlink" title="Passion Redirection"></a>Passion Redirection</h2><p>I’m glad that I have been unable to build this blog up as much as I had hoped/planned, because it is now still a personal blog and I cannot have anyone telling me what I may or may not post on here. This is good, because I hope to now write about what God is doing and has done in my life and in the world more often here.</p><p>Don’t worry too much if you’re just here for the JavaScript stuff and could care less about a Christian talking about God; I will still be writing about JavaScript, as this _is_ a JavaScript blog. I’ll be trying to keep the “awesome”s and such to a minimum, though, since nothing is more awesome than God.</p><h2 id="Conclusion"><a href="#Conclusion" class="headerlink" title="Conclusion"></a>Conclusion</h2><p>Now that I’ve gotten that out there, I’ll be signing off for now. In the meantime, you can read my <a href="/uncategorized/saving-bits-and-pixels-the-geeks-gospel/" title="Saving Bits and Pixels: The Geek&#39;s Gospel">explanation of the Gospel for geeks</a>. God bless and happy coding.</p>]]></content:encoded>
      
      <comments>https://www.joezimjs.com/uncategorized/making-up-for-misplaced-passion/#disqus_thread</comments>
    </item>
    
  </channel>
</rss>
