<?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 Francois Ward on Medium]]></title>
        <description><![CDATA[Stories by Francois Ward on Medium]]></description>
        <link>https://medium.com/@fward?source=rss-ebdea3e7fd7c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*SgoT7z2nF3hf4cNdK3L-tg.png</url>
            <title>Stories by Francois Ward on Medium</title>
            <link>https://medium.com/@fward?source=rss-ebdea3e7fd7c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 12:55:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fward/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[Redux side effects and you]]></title>
            <link>https://medium.com/javascript-and-opinions/redux-side-effects-and-you-66f2e0842fc3?source=rss-ebdea3e7fd7c------2</link>
            <guid isPermaLink="false">https://medium.com/p/66f2e0842fc3</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <dc:creator><![CDATA[Francois Ward]]></dc:creator>
            <pubDate>Sat, 05 Mar 2016 19:37:26 GMT</pubDate>
            <atom:updated>2017-01-08T21:59:11.895Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_zUh7Lutwfa5WcsZaF4SeA.png" /><figcaption>Spiral by <a href="https://www.flickr.com/photos/31085717@N00/7414803568/in/photolist-cidNLQ-bvUqz8-fsMmsa-7xpsxR-8TUd1y-e4vvaC-762UTh-21ihC-8AXRHw-ib5LYg-ibzVQC-posear-6bR26C-dKaRbU-5WxEie-4nG2cV-5WxcPg-9uuHB-6nB3fD-e7T1yg-aX8k9P-rN32vU-5PeTnW-yTSbV-7wjyVH-f2Xpi5-e7SZnT-btDjwc-9uv6H-e7YDpb-e7YGUu-kPAoKR-9kXswX-e7YCo5-73x19f-5jFCp-cKBLk3-rL4NVf-nvuin7-e7T3Vi-KVZ8n-7wjxP6-4nFME8-2DeTwa-8AW7nh-Qkr3-dZfBni-4nG1wn-4nKxm1-67C3n1">Khairul Nizam</a>, CC BY 2.0</figcaption></figure><p>Should you care about alternatives to the venerable <a href="https://github.com/gaearon/redux-thunk">redux-thunk</a>?</p><p>It seems every couple of days now, someone comes up with a solution for side effects in Redux to replace redux-thunk. Thunk is the go-to middleware that allows us to return functions from action creators to dispatch action objects synchronously or asynchronously. If you’ve never used it or don’t know what I’m talking about, the <a href="http://redux.js.org/docs/advanced/AsyncActions.html">official documentation</a> describes it pretty well.</p><p>Some of those alternatives have been around for a while now: <a href="https://github.com/yelouafi/redux-saga">redux-sagas</a>, <a href="https://github.com/raisemarketplace/redux-loop">redux-loop</a> are gaining visibility, while other models such as <a href="http://jamesknelson.com/join-the-dark-side-of-the-flux-responding-to-actions-with-actors/">actors</a> are also coming in the spotlight every now and then.</p><p>But why does it matter, if at all? Are they worth considering?</p><blockquote>Edit 3/27/2016: Highly related to this post, see the <a href="https://github.com/reactjs/redux/issues/1528">following discussion</a> on the Redux github repo about side effects handling</blockquote><h3>If you’re happy with redux-thunk, stop there</h3><p>It’s pretty much that simple.</p><p>If you’ve never heard of those alternatives, or if you’re wondering why you should care, you can stop worrying about it. Thunks will work just fine. They are simple, easy to learn and flexible. They will allow you to build the largest, most complicated application you can think of.</p><p>There are some issues with unit testing, but using tools such as <a href="https://github.com/arnaudbenard/redux-mock-store">redux-mock-store</a> and <a href="https://github.com/pgte/nock">nock</a>, you can handle most cases. You can see examples on the <a href="http://redux.js.org/docs/recipes/WritingTests.html">official recipes page</a>.</p><p>Only look further if you feel you’ve mastered Redux and feel it’s not enough. Whatever you do, do NOT try to make your own middleware to handle asynchronous actions and side effects until you’ve already looked at what’s out there.</p><h3>The search for the one true model</h3><p>If thunks are so great, why are there so many smart people trying to come up with alternatives?</p><p>It generally falls in two big categories:</p><ol><li>They are harder to test</li><li>Mixing actions and side effects in asynchronous action creators <a href="https://riad.blog/2015/12/28/redux-nowadays-from-actions-creators-to-sagas/">drastically increases complexity</a>.</li></ol><p>Other ecosystems, such as <a href="http://elm-lang.org/">Elm</a> (which heavily inspired Redux) use common functional patterns to tackle these problems. In the React/Redux/JavaScript world however, these are still open questions.</p><p>That’s why every couple of days, someone tries to find a more elegant way to solve these problems, and we end up with countless side effect “frameworks”. This is very much like how, until Redux became popular, a new Flux framework came out every other week. I don’t think it’s a bad thing. A better de facto model to handle the hardest piece of Redux development would be great.</p><p>I, however, think these tools should not be used as clutch to bypass problems with the JavaScript testing ecosystem. There are also a lot of common elements that each new attempt share, yet they are frequently presented as brand new ideas.</p><h3>Testing is a solved problem</h3><p>First, I’d like to dispel the notion that we need an alternative to thunks because of testing.</p><p>Yes, testing with redux-saga is beautiful, thanks to its <a href="http://yelouafi.github.io/redux-saga/docs/basics/DeclarativeEffects.html">declarative side effects</a>, mocking dependencies work great too, and is often simpler. Look again at the Redux <a href="http://redux.js.org/docs/recipes/WritingTests.html">testing recipes</a> under “Async action creator”.</p><blockquote>Declarative side effects are a way to describe an effect, such a <a href="https://davidwalsh.name/fetch">fetch</a> call, as an object instead of calling the function directly. In Redux’s case, a middleware would then handle calling fetch for you. When unit testing, instead of mocking fetch, one can simply inspect the object to make sure it describes the call directly. The actual fetch function is never called.</blockquote><p>It really isn’t that complicated, and many would argue it’s simpler than learning a whole new tool during development. You can keep using the simple thunk the way you always did.</p><p>The problem with this approach is that while well known global functions like fetch are easy to mock, the JavaScript ecosystem is anemic when it comes to mocking arbitrary things. In Java, C# or other classic OOP languages, this problem is solved via <a href="https://en.wikipedia.org/wiki/Dependency_injection">dependency injection</a> frameworks that make it easy to substitute dependencies.</p><p>In JavaScript, dependency management tools such as Webpack or RequireJS complement module syntax such as <a href="http://www.2ality.com/2014/09/es6-modules-final.html">ES6 modules</a>, CommonJS or AMD to decide which modules to load. Allowing mocking and substitution of dependencies isn’t their primary goals. Frameworks such as Angular and <a href="http://aurelia.io/">Aurelia</a> implemented their own dependency injection system in addition to JavaScript modules for that reason.</p><blockquote>Many will argue that modules aren’t a substitute for dependency injection and breaks the <a href="https://en.wikipedia.org/wiki/Inversion_of_control">inversion of control</a> pattern. I disagree. The syntax makes it look that way, but the semantic is very much “I declare that I need this dependency”, and it is up to the module system to provide it. The fact they look like factory method calls is just syntax sugar. Adding another DI framework such as Angular’s is redundant.</blockquote><p>We are left with weaker or more complicated tooling that is often environment specific.</p><ul><li><a href="https://github.com/plasticine/inject-loader">inject-loader</a> is Webpack specific and isn’t built with ES6 modules in mind.</li><li><a href="https://github.com/speedskater/babel-plugin-rewire">babel-plugin-rewire</a> works at compile time, is babel specific and has a complicated API.</li><li><a href="https://github.com/mfncooper/mockery">Mockery</a> is node specific</li></ul><p>Good, maintainable, decoupled code is easy to test and limits the need for mocks. That is one of the value propositions of the alternative side effect models. However, I think before we do that, the quality of the testing tools available in JavaScript should be improved. There will always be scenarios where you need to mock a dependency and warping high quality code for no other reason then testing is counterproductive.</p><p>I really think the community should not let efforts to make writing testable code easier stop it from developing better testing tools. They’re complementary. We need both.</p><h3>Don’t ignore what has been done before</h3><p>This is a bit of a pet peeve of mine. Every couple of days, someone who has been learning React/Redux for a few weeks comes up with this revolutionary idea to reduce boilerplate or. in this case, to handle side effects. The vast majority are just rehash of the 60 other attempts that were made before.</p><p>Worse, they usually haven’t even tried the existing solutions, which often would have solved their problem already. Recently I’ve seen one where the author hadn’t fully grasped redux-thunk before starting to make their own. Thunk is <a href="https://github.com/gaearon/redux-thunk/blob/master/src/index.js">8 lines of code</a> including the blank line and brackets. Sagas, Loop and the others may not be perfect, but they are very solid attempts at simplifying side effects.</p><p>More importantly, across all the attempts we’re starting to see clear themes coming up, and any new tool should explain how they’re working with those themes, or why they did not. Here’s some of the themes I look for in every new tool I look at.</p><h4>Declarative side effects</h4><p>To avoid <a href="http://eng.localytics.com/better-asynchronous-javascript/">callback hell</a>, simplify the control flow, and make testing easier (oh no, I fell for it too!), there’s a lot of gain to be made in having declarative side effects be a first class citizen. Almost all of the attempts at side effects models go that route.</p><h4>Synchronous actions only</h4><p>Sagas, Loop and actors all get rid of asynchronous actions altogether. Action creators go back to the default (returning an action object), and some kind of external listener or even the reducer takes care of side effects. If the side effect isn’t declarative, that just moves the problem elsewhere, though.</p><h4>Changing the Redux pattern</h4><p>Redux is a design pattern, and it’s great, but many people like to experiment with tweaking the pattern. In Redux-loop for example, modifying state is considered just one of many side effects handled by the reducer, which is a significant change. Those aren’t necessarily bad things, but authors should be clear about what they’re changing and what are the trade offs.</p><h4>Comparison with Elm or functional programming</h4><p>Redux takes a lot from Elm and functional programming in general, and for good reasons. FP patterns are great at keeping function simple, pure, testable and keeping state or side effects isolated.</p><p>When bringing forward a new way to handle promises, http requests or other side effects, it’s likely there are parallels in Elm, Haskell or Elixir communities, to name a few. I like to see these brought up in the conversation. “We’re doing things this way because it is a problem that was solved in FP language XYZ and it worked well”. Let’s not reinvent the wheel.</p><h3>The next leap</h3><p>Like Redux did for Flux, I think we’re getting close to the point where one of those middlewares or tool will raise above the rest as THE way to go when developing React applications. It’s possible one of the existing solution will be it, or that a new one will come out of nowhere.</p><p>To get there though, we have to attack the right problems, and build on top of what we already have instead of starting over every time as if no one else tried before.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=66f2e0842fc3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javascript-and-opinions/redux-side-effects-and-you-66f2e0842fc3">Redux side effects and you</a> was originally published in <a href="https://medium.com/javascript-and-opinions">JavaScript and Opinions</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[State of the Art JavaScript in 2016]]></title>
            <link>https://medium.com/javascript-and-opinions/state-of-the-art-javascript-in-2016-ab67fc68eb0b?source=rss-ebdea3e7fd7c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab67fc68eb0b</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Francois Ward]]></dc:creator>
            <pubDate>Sun, 28 Feb 2016 15:04:11 GMT</pubDate>
            <atom:updated>2016-04-22T01:32:26.974Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BAwhVEwe5bPJKCNHBdfGPA.png" /><figcaption>Image “Question!” by<a href="https://www.flickr.com/photos/-bast-/349497988/in/photolist-wTgzo-4ms8ZA-5DeuzB-8JkcMH-5CCQse-wRSNhj-6nCmik-rphyCW-5huQJc-bTQwfx-6S4XJJ-9grzfE-6Vmcpf-56eXRT-7VhPft-u5Gjqy-azGM3y-i6cpkf-7Er6af-7kZ57d-bTQwf4-5uCCw4-4vz7rG-ediLaQ-5JE9tz-5UnDmk-rrtnoF-8qQBZ9-KGgU8-9SScHJ-5YpgQU-do8Bez-5Ttgxf-oqtM3G-p9e9F3-s29nxg-v2dmxU-9uZpk3-uZot4q-u5RNwp-e5A9GJ-LaARx-cxUcBu-bncE6P-hyjkR3-fvAqY1-sQzvg-9v3xhu-6CrL7s-snRpm3/"> Stefan Baudy</a>, CC BY 2.0</figcaption></figure><p>So, you’re starting a brand new JavaScript front end project or overhauling an old one, and maybe you haven’t kept up with the breakneck pace of the ecosystem. Or you did, but there’s too many things to choose from. React, Flux, Angular, Aurelia, Mocha, Jasmine, Babel, TypeScript, Flow, oh my! By trying to make things simpler, some fall into a trap captured by one of my favorite XKCD comics.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*DWIYyJZI5Mu13L_m." /></figure><p>Well, the good news is the ecosystem is starting to slow down. Projects are merging. Best practices are starting to become clear. People are building on top of existing stuff instead of building new frameworks.</p><p>As a starting point, here’s my personal picks for most pieces of a modern web application. Some choices are likely controversial and I will only give basic reasoning behind each choices. Keep in mind they’re mostly my opinion based on what I’m seeing in the community and personal experiences. Your mileage may vary.</p><h3>Core library: React</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/242/1*nPQAJ3_tb3qbvxmdD-THlw.png" /></figure><p>The clear winner right now, is <em>React</em>.</p><ul><li>Components all the way down makes your application much easier to reason about.</li><li>The learning curve is very flat. The important APIs would fit on one page.</li><li>JSX is awesome. You get all the power of JavaScript and its tooling when writing your markup.</li><li>It is the natural match for <a href="https://facebook.github.io/flux/">Flux</a> and Redux (more on that later).</li><li>The React community is amazing, and produced many best of breed tools such as Redux (also more on that later).</li><li>Writing high quality data flow is much easier in large applications than dealing with 2 way data binding (eg: Knockout)</li><li>If you ever need to do server side rendering, React is where it’s at.</li></ul><p>There’s plenty of monolithic frameworks like Ember, Aurelia and Angular that promise to take care of everything, but the React ecosystem, while requiring a few more decisions (that’s why you’re reading this!), is much more robust. Many of these frameworks, such as Angular 2.0, are playing catch up with React.</p><p>Picking React isn’t a technology decision, it’s a <a href="https://blog.formidable.com/using-react-is-a-business-decision-not-a-technology-choice-63c4641c5f7">business decision</a>.</p><blockquote><em>Bonus points: Once you start working on your mobile apps, you’ll be ready for it thanks to </em><a href="https://facebook.github.io/react-native/"><em>React Native</em></a><em>.</em></blockquote><h3>Application life cycle: Redux</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/255/1*kBEjK_DHrIRit-MFmX9reQ.png" /><figcaption>This isn’t the final logo!</figcaption></figure><p>Now that we have our view and component layer, we need something to manage state and the lifecycle of our application. <a href="https://github.com/reactjs/redux">Redux</a> is also a clear winner here.</p><p>Alongside React, Facebook presented a design pattern for one way data flow called <a href="https://facebook.github.io/flux/">Flux</a>. Flux largely delivered on its promise of simplifying state management, but it also brought with it more questions, such as how to store that state and where to do Ajax requests.</p><p>To answer those questions, countless frameworks were built on top of the Flux pattern: Fluxible, Reflux, Alt, Flummox, Lux, Nuclear, Fluxxor and many, many more.</p><p>One Flux-like implementation eventually caught the community’s attention, and for good reasons: Redux.</p><p>In Redux, almost all of the moving parts are <a href="https://en.wikipedia.org/wiki/Pure_function">pure functions</a>. There is one centralized store and source of truth. Reducer functions are responsible for manipulating data that makes up the store. Everything is much clearer than in vanilla Flux.</p><p>More importantly, learning Redux is a snap. Redux’s author, <a href="https://twitter.com/dan_abramov">Dan Abramov</a> is a fantastic teacher, and his training videos are fantastic. Watch the videos, become a Redux expert. I’ve seen a team of engineers go from nearly zero React experience to having a production ready application with top notch code in a few weeks.</p><p>Redux’s ecosystem is as top notch as Redux itself. From the nearly magical <a href="https://github.com/gaearon/redux-devtools">devtool</a> to the amazing memoization utility <a href="https://github.com/reactjs/reselect">reselect</a>, the Redux community got your back.</p><p>One thing to be careful is the natural instinct to try and abstract away the Redux boilerplate. There’s good reasons behind all those pieces. Make sure you tried it and understand the “why” before trying to blindly improve on it.</p><h3>Language: ES6 with Babel. No types (yet)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/241/1*MbLmtXI-aYGF89xYhyROtQ.png" /></figure><p>Avoid CoffeeScript. Most of its better features are now in ES6, a standard. Tooling (such as CoffeeLint) is very weak. Its community is also rapidly declining.</p><p>ES6 is a standard. Most of it <a href="https://kangax.github.io/compat-table/es6/">is supported</a> in the latest version of major browsers. Babel is an amazing “pluggable” ES6 compiler. Configure it with the right presets for your target browsers and you’re good to go.</p><p>What about types? <a href="http://www.typescriptlang.org/">TypeScript</a> and <a href="http://flowtype.org/">Flow</a> both offer ways to add static typing to JavaScript, enhancing tooling and catching bugs without needing tests. With that said, I suggest a wait and see approach for now.</p><p>TypeScript tries too hard to make JavaScript like C# or Java, lacking on modern type system features such as <a href="https://en.wikipedia.org/wiki/Algebraic_data_type">algebraic data types</a> (and you really want those if you’re going to do static types!). It also doesn’t handle nulls as well as Flow.</p><p><strong>EDIT</strong><em>: It was brought up that TypeScript does have things like union types which cover a lot of use cases. I only meant that I think when it comes to type system in UX-land, you go all the way or not at all.</em></p><p>Flow can be much more powerful, catching a wider variety of bugs, but it can be hard to setup. It’s also behind Babel in terms of language features and has poor Windows support.</p><p>I’ll say something controversial: Types are not nearly as critical to front end development as some will have you believe (the whole argument will have to be in a future blog post). Wait until the type systems are more robust and stick to Babel for now, keeping an eye on Flow as it matures.</p><h3>Linting &amp; style: ESLint with Airbnb</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/133/1*iK06h6GPf6RAf6f6gp3GHw.png" /></figure><p>Another clear winner <a href="http://eslint.org/">ESLint</a>. With its React plugin and awesome ES6 support, one could not ask for more of a linter. <a href="http://www.jslint.com/">JSLint</a> is dated. ESlint does what the <a href="http://jshint.com/">JSHint</a> + <a href="http://jscs.info/">JSCS</a> combo does in a single tool.</p><p><strong>Edit</strong>:<em> after I wrote this, the ESlint team announced that the JSCS team was now joining them.</em></p><p>You do have to configure it with your style preferences. I highly recommend <a href="https://github.com/airbnb/javascript">Airbnb’s styleguide</a>, most of which can be enforced via the <a href="https://www.npmjs.com/package/eslint-config-airbnb">ESlint airbnb config</a>. If your team is the kind that will argue on code style, just use this style guide as gospel and the end all be all of arguments. It isn’t perfect, but the value of having consistent code is highly underestimated.</p><p>Once you’re comfortable with it, I’d suggest enabling even more rules. The more that can be caught while typing (with an ESlint plugin for your favorite editor), the less decision fatigue you’ll have and the more productive you and your team will be.</p><h3>Dependency management: It’s all about NPM, CommonJS and ES6 modules</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/202/1*C48H18qc-dq0wXu2xBMv7A.png" /></figure><p>This one is easy. Use NPM. For everything. Forget about Bower. Build tools such as Browserify and Webpack brings NPM’s power to the web. Versioning is handled easily and you get most of the Node.js ecosystem. Handling of CSS is still less than optimal though.</p><p>One thing you’ll want to consider is how to handle building on your deployment server. Unlike Ruby’s <a href="http://bundler.io/">Bundler</a>, NPM uses wildcard versions, and packages can change between the time you finish coding and you start deploying. Use a <a href="https://docs.npmjs.com/cli/shrinkwrap">shrinkwrap</a> file to freeze your dependencies (I recommend using <a href="https://github.com/uber/npm-shrinkwrap">Uber’s shrinkwrap</a> to get more consistent output). Also consider hosting your own private NPM server using something like <a href="https://www.npmjs.com/package/sinopia">Sinopia</a>.</p><p>Babel will compile <a href="http://www.2ality.com/2014/09/es6-modules-final.html">ES6 module</a> syntax to <a href="https://nodejs.org/docs/latest/api/modules.html">CommonJS</a>. You’ll get a future proof syntax, and the benefits of static code analysis, such as <a href="http://www.2ality.com/2015/12/webpack-tree-shaking.html">tree shaking</a> when using a build tool that supports it (Webpack 2.0 or <a href="http://http//rollupjs.org/">Rollup</a>).</p><h3>Build tool: Webpack</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/0*mmlsOUZXJg2yWqQx.png" /></figure><p>Unless you fancy adding hundreds of script tags to your pages, you need a build tool to bundle your dependencies. You also need something to allow NPM packages to work in browsers. This is where Webpack comes in.</p><p>A year ago you had a lot of potential options here. Your environment, such as Rails’ <a href="https://github.com/rails/sprockets">sprockets</a> could do it. <a href="http://requirejs.org/">RequireJS</a>, <a href="http://browserify.org/">Browserify</a> and Webpack were the JavaScript based solutions. Now, <a href="http://rollupjs.org/">RollupJS</a> promises to handle ES6 modules optimally.</p><p>After trying them all, I highly recommend Webpack:</p><ul><li>It is more opinionated yet can be configured to handle even the craziest scenarios.</li><li>All main module formats (AMD, CommonJS, globals) are supported.</li><li>It has features to fix broken modules.</li><li>It can handle CSS.</li><li>It has the most comprehensive cache busting/hashing system (if you push your stuff to CDNs).</li><li>It supports hot reload out of the box.</li><li>It can load almost <a href="https://webpack.github.io/docs/list-of-loaders.html">anything</a>.</li><li>It has an impressive list of <a href="https://github.com/webpack/docs/wiki/optimization">optimizations</a>.</li></ul><p>Webpack is also by far the best to handle extremely large SPA applications with built in code splitting and lazy loading.</p><p>Be warned that the learning curve is brutal! But once you get it, you’ll be rewarded with the best build system available.</p><p>But what about Gulp or Grunt? Webpack is much better at processing assets. They can still be useful if you need to run other kind of tasks though (usually you won’t). For basic tasks (such as running Webpack or ESlint), I recommend simply using <a href="https://docs.npmjs.com/cli/run-script">NPM scripts</a>.</p><h3>Testing: Mocha + Chai + Sinon (but it’s not that simple)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/192/0*aEF1UYWsr_ja1fO6." /></figure><p>There are a LOT of options for unit testing in JavaScript, and you can’t go wrong with any of them. If you have unit tests, that’s already good!</p><p>Some choices are <a href="http://jasmine.github.io/">Jasmine</a>, <a href="https://mochajs.org/">Mocha</a>, <a href="https://github.com/substack/tape">Tape</a> and <a href="https://github.com/sindresorhus/ava">AVA</a> and <a href="https://facebook.github.io/jest/">Jest</a>. I’m sure I’m forgetting some. They all have something they do better than the rest.</p><p>My criteria for a test framework are as follow:</p><ul><li>It should work in the browser for ease of debugging</li><li>It should be fast</li><li>It should easily handle asynchronous tests</li><li>It should be easy to use from the command line</li><li>It should let me use whatever assertion and mock library I want</li></ul><p>The first criteria knocks out AVA (even though it looks awesome) and Jest (auto-mocking isn’t nearly as nice as it sounds, and is very slow anyway).</p><p>You can’t really go wrong with Jasmine, Mocha or Tape. I prefer Chai asserts because of all available plugins and Sinon’s mocks to Jasmine’s built in construct, and Mocha’s asynchronous test support is superior (you don’t have to deal with done callbacks). <a href="https://github.com/domenic/chai-as-promised">Chai as Promised</a> is amazing. I highly recommend using <a href="https://github.com/prodatakey/dirty-chai">Dirty Chai</a> to avoid some headaches, though. Webpack’s <a href="https://github.com/webpack/mocha-loader">mocha-loader</a> let’s you automatically run tests as you code.</p><p>For React specific tooling, look at Airbnb’s <a href="https://github.com/airbnb/enzyme">Enzyme</a> and <a href="https://github.com/jquense/teaspoon">Teaspoon</a> (this isn’t the Rails based Teaspoon).</p><p>I really enjoy Mocha’s features and support. If you want something more minimalist, read <a href="https://medium.com/javascript-scene/why-i-use-tape-instead-of-mocha-so-should-you-6aa105d8eaf4">this article</a> about Tape.</p><p><strong><em>Edit 3/11/2016</em></strong><em>: Since I posted this, Facebook posted </em><a href="http://facebook.github.io/jest/blog/2016/03/11/javascript-unit-testing-performance.html"><em>this article</em></a><em> on how they make Jest scale. Probably a bit too complex for most people, but if you have the resources and don’t care about running things in the browser, you can probably make it awesome.</em></p><p><em>Additionally, a bunch of people thought I dismissed AVA too quickly. Don’t get me wrong, AVA is amazing. One of my criteria, however, is full browser support, so people can run them straight from any browser (to test cross browser support) and debug them easily. If you don’t care about that, you can use the fantastic </em><a href="https://github.com/s-a/iron-node"><em>iron-node</em></a><em> for debugging. Coupled with the bundled power asserts, it would easily beat my Mocha setup.</em></p><p><strong><em>Edit 4/21/2016</em></strong><em>: Had a chat with someone from Facebook about Jest. I didn’t get to try myself, but supposedly they run tens of thousands of tests (all of their tests) in &lt; 2 minutes on Jest with the bells and whistles, incluting things such as isolation of all the tests, some auto mocking, etc. Also, Jest’s mocking tool is quite nice and can be used anywhere. It’s available at </em><a href="https://github.com/facebook/jest/tree/master/packages/jest-mock"><em>https://github.com/facebook/jest/tree/master/packages/jest-mock</em></a><em>. I still like Mocha for its browser support, but if you don’t care about that and are comfortable debugging tests in </em><a href="https://github.com/s-a/iron-node"><em>iron-node</em></a><em>, Jest is a very strong option.</em></p><h3>Utility library: Lodash is king, but look at Ramda</h3><p>JavaScript doesn’t have a strong core of utilities like Java or .NET does, so you’ll most likely want to include one.</p><p>Lodash is by far the king and contains the entire kitchen sink. It is also one of the most performant, with features such as <a href="http://filimanjaro.com/blog/2014/introducing-lazy-evaluation/">lazy evaluation</a>. You don’t have to include the whole thing if you don’t want to, either: Lodash lets you include only the functions you use (pretty important considering how large it has become). As of 4.x, Lodash also natively supports an optional “functional” mode for the FP geeks among us. See how to use it <a href="https://github.com/lodash/lodash/wiki/FP-Guide">here</a>.</p><p>If you’re into functional programming, however, take a look at the fantastic <a href="http://ramdajs.com/0.19.1/index.html">Ramda</a>. If you decide to use it, you might still need to include some Lodash functions (Ramda is focused on data manipulation and functional construct almost exclusively), but you’ll get a lot of the power of functional programming languages in a JavaScript friendly way.</p><h3>Http requests: Just use fetch!</h3><p>Many React applications don’t need jQuery at all anymore. Unless you’re working on a legacy application or have 3rd party libraries that depend on it, there’s no reason to include it. That means you need to replace $.ajax.</p><p>I like to keep it simple and just use <a href="https://fetch.spec.whatwg.org/">fetch</a>. It’s promise based, it’s built in Firefox and Chrome, and it Just Works (tm). For other browsers, you’ll need to include a polyfill. I suggest <a href="https://github.com/matthew-andrews/isomorphic-fetch">isomorphic-fetch</a>, to ensure you have all your bases covered, including server side.</p><p>There are other good libraries such as <a href="https://github.com/mzabriskie/axios">Axios</a>, but I haven’t needed much beyond fetch.</p><blockquote><em>For more details about why promises are important, see my post on </em><a href="http://eng.localytics.com/better-asynchronous-javascript/"><em>asynchronous programming</em></a><em>.</em></blockquote><h3>Styling: Consider CSS modules</h3><p>This is an area I feel is lagging behind. <a href="http://sass-lang.com/">S</a>ass is the current go to, and <a href="https://github.com/sass/node-sass">node-sass</a> is a great way to use it in your JavaScript project. That said, I feel it’s missing a lot to be a perfect solution. Lack of reference imports (a way to import just variables and mixins from a file, without duplicating selectors) and native URL rewriting makes it harder than needed to keep things lean and clean in production. node-sass is a C library, and will have to be kept in sync with your Node version.</p><p><a href="http://lesscss.org/">LESS</a> does not suffer from these issues, but has fallen out of favor due to lacking many of Sass’ features.</p><p><a href="https://github.com/postcss/postcss">PostCSS</a> is much more promising, allowing you to kind of “make your own CSS processor”. I’d recommend using it on its own, or even in ADDITION to your preferred processor for things such as <a href="https://github.com/postcss/autoprefixer">AutoPrefixer</a> instead of importing a big library like <a href="http://bourbon.io/">Bourbon</a>.</p><p>One thing worthy of attention though, are <a href="http://glenmaddern.com/articles/css-modules">CSS modules</a>. CSS modules prevents the “cascading” part of CSS, allowing us to keep our dependencies explicit, and prevents conflict. You’ll never have to worry about overriding classes by accident or having to make ultra explicit names for your classes. It works great with React, too. One drawback: <a href="https://github.com/webpack/css-loader">css-loader</a> with CSS modules enabled is REALLY slow, so if you plan on having hundreds of kilobytes of CSS, you may want to avoid it until it gets better.</p><p>If I was to start a large project from scratch today, I’d probably just use PostCSS along with pre-compiled versions of my favorite CSS libraries.</p><p>Regardless of what you choose, you may want to look at my post on <a href="http://eng.localytics.com/faster-sass-builds-with-webpack/">CSS performance with Webpack</a>, especially if you go with Sass.</p><h3>Universal (Isomorphic) JavaScript: Make sure you need it.</h3><p>Universal or Isomorphic JavaScript refers to JavaScript that can be used on both the client and the server. This is primarily used to pre-render pages server side for performance and SEO purpose. Thanks to React, what was once only the realm of giants such as Ebay or Facebook is now within reach of most development shops. It is still not “free” though, adding significant complexity and limiting your options in term of libraries and tooling.</p><p>If you are building a B2C (Business to Customer) website, such as an e-commerce website, you may not have a choice but to go that route. For internal web or B2B (Business to Business) applications however, that kind of initial performance may not be required. Discuss with your product manager to see if the cost:benefit ratio is worth the trouble.</p><h3>The API: There’s still no true answer.</h3><p>It seems everyone lately is asking themselves what to do for API. Everyone is jumping in the <a href="https://en.wikipedia.org/wiki/Representational_state_transfer">RESTful API</a> bandwagon, and <a href="https://en.wikipedia.org/wiki/SOAP">SOAP</a> is a memory of the past. There are various specifications such as <a href="https://en.wikipedia.org/wiki/HATEOAS">HATEOAS</a>, <a href="http://jsonapi.org/">JSON API</a>, <a href="http://stateless.co/hal_specification.html">HAL</a>, <a href="https://facebook.github.io/react/blog/2015/05/01/graphql-introduction.html">GraphQL</a> among others.</p><p>GraphQL gives a large amount of power (and responsibility) to the client, allowing it to make nearly arbitrary queries. Along with <a href="https://facebook.github.io/relay/">Relay</a>, it handles client state and caching for you. Implementing the server side portion of GraphQL is difficult and most of the documentation is for Node though.</p><p>Netflix’s <a href="https://github.com/Netflix/falcor">Falcor</a> looks like it will eventually give us a lot of what GraphQL/Relay offers, with simpler server requirements. It is however only a developer preview and not ready for prime time.</p><p>All the well known specifications have their quirks. Some are overly complex. Some only handle reads and don’t cover update. Some stray significantly from REST. Many people choose to make their own, but then have to solve all the design problems on their own.</p><p>I don’t think any solutions out there is a slam dunk, but here’s what I think your API should have:</p><ul><li>It should be predictable. Your endpoints should follow consistent conventions.</li><li>It should allow fetching multiple entities in one round trip: needing 15 queries to fetch everything you need on page load will give poor performance.</li><li>Make sure you have a good update story: many specifications only covers reads, and you’ll need to update stuff sometimes.</li><li>It should be easy to debug: looking at the Chrome inspector’s network tab should easily let me see what happened.</li><li>It should be easy to consume: I should be able to easily consume it with fetch, or have a well supported client library (like Relay)</li></ul><p>I haven’t found a solution that covers all of the above. If there is one, let me know.</p><p>Consider looking at <a href="http://swagger.io/">Swagger</a> to document your API if you go the standard RESTful path.</p><h3>Desktop applications: Electron.</h3><p><a href="https://github.com/atom/electron">Electron</a> is the foundation of the great <a href="https://atom.io/">Atom</a> editor and can be used to make your own applications. At its core, it is a version of Node that can open Chrome windows to render a GUI, and has access to the operating system’s native APIs without a browser’s typical security sandboxing. You’ll be able to package your application and distribute it like any other desktop application, complete with an installer and auto-updates.</p><p>This is one of the easiest ways to make an application that can run on OSX, Windows and Linux while reusing all the tools listed above. It is well documented and has a very active community.</p><p>You may have heard of <a href="http://nwjs.io/">nw.js</a> (formerly node-webkit) which has existed longer (and does almost the same thing), but Electron is now more stable and is easier to use.</p><p>Take a look at this <a href="https://github.com/chentsulin/electron-react-boilerplate">great boilerplate</a> to play around with Electron, React and hot reload. You’ll probably want to start from scratch if you’re serious about making your own application so you understand how all the pieces work.</p><h3>Who to follow and where to learn more?</h3><p>This is a place where I’m falling short, but on Twitter I follow the following people:</p><ul><li><a href="https://github.com/gaearon">Dan Abramov</a>, author of Redux</li><li><a href="https://twitter.com/Vjeux">Christopher Chedeau</a> aka Vjeux, a React developer at Facebook very active in the community.</li><li><a href="https://github.com/jeffmo">Jeff Morrison</a>, one of the main Flow contributors.</li><li><a href="https://twitter.com/sebmarkbage">Sebastian Markbåge</a>, another React developer at Facebook, involved with the TC39</li><li><a href="https://twitter.com/floydophone">Pete Hunt</a>. Originally from Instagram and Facebook, famous for his <a href="https://www.youtube.com/watch?v=x7cQ3mrcKaY">Rethinking best practices</a> talk, partly responsible for putting React on the map.</li><li><a href="https://twitter.com/reactjs">React</a>, because duh.</li><li>The above are more are aggregated in <a href="https://twitter.com/oguzbilgic/lists/react-influencers">React Influencers</a></li></ul><p>While there’s many more worth noting, those people retweet almost anything worth looking at, so they’re a good start.</p><p>Consider reading Pete Hunt’s <a href="https://github.com/petehunt/react-howto">Learning React</a>. Follow the order!</p><p>Dan Abramov published the <a href="https://egghead.io/series/getting-started-with-redux">Getting started with Redux</a> video series. I can’t overstate how amazing it is at teaching Redux.</p><p>The official <a href="http://redux.js.org/docs/FAQ.html">Redux FAQ</a></p><p>Dan also published <a href="https://medium.com/@dan_abramov/my-react-list-862227952a8c#.740o0wzee">his own list</a>, and it’s probably better than mine.</p><p>Mark Erikson’s collection of <a href="https://github.com/markerikson/react-redux-links">React/Redux links</a> is an ever growing gold mine.</p><p>Read <a href="http://jlongster.com/Removing-User-Interface-Complexity,-or-Why-React-is-Awesome">Removing user interface complexity, or why React is awesome</a> to get a walkthrough of how React is designed and why.</p><h3>If you don’t need it, don’t use it</h3><p>The JavaScript ecosystem is thriving and moving quickly, but there’s finally an end at the light of the tunnel. Best practices are no longer changing constantly, and it is becoming increasingly clear which tools are worth learning.</p><p>The most important thing to remember is to keep it simple and only use what you need.</p><p>Is your application only 2–3 screens? Then you don’t need a router. Are you making a single page? Then you don’t even need Redux, just use React’s own state. Are you making a simple CRUD application? You don’t need Relay. Are you learning ES6? You don’t need Async/Await or Decorators. Are you just starting to learn React? You don’t need Hot reload and server rendering. Are you starting out with Webpack? You don’t need code splitting and multiple chunks. Are you starting with Redux? You don’t need Redux-Form or Redux-Sagas.</p><p>Keep it simple, one thing at a time, and you’ll wonder why people ever complained about JavaScript fatigue.</p><h3>Did I miss anything?</h3><p>And there you have it, my view of the current state of JavaScript. Do you think I forgot an important category? Do you think I’m objectively wrong on one of these choices? Do you recommend something else? Let me know!</p><p><strong><em>Edit 3/11/2016</em></strong><em>: Added some notes on alternate unit testing tools to clarify my stance of AVA and to include new information on Jest performance from Facebook.</em></p><p><strong><em>Edit 3/12/2016</em></strong><em>: Added a link to </em><a href="https://github.com/lodash/lodash/wiki/FP-Guide"><em>Lodash FP</em></a><em>. Because it’s awesome, and I should link to awesome. Also, the world is a better place with more functional programming in it.</em></p><p><strong>Edit 3/28/2016</strong>: Added link to the official Redux FAQ</p><p><strong>Edit 4/19/2016</strong>: Updated to mention that the JSCS and ESlint teams are joining force.</p><p><strong>Edit 4/21/2016<em>: </em></strong>Updated the unit testing section with information from a Facebook person about how awesome Jest is becoming.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab67fc68eb0b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javascript-and-opinions/state-of-the-art-javascript-in-2016-ab67fc68eb0b">State of the Art JavaScript in 2016</a> was originally published in <a href="https://medium.com/javascript-and-opinions">JavaScript and Opinions</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>