<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Matthew Goo on Medium]]></title>
        <description><![CDATA[Stories by Matthew Goo on Medium]]></description>
        <link>https://medium.com/@moog16?source=rss-d4056a20caa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*DevhL_y2N6OJHaSViDBd5g.jpeg</url>
            <title>Stories by Matthew Goo on Medium</title>
            <link>https://medium.com/@moog16?source=rss-d4056a20caa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 13:19:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@moog16/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Ford Transit 350 camper van details]]></title>
            <link>https://medium.com/@moog16/ford-transit-350-camper-van-details-f01e7c80c1c6?source=rss-d4056a20caa------2</link>
            <guid isPermaLink="false">https://medium.com/p/f01e7c80c1c6</guid>
            <dc:creator><![CDATA[Matthew Goo]]></dc:creator>
            <pubDate>Sun, 11 May 2025 18:37:12 GMT</pubDate>
            <atom:updated>2025-05-11T18:37:12.382Z</atom:updated>
            <content:encoded><![CDATA[<img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f01e7c80c1c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working with Sass & Create React App v2]]></title>
            <link>https://medium.com/@moog16/working-with-sass-create-react-app-v2-69c9629319b1?source=rss-d4056a20caa------2</link>
            <guid isPermaLink="false">https://medium.com/p/69c9629319b1</guid>
            <category><![CDATA[help]]></category>
            <category><![CDATA[sass]]></category>
            <category><![CDATA[node-sass]]></category>
            <category><![CDATA[create-react-app]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Matthew Goo]]></dc:creator>
            <pubDate>Thu, 08 Nov 2018 05:43:47 GMT</pubDate>
            <atom:updated>2018-11-08T05:43:47.744Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gBYDPAsQsbRJRCaK0Jhf4Q.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/P6s8EbcSgmA?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Jacob Mejicanos</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Create React App is one of the most beloved tools of the frontend community (<a href="https://npm-stat.com/charts.html?package=create-react-app&amp;from=2017-11-08&amp;to=2018-11-07">approaching ~2M</a> as of writing this). When I heard <a href="https://reactjs.org/blog/2018/10/01/create-react-app-v2.html">Sass and CSS Modules were being supported</a> right of the box, I was pretty excited! CRA could potentially be used as a production app without ejecting. Gone were the days of configuring Webpack!</p><h3>The Let Down…</h3><p>Like most developers, I whipped out my computer and npm installed the updated CRA, and installed my <a href="https://github.com/material-components/material-components-web-react/tree/master/packages/button">favorite React Button</a>. I added basic markup to App.js and npm start‘ed. I ran into the error…</p><pre>File to import not found or unreadable: @material/react-button/index.<br>      in /Desktop/my-app/src/App.scss (line 1, column 1)</pre><p>btw my App.scss looked like this:</p><pre>@import &#39;@material/react-button/index&#39;; // pretty simple, right??</pre><h3>Long Story Short</h3><p>Basically the issue is the MDC Web and React libraries don’t have a ~ in front of their Sass import names (~@material/react-button/index). If that tilda existed, node-sass knows that the file path is found in the node_modules directory. But there are other flavors of Sass (ie. ruby-sass), which do not use the ~ convention — so sucks for us JS people.</p><p>Hours of Googling and reading and responding on forums, I finally found <a href="https://github.com/material-components/material-components-web/issues/3985#issuecomment-434406165">a solution</a> (credit goes to @<a href="https://github.com/robcaldecott">robcaldecott</a>). Basically node-sass has an environment variable hook, when set is used to resolve imports. And thus was born my SASS_PATH entry in my .bash_profile (for the MacOSX users out there). It looks like this:</p><pre>// relative path to your node_modules from your app root directory<br>export SASS_PATH=./node_modules</pre><p>Source the .bash_profile, and voila all your npm imports with Sass now work! Again all was right in the world.</p><p>For those of you not on Mac, or need more instruction on environment variables, check out <a href="https://github.com/material-components/material-components-web-react/blob/v0.6.2/docs/adding-env-variables.md">this doc</a>. Just wanted to share this easy and amazing one-liner to save you headache and get you using CRA as intended.</p><p><em>Happy Coding!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69c9629319b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rules of Npm Packaging]]></title>
            <link>https://medium.com/@moog16/rules-of-npm-packaging-16a40c5d7e30?source=rss-d4056a20caa------2</link>
            <guid isPermaLink="false">https://medium.com/p/16a40c5d7e30</guid>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[build-tool]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[es6]]></category>
            <dc:creator><![CDATA[Matthew Goo]]></dc:creator>
            <pubDate>Thu, 16 Aug 2018 18:10:32 GMT</pubDate>
            <atom:updated>2018-08-16T18:10:32.398Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MWW1yjbTpAYZQOoYL-fg7g.jpeg" /><figcaption>Photo creds: <a href="https://unsplash.com/@erdaest?utm_medium=referral&amp;utm_campaign=photographer-credit&amp;utm_content=creditBadge">Erda Estremera</a></figcaption></figure><p>There is no one way to skin a cat. This is also true when building a library of components, tools, frameworks, etc. There is no guide out there telling you how to build these things, or what the best practices are — but I’m here to tell you <strong>THIS </strong>is one of those things you must follow when building a JavaScript library.</p><blockquote><em>You should always default export your npm packages as ES5.</em></blockquote><blockquote>This write up is under the assumption your library is on npm, that you have both ES5 and ES6+ modules served from the npm package, but export the ES6+ by default.</blockquote><h3>A few definitions</h3><ul><li><em>transpiling</em> — compiling ES6+ to ES5, or compiling ES6+ code to better support older browsers with less features.</li><li><em>ES6+</em> — <a href="https://codeburst.io/javascript-wtf-is-es6-es8-es-2017-ecmascript-dca859e4821c">JavaScript versions</a>, including ES2016, ES2017, ES.Next, and beyond.</li><li><em>ES5</em> — ES5 is supported by all major browsers (Chrome, Firefox, Safari, Edge, IE11 (I know…)). Let’s call it universally accepted.</li><li><em>Your users</em> — end developers using/implementing your library of components, tools, etc.</li><li><em>Build tools — </em>Tools that bundle your JavaScript dependencies together. Think Webpack, Rollup, SystemJS, Browserify.</li></ul><h3>Reasons you might argue against it</h3><ol><li>My developer audience all use a build tool that goes through a transpiling build step, so my library can by default provide ES6+.</li><li>Transpiling with a build tool increases file size.</li><li>You can’t take advantage of <em>treeshaking</em> after transpiling my ES6+.</li><li>I’m worried that ES6+ developers will have issues with importing ES5.</li></ol><p>I’m here to put these concerns to rest.</p><h3>ES5 is Universal</h3><p>Its fair to say that Webpack is the most used module bundler in the community. Webpack by default does <em>not</em> transpile dependencies (ie: node_modules). This means when a developer using your library and imports your ES6+ code, they will run into issues if they are trying to support browsers not supporting ES6+ syntax. Some ES6+ syntax that is not featured in ES5 include: class, extends, Object.assign, the rest operator (...myObject).</p><p>Yes, there are a few work arounds or plugins that people could use to fix this problem, but why frustrate your users. Why have them dig into your source code and figure things out? That’s how you lose users. The simple solution: <em>default </em>provide ES5 up front to your users.</p><p><strong>MYTH BUSTED</strong></p><h3>ES-Which?</h3><p>Its hard to keep track of what ES version you might be on, or what each version supports/lacks. I honestly couldn’t tell you the difference. But there in lies the problem. Which ES version or transpiler should your library support? There are 10 versions of EcmaScript versions out there, and at least <a href="https://ilikekillnerds.com/2015/01/transpiling-wars-6to5-vs-traceur/">2 major transpiliers</a> (<a href="https://babeljs.io/">Babel</a>, <a href="https://github.com/google/traceur-compiler">Traceur</a>) with new ones the rise (<a href="https://buble.surge.sh/guide/">Buble</a>). Transpilers do have differences between them, and may/may not support the features you’re using in your ES6+ library code.</p><p>So even if you think your end developer is using a build tool that is transpiling your code (probably not by default), they could be using a different transpiler with different features.</p><p>So, again, just default export ES5 files.</p><p><strong>MYTH BUSTED</strong></p><h3><strong>File size doesn’t matter</strong></h3><p>I appreciate that you’re still with me reading this after reading the above.</p><p>Let’s take <a href="https://github.com/material-components/material-components-web-react/tree/master/packages/top-app-bar">MDC React’s Top App Bar Component</a> as an example. The ES6 file size is 5kb. The transpiled version is 11kb. The minified version is 6kb (without comments, whitespace, but not uglified). So sure…we increased the (minified) file size by 20%, but the net increase is negligible. Especially considering in the grand scheme of an app using frameworks such as React+ReactDOM, Angular, Ember, etc., this component file size doesn’t matter.</p><p><strong>MYTH BUSTED</strong></p><h3>What TreeShaking?</h3><p>For those of you who don’t know, TreeShaking is a feature that is built into most build tools. It is meant to remove unused code from your bundle.js file, which in turn decreases the size of your payload. This makes sense and is a great feature!</p><p>True, that you must use the import and export module syntax in order to get TreeShaking to work (at least for Webpack). However, this is an advanced feature. <em>Advanced</em> features are for <em>advanced</em> users, who know how to dig into your /dist directory and find the correct file they need.</p><p>So include both ES6+ and ES5 files, but still default to your npm package export to ES5 files for all your library users out there just trying to get a prototype working.</p><p><strong>MYTH PLAUSIBLE</strong></p><h3>Life is Like a Box of Chocolates</h3><p>This section isn’t much of a myth, but just another point as to why defaulting to ES5 files is important. Take this example <a href="https://github.com/moog16/browserify-no-build-import-node-modules">repo</a> for example. Clone it/download it, and run yarn build. It’s not working! Why? Well its being bundled with Browserify, which doesn’t understand the import or export module syntax (<a href="https://webpack.js.org/concepts/modules/#what-is-a-webpack-module">not a problem in Webpack</a>).</p><p>Browserify may be older and less popular than other bundlers, but like life, development <em>is like a box of chocolates</em>, and you can’t predict how your library will be used.</p><p>So instead of having your users bang their heads, just default export your npm package in ES5 format.</p><h3><strong>Makes Sense, How Do I ES5?</strong></h3><p>We’ve pretty much discussed most of the reasons why we want to provide ES5 by default. So how do we do it??</p><p>Glad you asked.</p><p>The package.json of your package should contain a main property, which points to the default file that the npm package should export.</p><pre>{<br>  &#39;name&#39;: &#39;my-amazing-app,<br>  &#39;main&#39;: &#39;./dist/my-es5-file.js&#39;<br>}</pre><p>And that’s it…</p><h4>How do I test this?</h4><p>Assume you have this project structure:</p><pre>- my-amazing-app<br>  - app.js<br>  - package (directory)<br>    - index.js<br>    - app.css<br>    - package.json<br>    - dist<br>      - my-es5-file.js</pre><p>Then in your app.js file:</p><pre>import superPackage from &#39;./package&#39;;</pre><pre>superPackage.makeTeleporter();</pre><p>Voila! It should now be importing ES5 code. You can check this by bundling(building) your app and checking to see that there is no ES5 syntax in your bundle.</p><blockquote>Without the main property in your package.json npm will by default use the index.js file.</blockquote><h3>Did You Hear Me?</h3><p>My hope is you see that exporting your ES6+ code is a problem, but the solution of which only has upsides. As creators/maintainers of JavaScript libraries we need to be helpful by lowering the barrier to entry for our users. This in turn will increase by word of mouth, how great your library is and increase your usage. Increasing your usage may/may not be one of your goals, but it sounds pretty cool.</p><p>So if there is one thing you got out of this, is that you should use the main property in your package’s package.json file and point to your ES5 formatted file, and make the world a better place.</p><p>Thanks for listening!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16a40c5d7e30" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Replacing PhantomJS for HeadlessChrome]]></title>
            <link>https://medium.com/points-san-francisco/replacing-phantomjs-for-headlesschrome-1e0b2baa5189?source=rss-d4056a20caa------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e0b2baa5189</guid>
            <category><![CDATA[chrome]]></category>
            <category><![CDATA[javascript-testing]]></category>
            <category><![CDATA[karma]]></category>
            <category><![CDATA[headless]]></category>
            <category><![CDATA[phantomjs]]></category>
            <dc:creator><![CDATA[Matthew Goo]]></dc:creator>
            <pubDate>Fri, 09 Jun 2017 00:20:39 GMT</pubDate>
            <atom:updated>2017-06-09T00:20:39.221Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*T36XWbcZtBFgnz1zAFX9ow.jpeg" /></figure><p>Like all great things, they must come to an end. PhantomJS you have been there for us for so long, and yet I’m sorry to say but now we must say goodbye. Many of you recently may have seen this post: <a href="https://groups.google.com/forum/#!topic/phantomjs/9aI5d-LDuNE">https://groups.google.com/forum/#!topic/phantomjs/9aI5d-LDuNE</a>, which was my red flag to begin removing Phantom in replacement of Chrome. And when Chrome <a href="https://developers.google.com/web/updates/2017/04/headless-chrome">announced v59.0</a> was stable, I thought it was time .</p><p>Over the past few years I’ve used PhantomJS on countless projects. It has worked very well, although not to say there is the occasional feature that does not work on PhantomJS. Safari, Firefox, Chrome, IE, and PhantomJS all have their differences, and if you’re a frontend guy ( or girl ) like me you’re probably using Chrome. In my experience I can think of about 1 or 2 times that I’ve had issues with the Chrome API and PhantomJS API differing. Or maybe ( most likely ) I was using it incorrectly.</p><p>Anyways I’m here to talk about Headless Chrome and how easy it is to replace PhantomJS with it. This has probably been the smoothest switch of technologies with regards to testing I’ve ever done. I just want to share with you what I did incase its not going smoothly for you! FYI this is for people that use <a href="https://karma-runner.github.io/1.0/index.html"><strong>Karma Runner</strong></a>. But I’m sure a lot of it can be applied to whatever frameworks/tools you may be using.</p><ol><li>update to latest version of Chrome v59.0</li><li>update to the latest <a href="https://github.com/karma-runner/karma-chrome-launcher"><strong>karma-chrome-launcher</strong></a> (my version = v2.1.1).</li><li>Created a customLauncher block in my karma.conf.js file. This is a feature of karma-chrome-launcher that allows you to create a new instance of Chrome with certain properties. You can set things like window size, headless mode, etc.</li></ol><pre>// karma.conf.js<br>{<br>  // rest of config file</pre><pre>  browsers: [&#39;Chrome_headless&#39;],</pre><pre>  customLaunchers: { <br>    Chrome_headless: { <br>      base: ‘Chrome’,<br>      flags: [<br>        ‘ — headless’,<br>        ‘ — disable-gpu’,<br>        ‘ — remote-debugging-port=9222’ <br>      ] <br>    } <br>  }<br>}</pre><p>3. If you have a “debug” mode, where you can open a regular instance of Chrome for debugging purposes, then you may want to update the `browsers` property:</p><pre>browsers: isDebugMode ? [&#39;Chrome&#39;] : [&#39;Chrome_headless&#39;]</pre><p>And that is basically it!</p><h3>Continous Integration?</h3><p>You may be thinking…alright it works locally on my dev machine, but what about my continuous integration server, Matt?? Well our server’s here run on Linux Ubuntu and my only issue was needing to update to the latest Chrome. This issue was easily solved by a quick Google: <a href="https://www.ubuntuupdates.org/ppa/google_chrome?dist=stable">https://www.ubuntuupdates.org/ppa/google_chrome?dist=stable</a>.</p><pre>wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -</pre><pre>sudo sh -c &#39;echo &quot;deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main&quot; &gt;&gt; /etc/apt/sources.list.d/google.list&#39;</pre><pre>sudo apt-get update<br>sudo apt-get install google-chrome-stable</pre><p>And that’s completely it!</p><p>Although its sad to see PhantomJS go, its really not sad. Because now we no longer need to worry about another browser. We can develop on Chrome, and run our tests on Chrome. That list of 5 browsers that we need to support (Firefox, IE, etc) is now just 4. That means your life as a frontend developer just became that much easier.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e0b2baa5189" width="1" height="1" alt=""><hr><p><a href="https://medium.com/points-san-francisco/replacing-phantomjs-for-headlesschrome-1e0b2baa5189">Replacing PhantomJS for HeadlessChrome</a> was originally published in <a href="https://medium.com/points-san-francisco">Points San Francisco</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What I Wish I Knew 6 Days Ago — The Missing Guide for Gulp/Webpack-Dev-Server/BrowserSync]]></title>
            <link>https://medium.com/points-san-francisco/what-i-wish-i-knew-6-days-ago-9f27c6c6ba02?source=rss-d4056a20caa------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f27c6c6ba02</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[hotloader]]></category>
            <category><![CDATA[browsersync]]></category>
            <category><![CDATA[webpack-2]]></category>
            <dc:creator><![CDATA[Matthew Goo]]></dc:creator>
            <pubDate>Thu, 09 Mar 2017 05:56:52 GMT</pubDate>
            <atom:updated>2017-03-10T04:16:18.075Z</atom:updated>
            <content:encoded><![CDATA[<h3>What I Wish I Knew 6 Days Ago — The Missing Guide for Gulp/Webpack-Dev-Server/BrowserSync</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9_Ylubv_uiEekHRe9_IEEg.jpeg" /></figure><p>Recently I spent 6 days scouring the web for answers- specifically on how to create a frontend build process that has the following:</p><ul><li>Gulp: compiles sass to css</li><li>Gulp: compiles handlebars to html</li><li>Webpack: bundles javascript</li><li>Webpack-dev-server: serves static files, the bundle.js, and hot reloads all javascript changes</li><li>BrowserSync: updates css without losing state</li></ul><p>This is my second time configuring webpack, and it was not any easier. That tool is a monster — it’s like using a chainsaw equipped with sonar, a compass and diamond studded blades for the purpose of mowing your lawn. Well, it’s actually pretty badass once it starts working, but I’m just trying to illustrate my frustration with the tool. So when you add Gulp and hot reloader into the mix, things start to get messy.</p><p>version usage:</p><ul><li>Webpack: v2.2.1</li><li>Webpack-dev-server: v2.4.1</li><li>Gulp: v3.9.1</li><li>BrowserSync: v2.18.8</li><li>BrowserSyncWebpackPlugin: v1.1.4</li></ul><h3>WHY???</h3><p>Why go through all this trouble? Why use all those tools when Webpack and webpack-dev-server do that for you? Why challenge yourself to build something so unnecessary? Well, the fact of the matter is that it was very necessary! Let me explain to you in a few bullets what I am building:</p><ul><li>1 React/Redux SPA that has multiple styled themes for different clients</li><li>Every color, font, icon differs from other clients.</li><li>Features can be turned off/on from a javascript config</li></ul><p>Hope that 1st line really sums it up, but to go into more depth — Webpack really isn’t meant for the type of build I’m describing. There are 2 things about each client that differ: 1) sass config, 2) javascript config. Almost 99% of the code that we write for the app is exactly the same, we just have logic that uses those configs to change the app appropriately.</p><p>The problem isn’t necessarily how Webpack bundling works. The problem is that it isn’t smart enough to know that just a few lines are different from another app (or maybe I’m not smart enough to figure out how to configure that). In any case, I originally only used Webpack and webpack-dev-server and I was forced to do some fancy things that ended up not making sense for us. Whenever we deployed it would take up to 10–12 minutes. Webpack would use around 2GB of RAM while bundling everything together, and that would kill our deployer. All because of the 1% code differences from client to client.</p><h3>Solution</h3><p>Currently we only have at most 5 clients on this system, and it takes forever. I realized the more clients we add (hopefully one day will be in the 1,000s. Isn’t that always the goal?), the longer it would take and eventually our deployer would run out of memory and not be able to complete a build. So I decided to separate concerns and use Gulp to compile all styles and templates, while having Webpack do what it does best and bundle just the javascript.</p><p>Here is the Webpack config (in real life it’s separated into a few files. I’ve also removed some details):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17c3fcd39c6b06c5dabe42fc86346177/href">https://medium.com/media/17c3fcd39c6b06c5dabe42fc86346177/href</a></iframe><p>All fairly standard stuff. If you you Google for Webpack examples then I’m sure you would see some flavor of what I have shown above (maybe something more elegant).</p><p>Then we have the production Gulpfile.js to build the sass:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d39f5d9c424586c237442bd426c9b933/href">https://medium.com/media/d39f5d9c424586c237442bd426c9b933/href</a></iframe><p>Again a very simple gulp-sass implementation. What’s even more boring is my html build and production build. Just to be thorough at a high level the following is my production task:</p><pre>gulp.task(“build:all”, [<br>  ‘setNodeEnvProd’,       // NODE_ENV=&#39;production&#39;<br>  ‘renderProdTemplate’,   // creates all index.html for all clients<br>  ‘copyAll’,              // copies all static assets into /static<br>  ‘clean’                 // cleans out previous /static folder<br>]);</pre><pre>// NOTE: /static is where all asset files are being served from</pre><p>What is most interesting and my motivation for writing this blog is the developer setup in Gulpfile.js and the watch task that runs BrowserSync to update the css.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03c92694502a942214c4c3cb8cff103b/href">https://medium.com/media/03c92694502a942214c4c3cb8cff103b/href</a></iframe><p>I’ve commented the above code to highlight what is/isn’t important for you. The next magic is an inspiration I found from this blog post: <a href="https://medium.com/@_jh3y/how-to-css-streaming-injection-with-browsersync-194edc6cd774#.xazgmyb0z">https://medium.com/@_jh3y/how-to-css-streaming-injection-with-browsersync-194edc6cd774#.xazgmyb0z</a>, which might also help you. Thanks <a href="https://medium.com/u/74b14e4c53bf">Jhey Tompkins</a> — you saved me!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e5dc3d707ba86c5cb5834c66e9764a1/href">https://medium.com/media/7e5dc3d707ba86c5cb5834c66e9764a1/href</a></iframe><p>Hopefully you have stayed with me up until now. If you are as desperate as I was, I understand why. But here’s the magic that lies in front of your eyes:</p><pre>browserSyncInstance.stream()</pre><p>This is what took me so long to figure out. This is what reloads the css without losing the state of the app. Clean and simple (if only everything were like that). Of course when you go back to the documentation and read it for the 20th time it makes sense.</p><h3>Hot Loader</h3><p>If you found the above helpful, another big pain point I felt was getting hot-loader to work with my new Gulp/webpack-dev-server setup. It worked right out of the box with Webpack and webpack-dev-server. But now you actually have to set somethings up, and actually modify some of your code.</p><p>Essentially the only thing that is missing is module.hot code at the bottom of any file(s) that need to be watched and updated. Code looks like:</p><pre>// index.js</pre><pre>import Root from &#39;./Root&#39;;<br>import ReactDOM from &#39;react-dom&#39;;<br>// AppContainer is a necessary wrapper component for HMR<br>import { AppContainer } from &#39;react-hot-loader&#39;;<br>import { Provider } from &#39;react-redux&#39;;<br>import configureStore from &#39;./reducers/utils/configureStore&#39;;</pre><pre>const store = configureStore();</pre><pre>const render = (RootContainer) =&gt; {<br>  ReactDOM.render(<br>      &lt;AppContainer&gt;<br>        &lt;Provider store={store}&gt;<br>          &lt;RootContainer store={store} /&gt;<br>        &lt;/Provider&gt;<br>      &lt;/AppContainer&gt;,<br>    document.getElementById(&#39;app&#39;)<br>  );<br>}</pre><pre>render(Root);</pre><pre>if(module.hot) {<br>  module.hot.accept(&#39;./Root&#39;, () =&gt; {<br>    const NewRoot = require(&#39;./Root&#39;).default;<br>    render(NewRoot);<br>  });<br>}</pre><p>module.hot is a global variable that is injected via Webpack when you include the react-hot-loader/patch . You don’t have to worry about production, since module.hot should not be included in your production webpack configuration. What is going on in that chunk of code is after webpack has recompiled the app changes, the callback is called and imports the new &lt;Root /&gt; element and calls render. The only changes that will be picked up will be within that &lt;Root /&gt; element. So if you ever change something in the <em>index.js</em>(above file) you will need to perform a refresh of the page. This is fine as it shouldn’t be that often.</p><p>In order to achieve this I had to perform a few changes to my <em>index.js. </em>I had to create a new RootContainer and move around my routes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0ef770bf7a4dc75fb5842549714eb16/href">https://medium.com/media/a0ef770bf7a4dc75fb5842549714eb16/href</a></iframe><p>You can see above that I actually wrapped the routes in their own component, while before they lived within the &lt;Provider /&gt; element in the <em>index.js</em> file. This approach is actually a lot nicer as it adheres more closely to our component patterns, and we can attach some logic to the lifecycle methods — this makes it much more readable. There is some weirdness where we have to only render the routes once, which explains my <em>setupRoutes</em> method. There are a couple ReactRouter issues: `Warning: [react-router] You cannot change &lt;Router routes&gt;; it will be ignored`. So if you get some error like that you will need to only render those once in the lifetime of the app.</p><p>I can’t imagine you would need to put that module.hot anywhere else if you have a hierarchy like the one I have shown above (which I greatly simplified). So you should only need to include it once. However, since I have Redux (you may have Flux or Mobx), you may also need a module.hot there.</p><pre>// configureStore.js</pre><pre>import { createStore, applyMiddleware, combineReducers } from &#39;redux&#39;;<br>import thunk from &#39;redux-thunk&#39;;<br>import { browserHistory } from &#39;react-router&#39;;</pre><pre>// this is an aggregation of all my reducers in an index.js<br>import reducer from &#39;../&#39;;<br>import { routerMiddleware } from &#39;react-router-redux&#39;;</pre><pre>export default () =&gt; {<br>  const store = createStore(<br>    reducer,<br>    applyMiddleware(thunk, routerMiddleware(browserHistory)));</pre><pre>  if(module.hot) {<br>    module.hot.accept(&#39;../&#39;, () =&gt; {<br>      const newReducer = require(&#39;../&#39;).default;<br>      store.replaceReducer(newReducer);<br>    });<br>  }</pre><pre>  return store;<br>}</pre><p>Very similar to my above component module.hot if statement. This will pick up any changes you have in your reducers. You may also need one for your action-creators, but I haven’t yet visited that area of the code. I can’t imagine after seeing these two examples that it would be too difficult to figure out.</p><h3>Conclusion</h3><p>The development build that I said was taking 10–12 minutes is now taking 1:30–2 minutes. This will increase every time we add a client, but it shouldn’t be by much, and it will only increase the sass compilation (not the js or html, etc). <strong>So bottom line</strong>: it will always be 1:30–2 minutes flat, which should put you to sleep at night when trying to take over the world.</p><p>The power of Webpack is in your hands. You have the responsibility and duty to make it work for you. Although the setup time takes a while, it is all worth it in the end. The development process is lightning fast with hot-loader, and in my experience the best that is out there to date. You can go hours without refreshing a page, losing state, or losing things in your js console (of course you have the preserve log option). I hope this tutorial/rundown gives you the knowledge you need to complete your build setup.</p><p><em>Stay sexy!</em></p><p><strong>Note:</strong> Along with all these changes I also did upgrade from webpack 1 to webpack 2. Really not that bad of a migration. You should take the hour to do it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f27c6c6ba02" width="1" height="1" alt=""><hr><p><a href="https://medium.com/points-san-francisco/what-i-wish-i-knew-6-days-ago-9f27c6c6ba02">What I Wish I Knew 6 Days Ago — The Missing Guide for Gulp/Webpack-Dev-Server/BrowserSync</a> was originally published in <a href="https://medium.com/points-san-francisco">Points San Francisco</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Experience Refactoring JSPM/SystemJS to Using Webpack]]></title>
            <link>https://medium.com/@moog16/my-experience-refactoring-jspm-systemjs-to-using-webpack-4c38eccffc71?source=rss-d4056a20caa------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c38eccffc71</guid>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[jspm]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[build-tool]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Matthew Goo]]></dc:creator>
            <pubDate>Sat, 03 Sep 2016 06:44:26 GMT</pubDate>
            <atom:updated>2016-09-03T06:44:26.639Z</atom:updated>
            <content:encoded><![CDATA[<p>Developers and engineers alike constantly face the age old question of asking what tools do I use? What technology can I utilize to build my apps as quickly, efficiently, and smoothly as possible? The answer is quite simple: you never know until you actually try all the tools out there. But who has time for that?? All you really want to do is build an app. Well, I did have some time…So I’m writing here to share with you my findings on the differences between JSPM/SystemJS and Webpack and converting from one to the other.</p><h3>What is Webpack and/or JSPM/SystemJS?</h3><p>tl;dr: if you know what they are, feel free to skip this section</p><p>If you’re not familiar with JSPM/SystemJS or Webpack, they are both a set of tools to allow you to modularize frontend apps, and try to be a one-stop solution build tool. What does that mean? Well, in my experience, both have acted as my dev server, minifier, uglifier, ES6-ifier, and static assets manager just to name a few.</p><p>Webpack has a much greater following, and it has become the industry standard among frontend web apps for better or for worse. But because of this popularity there are so many plugins and loaders that already have been built for you. Essentially all you (the developer) are responsible for is filling in the blanks in the configuration file. This makes it super easy, since finding tutorials and examples on the web are so prevalent. If you are just starting out, I would suggest to take a read through this eBook, <a href="http://survivejs.com/webpack/introduction/">http://survivejs.com/webpack/introduction/</a>.</p><p>JSPM/SystemJS has certainly gained in popularity and is the brain child of <a href="https://medium.com/u/e920df262f3a">Guy Bedford</a>. SystemJS is a module loader, and manages all your components and js packages. JSPM is the package manager that handles installing all those great 3rd party packages that we so rely on similar to NPM or Bower, but better! Over the course of the past 6 months, I’ve built 3 production apps using this set of tools, and have loved it. The thing that makes SystemJS great is that it is built to the ES6-specs. The idea behind this is that when ES6 is finally universally accepted, there will be a minimal amount of refactoring that you will need to do to your app. Another major benefit to using JSPM is that the 3rd party package that you want to install doesn’t have to be an actual package. It can live on Github, NPM, Bower, or in the JSPM registry. Which at first may not sound like much, but its actually so nice when you want to unify the way you manage all your packages. It really takes away the complexities that are associated with package managing.</p><h3>The Process</h3><p>How did I do it? Well it was actually super easy, but tedious. Along with JSPM/SystemJS I was using Gulp as the dev server and to copy my static assets to their respective places in my file system. I also had a few Gulp tasks to minify the javascript and css for production. All pretty standard stuff. Here is my Gulpfile in this Gist:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/66f5fcd59d3c9fdc3f29b6884fd31140/href">https://medium.com/media/66f5fcd59d3c9fdc3f29b6884fd31140/href</a></iframe><p>You don’t necessarily need Gulp/Grunt or some build tool. But it does clean it up a bit, and makes it much more human readable. I have also been lead to be believe that Gulp is faster, since its piping all the data, instead of being synchronous.</p><p>What also comes with it is a huge auto-generated config.js file, that is not as interesting, but is the configuration file for SystemJS and a map for all our packages and dependencies installed by our favorite JSPM. You can think of it as your package.json (for all your npm lovers). It may look like a lot at first, but all you really care about are the first 6 options:</p><ol><li><strong>defaultJSExtensions</strong>: [boolean] allows the developer to ignore the .js extension in each import statement</li><li><strong>transpiler</strong>: the transpiler you so choose</li><li><strong>babelOptions</strong>: options you pass to the babel transpiler</li><li><strong>paths</strong>: where all your dependencies live</li><li><strong>baseUrl</strong>: the root of your app</li><li><strong>map</strong>: the map of your dependencies and 3rd party packages</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2aac258d5ecb9a1bcdc4975c33dbc5e4/href">https://medium.com/media/2aac258d5ecb9a1bcdc4975c33dbc5e4/href</a></iframe><p>The easy part in the refactor was removing these two files completely. So what replaced them? Well I had to add a new webpack.config.js file, which is the config for webpack. I also was able to completely replace Gulp’ responsibilities (dev server, the minifier, and static assets manager).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c87d7025b35ecd6858c4a9a73c279fcf/href">https://medium.com/media/c87d7025b35ecd6858c4a9a73c279fcf/href</a></iframe><p>The main things you need to focus on in the webpack.config.js file are the loaders and plugins. This is the meat of the config file, and is where you define how to handle each file in your application. The most difficult thing for me that I still don’t really understand is the output.path and output.publicPath properties. If you get them incorrect then the app just won’t work, and yet I don’t see why you need both. Please comment or tweet me if you do.</p><p>The dev server was fairly easy to setup, but getting the file proxies to work took a lot of trial and error. I don’t think my answer is very intuitive, but it works. For example:</p><pre>‘/static/img/logos’: {<br>  target: `${localhost}:${PORT}`, <br>  pathRewrite: { <br>    ‘/static/img/logos’: ‘/assets/images/logos’<br>  }<br>}</pre><p>The /static/img/logos is the source path the server should catch when a request is made. /assets/images/logos is the destination path it should replace it with. There is probably some shorthand version that looks a lot better, but it took me about 20 tries to get this correct.</p><p>Another great thing about Webpack is that you can just use a templating tool, such as html-webpack-plugin. This allows the developer to get rid of an index.html template where you include your js and css and such. The one weird thing when doing this is that you have to import your main app.scss file into your entry js file (index.js in my case). This is so that Webpack is aware of the styles you have, which makes sense, but is a change worth noting when comparing it to SystemJS.</p><p>Webpack with npm has the capability to act as the build tool for production, the dev server, and serve the production build. My file structure looks like this for those wondering:</p><pre>|<br>| assets<br>  - |images<br>  _ | scripts<br>| fonts<br>| src<br>  - | action-creators<br>  - | api<br>  - | components<br>  - | middlewares<br>  - | models<br>  - | reducers<br>  - | styles<br>      - | 01-settings<br>      - | 02-tools<br>      - | 03-generic<br>      - | 04-base<br>      - | 05-objects<br>      - | 06-components<br>      - | 07-trumps<br>      - | app.scss<br>  - | index.hbs<br>  - | index.js<br>| test<br>| webpack.config.js<br>| package.json<br>| karma.conf.js<br>| .babelrc (don&#39;t forget this)</pre><p>And once I ran the build script (npm run build) it would build my static folder as so:</p><pre>|<br>| index.html<br>| main.[hash].css<br>| bundle.[hash].js<br>| img<br>  - | images<br>  - | logos<br>  - | icons<br>| fonts<br>  - | font files<br>  - | icon fonts</pre><p>If you aren’t aware of <a href="https://docs.npmjs.com/misc/scripts">npm scripts</a> look into them! They really make your life and the rest of the developers on the project so much easier! They live in your package json and basically act as alias’s to run, build, and test your app. Here is a sample of mine:</p><pre>“scripts”: {<br> “test”: “./node_modules/karma/bin/karma start karma.conf.js”,<br> “test:debug”: “./node_modules/karma/bin/karma start karma.conf.js — debug=true”,</pre><pre> “build”: “webpack -p — define           process.env.NODE_ENV=’\”production\”’”,&#39;</pre><pre> “dev”: “webpack-dev-server — hot — inline”,<br> “dev:prod”: “webpack-dev-server — define process.env.NODE_ENV=’\”production\”’”<br> },</pre><p>Say for example you wanted to run your tests. You would just run `npm run test`, or `npm run test: debug` if you wanted to run in chrome or some browser other than phantom. If you wanted to build you would run `npm run build`, which would minify your files. And if you wanted to run your dev server its `npm run dev`.</p><h3><em>styles</em></h3><p>In order for the sass to work I had to replace all the jspm: prefixes to ~, which is as easy find/replace, and pretty much everything worked after then. So if you were importing some files like:</p><pre><a href="http://twitter.com/import">@import</a> “jspm:inuit-functions/tools.functions”;<br><a href="http://twitter.com/import">@import</a> “jspm:inuit-mixins/tools.mixins”;</pre><p>you would change it to</p><pre><a href="http://twitter.com/import">@import</a> &quot;~inuit-functions/tools.functions&quot;;<br><a href="http://twitter.com/import">@import</a> &quot;~inuit-mixins/tools.mixins&quot;;</pre><p>Really easy!</p><h3><em>tests</em></h3><p>Tests on the other hand was just as challenging as filling in the blanks for the webpack.config.js file. I basically created a small webpack.config within the the karma.conf, and had to make sure to include all the karma plugins that I was using. But after doing the first webpack.config.js file, I felt really comfortable doing the karma.conf although it was much simpler.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b4700c5155ce45c6df3dd4dc7e1cc72/href">https://medium.com/media/0b4700c5155ce45c6df3dd4dc7e1cc72/href</a></iframe><h3>What Do I Prefer?</h3><p>If you’re still with me and have read up until here, you probably don’t care too much about my opinion. I get it…But I’m saying it anyway. JSPM and SystemJS have a lot going for it. Its very easy to setup, minimal learning curve, and is the package manager of the future. But the downside is in the build step. Every time you make a change it has to build the entire app. It doesn’t matter so much if your app is really small, but once you have a couple API calls and a few pages in your SPA, you might as well be doing your laundry in the mean time. If you have livereload it gets super annoying. I actually removed that feature while developing.</p><p>Which leads me to my preference, Webpack. Its the most popular tool for a reason. When developing there is no comparison. You could have a 100 files or a million files, and it would still compile just the same with every change (unless you changed all million files). What I’ve read is that it takes your diff and only compiles those one or two files and adds it back into the bundle, which is why its so much faster. The config is hard to learn, which is the reason it took about a week to convert the projects. I think in the end this is well worth its time. Saving 5–10 seconds every time you make a change may not sound like a lot, but I think it really brings up your focus when troubleshooting/debugging. There are also a lot of plugins made for Webpack, which makes the tool that much more valuable. For example hot reloading or autoprefixing are two things well worth the refactor. I don’t have a huge amount of experience in using either, but instantly I’m able to see a use for both. Hot reloading you never have to refresh the page, which makes it so much faster to develop. <a href="https://github.com/postcss/autoprefixer">Autoprefixer</a> allows the dev to never have to worry about vendor prefixing. Sure its a tiny issue, but its easy to integrate and allows you to write css as if you’re living in the future (which is sexy).</p><p>All in all if I were to go back in time, I would start off using Webpack. Its harder to learn and may not be the end all tool, but the community and the tools that come along with it are what make it worthwhile. While learning and reading other people’s <em>how to</em> blogs, take a walk away from the computer screen. Over half of my issues while learning Webpack were resolved from doing just that. Simply most of the issues was a spelling issue (missing a s or misspelled some camelCased word). And to be honest, its nice getting rid of Gulp/Grunt. That’s a whole other API that you have to learn and become accustom to that no one really wants to learn. All we want to do is code, and that’s exactly what Webpack allows a developer to do. Eat, sleep, code, repeat; That’s what we’re all here to do.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c38eccffc71" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Publishing React Components NPM Modules]]></title>
            <link>https://medium.com/points-san-francisco/publishing-react-components-npm-modules-678258bd6ba0?source=rss-d4056a20caa------2</link>
            <guid isPermaLink="false">https://medium.com/p/678258bd6ba0</guid>
            <category><![CDATA[publishing]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Matthew Goo]]></dc:creator>
            <pubDate>Fri, 22 Apr 2016 18:27:43 GMT</pubDate>
            <atom:updated>2016-04-22T18:29:57.186Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P6npsHnwmbDa_jFplbB5mQ.jpeg" /></figure><p>Naturally we all progress on to greater things. Here at <a href="https://www.points.com/#/">Points</a> we started building our first new app in <a href="https://facebook.github.io/react/">React.js</a>, and are about to start our second. We anticipate that some of the components that we use in our first app will also be useful to have in our second app. To share code between these 2 apps we have decided to go the route of creating NPM modules, which makes it extremely easy to install in any app. I want to share with you what I’ve learned and any pain points I may have had in doing so.</p><h4>Package.json</h4><p>If you look at different npm repos, they look basically like a mini project. You have some build steps, a gulp or grunt file, a .git directory, and package.json. So where to begin?? NPM is pretty helpful answering this question. They have provided a nice terminal command</p><pre>npm init</pre><p>This leads you through the setup of your package.json file pretty quickly. I usually just do all the default values. After that you can start building up your component or npm project. Or in our case, just copying over existing component code, and creating a user friendly API.</p><h4>Build step</h4><p>In my attempt of creating an npm module, I wanted to keep it as lightweight as possible. So instead of using a build tool like Gulp/Grunt, I chose to use simple npm scripts. Setting one up is fairly straight forward.</p><p>In your package.json file you can add a new property, `scripts` as an object like below:</p><pre>“scripts”: {</pre><pre>  &quot;build&quot;: &quot;rm -rf dist &amp;&amp; node ./scripts/build-dist&quot;,<br>  &quot;otherCmd&quot;: &quot;more terminal commands...&quot;</pre><pre>}</pre><p>And the way you would execute one of these bad boys in the terminal would be:</p><pre>npm run build</pre><p>Something you might have not noticed in my above example is that you can use external node scripts. In my case, I have a node.js file in `./scripts/build-dist.js`. If you’re like me and lacking in the terminal commands department, I found writing node scripts to be far easier for more complicated instructions.</p><h4>CSS</h4><p>If you have a component you will probably have styles to go along with it. I’m not a huge fan of including css inside your jsx file, and would rather use s<a href="http://sass-lang.com/">css</a>. The way I tackled this problem is to force the consumer of my npm module to include my compiled css file or scss file, which has been working out well for us. If the consumer uses scss, they can actually easily configure and customize the npm component by overriding scss variables that we have clearly defined. If they are just using plain css, they will need to override the classes that we have, which will require them digging into the css file.</p><h4>ES6</h4><p>Here at Points we are big fans of ES6/7 and using new tools. I just wanted to share something that took me half a day to figure out. If you’re using Babel CLIwith React and jsx files, you’re going to need a .babelrc file, the babel configuration file. You will get errors compiling your jsx that look something like this:</p><pre>SyntaxError: src/RangeSlider.jsx: Unexpected token (135:6)<br>  133 |<br>  134 | return (<br>&gt; 135 | &lt;div<br>      | ^</pre><p>Babel won’t understand the html in your jsx file, and will barf at you. So the fix this you just need a .babelrc at the root of your file:</p><pre>{<br> “plugins”: [<br> “transform-react-jsx”,<br> “add-module-exports”<br> ],<br> “presets”: [“es2015”]<br>}</pre><h4>Readme.md</h4><p>Probably the most important part of the NPM module is to include a README! No developer wants to dig into your code and figure out what’s going on. So document…The best NPM modules I’ve used are the ones where I just read the readme, and can plug and play in just a few minutes.</p><p>Examples also help greatly in understanding more complicated modules that have too many options and configurations than can be explained. Some people (me) don’t always want to read things twice, three times and not understand what you’re saying. Picture’s worth a thousand words.</p><h4>Build for yourself</h4><p>Going through this process has made me realize its not easy to account for every use case and every consumer out there. Everyone’s problems are different and everyone will want something to be tweaked. So to start, just start small. Your module should just address your concerns at first with a small set of configuration. It should do one thing very well instead of many things kind of ok. So open source and share the wealth, but be true to your needs.</p><p>Please check out our React components and let us know how to improve!</p><p><a href="https://github.com/the-unsullied">https://github.com/the-unsullied</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=678258bd6ba0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/points-san-francisco/publishing-react-components-npm-modules-678258bd6ba0">Publishing React Components NPM Modules</a> was originally published in <a href="https://medium.com/points-san-francisco">Points San Francisco</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Separation at Birth — Mapping Web to iOS Development]]></title>
            <link>https://medium.com/points-san-francisco/the-web-and-ios-the-separation-at-birth-5f57c93f2036?source=rss-d4056a20caa------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f57c93f2036</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <dc:creator><![CDATA[Matthew Goo]]></dc:creator>
            <pubDate>Wed, 17 Feb 2016 21:21:29 GMT</pubDate>
            <atom:updated>2016-02-17T21:37:18.991Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*S3xw0fne7cxJ6L4ka99clw.jpeg" /><figcaption>“Brother’s don’t shake hands. Brothers gotta hug!” — Tommy Boy</figcaption></figure><p>Brothers don’t shake hands, brothers gotta hug. Web and iOS development are no different in this case. They can both act as <em>clients</em> that make API requests. They both act as UIs to display information to a user. Let me create the mental map for your web developer mind to translate to iOS.</p><h3>Elements</h3><p>When you first learn about web development, the most basic thing you can learn about are the HTML elements. In iOS they are really just another high level library that Apple created called UIKit, and thusly name <em>UIKit Components. </em>These HTML elements and UIKit Components don’t completely match 1:1, but the way in which you mix and match the elements or components will allow you to achieve the same look and feel. This is not a complete list, but are the most common elements that I used while learning iOS.</p><p><strong>UILabel</strong>: This component is used for any text that is to be displayed in app. So in terms of HTML elements this replaces <strong>&lt;p&gt;</strong>, <strong>&lt;span&gt;</strong>, <strong>&lt;label&gt;.</strong></p><p><strong>UIView</strong>: Use this to act as any generic component in app. All components extend from this parent class. I like using this to group many small components together to act like a <strong>&lt;div&gt;</strong>. To create custom Components most people will extend from UIView.</p><p><strong>UIImageView</strong>: Like the name suggests, this is used for images. HTML elements that it replaces: <strong>&lt;img&gt;</strong>.</p><p><strong>UIButton</strong>: The name says it all with this component. This element is used for the most basic of user touch interactions with the app. And like with any HTML button, UIButton can setup listeners to trigger code on user events such as</p><ol><li>“touch up inside” → “click”</li><li>“touch down” → “mousedown”</li><li>“touch drag enter” → “drag”</li></ol><p>list of events: <a href="http://stackoverflow.com/questions/11389915/uibutton-events-whats-the-difference">http://stackoverflow.com/questions/11389915/uibutton-events-whats-the-difference</a></p><p><strong>UITextField</strong>: Use this component to input text, which would replace :</p><pre>&lt;input type=”text” /&gt;</pre><p>Not too much magic that happens here, but you can also attach events to UITextField such as</p><ol><li>“touch up inside” → “focus”</li><li>“editing did changed” → “change”</li><li>“editing did end” → “blur”</li></ol><p><strong>UITextView</strong>: Use this component when dealing with long blocks of text such as an email message or a long description. This is most similar to <strong>&lt;textarea&gt;</strong>, and has the same events as the UITextField.</p><p><strong>UIScrollView</strong>: ScrollView is like a scrollable <strong>&lt;div&gt;</strong>. If you have too much content in app, it will all be hidden since you don’t get scrolling for free like the browser. To fix this you will need to place it in a scrollview. The most common configuration with scrollView is to enable paging mode. This is where each app screen looks and acts like a page. Many iOS developers use this to enable draggable side-menus.</p><p>Really good guide: <a href="http://guides.codepath.com/ios/Scroll-View-Guide">http://guides.codepath.com/ios/Scroll-View-Guide</a></p><p><strong>UITableView</strong>: Probably one of the most commonly used components in iOS. You can see examples of this being used in Twitter, Yelp, Rotten Tomatoes, the Mail App, the Phone Book App, the App Store, the Notes App, and pretty much any app under the sun. This is used in conjunction with <strong>UITableViewCell</strong>, which is the subview that lives within the tableView.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*Df0Qxtfz8oEK0Y1DE3PvIw.png" /></figure><p>There is nothing in HTML land that compares to a UITableView, but think of it as a way to create a <em>list</em> of one or more of the same subview (cell). Here at <a href="http://points.com/">points</a> in our webapp we have examples of a list that correspond to tableViews, such as the <em>exchange program </em>modal and <em>add program </em>sidebar.</p><h3>Building UI</h3><p>Now putting all these piece together is the real work. In web development we use html, css, and javascript. There is a clear division of responsibilities, where HTML has all your structure and markup that your page contains, CSS contains all your styles, color, and beauty, and javascript contains the logic and “UI Magic” that we see on the page. These files are just simple text files — Easy to read and understand if you’re familiar with code. I may be biased, but this approach is far more straightforward, but possibly more error prone than developing with iOS.</p><h4>storyboards</h4><p>iOS is a whole other beast. The most universally accepted method is the use of storyboards. They show the developer or designer high level view of a portion or the entire application. Its very clear and simple to look at each screen at every point in the app flow. You can easily add UIKit Components into the storyboard, and get a preview of what your app looks like without having to build/run it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HeB6DSyMrNyMBNXYaOe8FA.png" /><figcaption>My Twitter App Flow Using Storyboards</figcaption></figure><p>Of course there are drawbacks. Storyboards don’t work well with large teams. Code conflicts are very much a part of a developer’s life, and these visual conflicts are not something you want to deal with on a daily basis. This method also requires a larger understanding and comfort with Xcode as man of the components can be styled just using the interface builder (storyboards and Xcode).</p><h4>xibs</h4><p>Are much like storyboards in that they visually layout a view’s elements. What they don’t have is a high level application flow, since its just one element in the app. I used this most when creating UITableViewCells, but was then corrected to just use storyboards for the same thing. So when in doubt just use storyboards.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/527/1*1fgPrVzxj7xGmiCyAefkCg.png" /><figcaption>Twitter UITableViewCell</figcaption></figure><h4>code</h4><p>The tried and true way for most large dev teams are just coding these babies up. Using a combination of storyboard-like text files and Objective-C/Swift ViewController files, you can programmatically build up an app’s UI. This of course is the most verbose way of doing this, but also allows for maximum flexibility and customization. The other great benefit of doing it this way is decreasing code conflicts. There is also a lot less hunting through Xcode interface builder for styles and enabling/disabling features/properties of elements.</p><p>In the end a dev team will probably need to use a combination of the three to achieve a complete app. There is no one solution to this, and really will depend on how everyone works together.</p><p>I hope this binds the glue in your mental map of understanding iOS a little bit better. This again is just a high level explanation of a few of the basics, so please look out for more posts in the near future!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f57c93f2036" width="1" height="1" alt=""><hr><p><a href="https://medium.com/points-san-francisco/the-web-and-ios-the-separation-at-birth-5f57c93f2036">The Separation at Birth — Mapping Web to iOS Development</a> was originally published in <a href="https://medium.com/points-san-francisco">Points San Francisco</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mobile Development: Yesterday, Today, Tomorrow]]></title>
            <link>https://medium.com/@moog16/mobile-development-yesterday-today-tomorrow-f2f52831f1c3?source=rss-d4056a20caa------2</link>
            <guid isPermaLink="false">https://medium.com/p/f2f52831f1c3</guid>
            <category><![CDATA[phonegap]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[mobile-development]]></category>
            <dc:creator><![CDATA[Matthew Goo]]></dc:creator>
            <pubDate>Wed, 02 Sep 2015 03:59:20 GMT</pubDate>
            <atom:updated>2015-09-02T04:00:41.146Z</atom:updated>
            <content:encoded><![CDATA[<p>For a long time mobile app development was not on anyone’s radar. Companies would build their own operating systems and in-house applications and devices were not see as multipurpose tools that we now know them as today. It was not until the first iPhone release (June 2007) did we finally see a company open their platform for 3rd party developers to create applications. Soon there after in July 2008 the App Store was introduced, HTC releases the first Android phone and Google opens up the Android Market. Since then Android and iPhones have ruled the market, making up 96.3% of the world smartphone share.</p><p>For the majority of this time, most companies and developers could only create apps using the API provided by Apple and Google with Objective-C and Java respectively. From the perspective of a web developer, these languages seemed complex and IDEs were tiresome to learn. But then in 2009 a tool called Cordova (now know as PhoneGap) was introduced, which acted as a web app wrapper that could be rendered as a native mobile application. Since then support for all platforms have been introduced (including Android, iOS, Windows, Blackberry, etc.). Many competitors have popped up such as <a href="https://trigger.io/">Trigger.io</a> and <a href="http://www.appcelerator.com/">Appcelerator</a>, along with tools and frameworks to build your web app with more ease and have a native look and feel such as <a href="http://ionic.io/">Ionic</a> and <a href="https://jquerymobile.com/">jQuery Mobile</a>. Most recently to hit the hot market is <a href="http://facebook.github.io/react-native/">React Native</a>, which is an abstraction over iOS with a promise to support Android as soon as next month.</p><h4>My Experience with PhoneGap</h4><p>Having worked with PhoneGap for about a month, I can say that it was miserable learning their API to access iPhone hardware features such as the camera. Development was slow! To get a working app on your phone or the iOS simulator you had to compile all your HTML, CSS, and Javascript into code that Xcode understood to build into the app image to be installed on your phone/sim. This all took around 2–3 minutes. You can imagine how time consuming it was to build a UI, not including the time it took to debug our unfixable bugs (unless we dove into PhoneGap land). Having to learn and understand Xcode was difficult enough, but then relying on a layer over that iOS environment proved to be just as, if not more difficult. That was about two years ago, and I’m sure the support, community, and performance has been improved, but I doubt that all issues I ran into have been resolved.</p><h4>React Native</h4><p>I’m sure other tools and competitors to PhoneGap will have other bugs and learning curves that we as developers will all face. But what about this new tool React?? Thus far React has taken the web community by storm with its fast virtual DOM and reusable component based structure. And again turned up the hype by announcing React Native in March of this year. What makes this tool so different is being able to develop just like a React web app. You can use npm and bower modules just like you would a React web app such as lodash or moment.js. One of those great modules already built into the framework is livereload. This in my opinion is one of the most important features of developing in React Native. You are able to run your application in the simulator, and in real time (1–2 seconds) see your updated changes, which is much faster than real iOS development. Other amazing benefits to React Native from a web developer’s perspective:</p><ol><li>No need to learn another language</li><li>React framework forces you to build in discrete components</li></ol><p>So if React is so amazing, then why the need for learning Native? Well React will forever be a layer written over iOS or Android to trigger native methods. That means you are at the mercy of Facebook for everything who even admits that “there are probably many things that are either broken or not implemented yet”. They are a huge company with a lot of resources and motivation to back this, but no one entity can be infallible.</p><h4>Why not just Mobile Web?</h4><p>Why not just build everything in mobile web? Especially since its so much faster to build. Well for one, we can build much better, more integrated user experiences with a native app. We can tap into the phone’s hardware features such as the camera, accelerometer, touchID, and give more features in our app to the user. We can use platform specific UI components, like maps, date pickers, switches that we don’t get for free on mobile web. Using the platform specific components keeps the app up to date without any developer having to change anything, since Apple or Google are the ones updating the date pickers and switches, etc. Also native is faster and forever will be, since as an application you have to download, most of the boilerplate is already on the phone. All the app has to do is make a few calls to a backend and voila. With mobile web you have to load the entire page as well as any data calls the web app needs.</p><h4>Conclusion</h4><p>Out of all these tools, React Native seems to be best alternative to building a native app. The only thing that is holding it back from taking over native app building is that it is still in its infancy. It only just came out about 6 months ago. There are still large hurdles that they must climb through, as well as building the API for Android. Whatever your opinion is, its an exciting time to be a developer. I just started my career, and so many tools have come about. I’m sure next year there will be a new tool to compete with React Native, and might have some better features.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f2f52831f1c3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Extensions in Swift]]></title>
            <link>https://medium.com/@moog16/extensions-in-swift-8acf61dd7303?source=rss-d4056a20caa------2</link>
            <guid isPermaLink="false">https://medium.com/p/8acf61dd7303</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[extension]]></category>
            <dc:creator><![CDATA[Matthew Goo]]></dc:creator>
            <pubDate>Mon, 24 Aug 2015 06:16:35 GMT</pubDate>
            <atom:updated>2015-08-24T06:20:38.508Z</atom:updated>
            <content:encoded><![CDATA[<p>Extensions are a way to add new functionality to existing classes, structs, and enums in Swift. There are 6 main use cases for extensions. Here are those 6 cases with some very simple examples.</p><h3>1. add computed properties and computed type properties</h3><p>Computed properties are properties that are defined on classes, structs, or enums that are calculated from other values on the class, struct, or enum. For example, if we want a computed type bool property on the <strong>Int</strong> struct called <em>isEven</em>, we could write an extension for this:</p><pre>extension Int {<br>  var isEven: Bool {<br>    return self%2 == 0<br>  }<br>}</pre><p>we can then access this computed type property as</p><pre>3.isEven // false<br>6.isEven // true</pre><h3>2. define instance methods and type methods</h3><p>Like computed properties, we can also add methods. For example if we wanted a method <em>isOdd</em> on <strong>Int</strong>, we can do so in a similar fashion as stated above:</p><pre>extension Int {<br>  func isOdd() -&gt; Bool {<br>    return self%2 == 0<br>  }<br>}</pre><pre>println(3.isOdd()) // true<br>println(6.isOdd()) // false</pre><h3>3. add new initializers</h3><p>We can also add new initializers to classes and structs. Say we wanted to create an <strong>Int</strong> from a variable of type <strong>String</strong>. We could write our extension like so:</p><pre>extension Int {<br>  init(stringVal: String) {<br>    self = stringVal.toInt()!<br>  }<br>}</pre><pre>var result = Int(stringVal: “234”)<br>println(“\(result + 166)”) // prints 400</pre><p>We see that <em>result</em> returns to us as an <strong>Int</strong> of 234 and adds it to 166. If it was still a string, this would have thrown an error, since you cannot add <strong>Strings</strong> and <strong>Ints</strong>. This doesn’t overwrite the original initializer, so if we were to create an Int with some number, <strong>Int(24)</strong>, this would still work.</p><h3>4. define new subscripts</h3><p>Subscripts are another handy feature of Swift, where we can access elements of lists, collections, and sequences. For example if we wanted the character at the index of some string, we could write:</p><pre>var myString = “Swift is awesome!”<br>Array(myString)[0] // will print “S”</pre><p>There is a more elegant way to do this with subscripts like below:</p><pre>extension String {<br>  subscript(int: Int) -&gt; Character {<br>    return Array(self)[int]<br>  }<br>}</pre><pre>myString[0] // will print “S”</pre><h3>5. define and use new nested types</h3><p>Nested types are a way of typing values of classes, structs, or enums. Using another example where we want to know if a <strong>Character</strong> is a vowel or a consonant, we could create a nested type to help us categorize this.</p><pre>extension Character {<br>  enum Type {<br>    case Vowel, Consonant<br>  }</pre><pre>  var type: Type {<br>    switch self {<br>    case “a”, “e”, “i”, “o”, “u”, “A”, “E”, “I”, “O”, “U”:<br>      return .Vowel<br>    default:<br>      return .Consonant<br>    }<br>  }<br>}</pre><pre>var myChar: Character = “C”<br>println(“\(myChar.type == .Consonant)”) // evaluates to true</pre><h3>6. make an existing type conform to a protocol</h3><p>Taking the example from the docs, we can take the simple <em>protocol</em> TextRepresentable:</p><pre>protocol TextRepresentable {<br>  func asText() -&gt; String<br>}</pre><p>and extend any existing type to conform to this <em>protocol</em>. So if we want the type <strong>Int</strong> to conform to our new <em>protocol</em>, we need to then add an <em>asText</em> method in the same extension:</p><pre>extension Int: TextRepresentable {<br>  func asText() -&gt; String {<br>    return “I am a number, \(self)”<br>  }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8acf61dd7303" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>