git.fiddlerwoaroof.com
Browse code

really add github badge

Ed Langley authored on 18/06/2017 05:29:04
Showing 2 changed files
... ...
@@ -10,7 +10,7 @@
10 10
   </head>
11 11
   <body>
12 12
     <article>
13
-      <root><h1 id="routedux--routes-the-redux-way">Routedux — Routes the Redux Way</h1><p><img alt="Route Dux" src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/da/Ducks_crossing_the_road_sign.png/92px-Ducks_crossing_the_road_sign.png" align="right"/></p><p><a href="https://badge.fury.io/js/routedux"><img src="https://badge.fury.io/js/routedux.svg" alt="npm version"/></a> <a href="https://travis-ci.org/cjdev/routedux"><img src="https://travis-ci.org/cjdev/routedux.svg?branch=master" alt="Build Status"/></a><a href="https://github.com/cjdev/routedux"><img src="https://img.shields.io/github/stars/badges/shields.svg?style=social&amp;label=Star" alt="GitHub stars"/></a></p><p>Routedux routes URLs to Redux actions and vice versa.</p><p>Your application doesn&rsquo;t need to know it lives in a browser, but your users want pretty urls and deep links.</p><h2 id="wait-my-application-doesnt-need-to-know-it-lives-in-a-browser">Wait, my application doesn&rsquo;t need to know it lives in a browser?</h2><p>URLs are great for finding things on the internet. But a single page application is not the same as a collection of resources that lives on a remote server.</p><p>A single page application is a web application only in the sense that it lives on the web. URLs are are not essential to it working well.</p><p>URLs give users accessing your application in a browser the ability to bookmark a particular view in your application so that their expectation of browser-based applications will continue to work.</p><p>We think that&rsquo;s a good thing, but we also don&rsquo;t think the idea of url paths should be littered through your application.</p><p>When you are developing a redux application, you want your UI to be a pure function of the current state tree.</p><p>By adding routes to that, it makes it harder to test. And this difficulty can be compounded by other decisions about how to add routes to your application.</p><h2 id="an-alternative-approach">An alternative approach</h2><p>React Router is the currently-accepted way to do URL routing in React applications. For a standard React application without Redux, this solution isn&rsquo;t too bad. But once you add Redux, things get difficult.</p><p>We basically discovered the same lessons as Formidable Labs: <a href="http://formidable.com/blog/2016/07/11/let-the-url-do-the-talking-part-1-the-pain-of-react-router-in-redux/">React Router is the wrong way to route in Redux apps.</a></p><p>However, we don&rsquo;t think their solution (<a href="https://github.com/FormidableLabs/redux-little-router">redux-little-router</a>) goes far enough, as it still embeds the idea of routes throughout your user interface.</p><p>Once you separate URLs from your application state, you can easily port it to other environments that don&rsquo;t know what URLs are, and by simply removing the routing declaration, things will work as before.</p><p>As an added (and we think absolutely essential) benefit, your entire application becomes easier to test, as rendering is a pure function of Redux state, and model logic and route actions are entirely encapsulated in Redux outside of the app.</p><h2 id="simple-routing-in-25-lines">Simple Routing in 25 lines</h2><pre class="brush: javascript"><code>import installBrowserRouter from 'routedux';
13
+      <root><h1 id="routedux--routes-the-redux-way">Routedux — Routes the Redux Way</h1><p><img alt="Route Dux" src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/da/Ducks_crossing_the_road_sign.png/92px-Ducks_crossing_the_road_sign.png" align="right"/></p><p><a href="https://badge.fury.io/js/routedux"><img src="https://badge.fury.io/js/routedux.svg" alt="npm version"/></a> <a href="https://travis-ci.org/cjdev/routedux"><img src="https://travis-ci.org/cjdev/routedux.svg?branch=master" alt="Build Status"/></a><a href="https://github.com/cjdev/routedux/"><img src="https://img.shields.io/github/stars/cjdev/routedux.svg?style=flat-square" alt="GitHub stars"/></a></p><p>Routedux routes URLs to Redux actions and vice versa.</p><p>Your application doesn&rsquo;t need to know it lives in a browser, but your users want pretty urls and deep links.</p><h2 id="wait-my-application-doesnt-need-to-know-it-lives-in-a-browser">Wait, my application doesn&rsquo;t need to know it lives in a browser?</h2><p>URLs are great for finding things on the internet. But a single page application is not the same as a collection of resources that lives on a remote server.</p><p>A single page application is a web application only in the sense that it lives on the web. URLs are are not essential to it working well.</p><p>URLs give users accessing your application in a browser the ability to bookmark a particular view in your application so that their expectation of browser-based applications will continue to work.</p><p>We think that&rsquo;s a good thing, but we also don&rsquo;t think the idea of url paths should be littered through your application.</p><p>When you are developing a redux application, you want your UI to be a pure function of the current state tree.</p><p>By adding routes to that, it makes it harder to test. And this difficulty can be compounded by other decisions about how to add routes to your application.</p><h2 id="an-alternative-approach">An alternative approach</h2><p>React Router is the currently-accepted way to do URL routing in React applications. For a standard React application without Redux, this solution isn&rsquo;t too bad. But once you add Redux, things get difficult.</p><p>We basically discovered the same lessons as Formidable Labs: <a href="http://formidable.com/blog/2016/07/11/let-the-url-do-the-talking-part-1-the-pain-of-react-router-in-redux/">React Router is the wrong way to route in Redux apps.</a></p><p>However, we don&rsquo;t think their solution (<a href="https://github.com/FormidableLabs/redux-little-router">redux-little-router</a>) goes far enough, as it still embeds the idea of routes throughout your user interface.</p><p>Once you separate URLs from your application state, you can easily port it to other environments that don&rsquo;t know what URLs are, and by simply removing the routing declaration, things will work as before.</p><p>As an added (and we think absolutely essential) benefit, your entire application becomes easier to test, as rendering is a pure function of Redux state, and model logic and route actions are entirely encapsulated in Redux outside of the app.</p><h2 id="simple-routing-in-25-lines">Simple Routing in 25 lines</h2><pre class="brush: javascript"><code>import installBrowserRouter from 'routedux';
14 14
 import {createStore, compose, applyMiddleware} from 'redux';
15 15
 
16 16
 const LOAD_USER = 'LOAD_USER';
... ...
@@ -4,7 +4,7 @@
4 4
 
5 5
 <img alt="Route Dux" src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/da/Ducks_crossing_the_road_sign.png/92px-Ducks_crossing_the_road_sign.png" align="right" />
6 6
 
7
-[![npm version](https://badge.fury.io/js/routedux.svg)](https://badge.fury.io/js/routedux) [![Build Status](https://travis-ci.org/cjdev/routedux.svg?branch=master)](https://travis-ci.org/cjdev/routedux)[![GitHub stars](https://img.shields.io/github/stars/badges/shields.svg?style=social&label=Star)](https://github.com/cjdev/routedux)
7
+[![npm version](https://badge.fury.io/js/routedux.svg)](https://badge.fury.io/js/routedux) [![Build Status](https://travis-ci.org/cjdev/routedux.svg?branch=master)](https://travis-ci.org/cjdev/routedux)[![GitHub stars](https://img.shields.io/github/stars/cjdev/routedux.svg?style=flat-square)](https://github.com/cjdev/routedux/)
8 8
 
9 9
 Routedux routes URLs to Redux actions and vice versa.
10 10