Skip to content
This repository has been archived by the owner on Sep 11, 2018. It is now read-only.

Commit

Permalink
(refactor)app: switch to redux-simple-router
Browse files Browse the repository at this point in the history
  • Loading branch information
justingreenberg committed Nov 26, 2015
1 parent bc477b4 commit db66626
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 30 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Features
* Includes react-addons-test-utils (`^0.14.0`)
* [React-Router](https://github.com/rackt/react-router) (`^1.0.0`)
* [Redux](https://github.com/gaearon/redux) (`^3.0.0`)
* redux-router (`^1.0.0-beta3`)
* redux-simple-router (`^0.0.10`)
* react-redux (`^4.0.0`)
* redux-devtools
* use `npm run dev:nw` to display in a separate window.
Expand Down Expand Up @@ -154,7 +154,7 @@ You can redefine which packages to treat as vendor dependencies by editing `vend
'react',
'react-redux',
'react-router',
'redux-router',
'redux-simple-router',
'redux'
]
```
Expand Down
2 changes: 1 addition & 1 deletion config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ config.set('vendor_dependencies', [
'react-redux',
'react-router',
'redux',
'redux-router'
'redux-simple-router'
].filter(dep => {
if (pkg.dependencies[dep]) return true;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"react-redux": "^4.0.0",
"react-router": "1.0.0",
"redux": "^3.0.0",
"redux-router": "^1.0.0-beta3",
"redux-simple-router": "^0.0.10",
"redux-thunk": "^1.0.0",
"yargs": "^3.18.0"
},
Expand Down
26 changes: 17 additions & 9 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import React from 'react';
import ReactDOM from 'react-dom';
import Root from './containers/Root';
import configureStore from './store/configureStore';
import React from 'react';
import ReactDOM from 'react-dom';
import createBrowserHistory from 'history/lib/createBrowserHistory';
import { syncReduxAndRouter } from 'redux-simple-router';
import Root from './containers/Root';
import configureStore from './store/configureStore';

const target = document.getElementById('root');
const store = configureStore(window.__INITIAL_STATE__, __DEBUG__);
const target = document.getElementById('root');
const history = createBrowserHistory();
const store = configureStore(window.__INITIAL_STATE__, __DEBUG__);

syncReduxAndRouter(history, store);

const node = (
<Root store={store}
debug={__DEBUG__}
debugExternal={__DEBUG_NW__} />
<Root
history={history}
store={store}
debug={__DEBUG__}
debugExternal={__DEBUG_NW__}
/>
);

ReactDOM.render(node, target);
11 changes: 6 additions & 5 deletions src/containers/Root.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React from 'react';
import { Provider } from 'react-redux';
import { Router } from 'react-router';
import routes from '../routes';
import { ReduxRouter } from 'redux-router';
import DevTools from './DevTools';
import { createDevToolsWindow } from '../utils';

export default class Root extends React.Component {
static propTypes = {
store : React.PropTypes.object.isRequired,
debug : React.PropTypes.bool,
history : React.PropTypes.object.isRequired,
store : React.PropTypes.object.isRequired,
debug : React.PropTypes.bool,
debugExternal : React.PropTypes.bool
}

Expand All @@ -30,9 +31,9 @@ export default class Root extends React.Component {
return (
<Provider store={this.props.store}>
<div>
<ReduxRouter>
<Router history={this.props.history}>
{routes}
</ReduxRouter>
</Router>
{this.renderDevTools()}
</div>
</Provider>
Expand Down
4 changes: 2 additions & 2 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { combineReducers } from 'redux';
import { routerStateReducer } from 'redux-router';
import { routeReducer } from 'redux-simple-router';
import counter from './counter';

export default combineReducers({
counter,
router: routerStateReducer
routing: routeReducer
});
4 changes: 3 additions & 1 deletion src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import React from 'react';
import { Route, IndexRoute } from 'react-router';
import CoreLayout from 'layouts/CoreLayout';
import HomeView from 'views/HomeView';
import AboutView from 'views/AboutView';

export default (
<Route path='/' component={CoreLayout}>
<Route component={CoreLayout} path='/'>
<IndexRoute component={HomeView} />
<Route component={AboutView} path='/about' />
</Route>
);
9 changes: 0 additions & 9 deletions src/store/configureStore.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import rootReducer from '../reducers';
import thunk from 'redux-thunk';
import routes from '../routes';
import { reduxReactRouter } from 'redux-router';
import createHistory from 'history/lib/createBrowserHistory';
import DevTools from 'containers/DevTools';
import {
applyMiddleware,
Expand All @@ -18,14 +15,8 @@ export default function configureStore (initialState, debug = false) {
if (debug) {
createStoreWithMiddleware = compose(
middleware,
reduxReactRouter({ routes, createHistory }),
DevTools.instrument()
);
} else {
createStoreWithMiddleware = compose(
middleware,
reduxReactRouter({ routes, createHistory })
);
}

const store = createStoreWithMiddleware(createStore)(
Expand Down
12 changes: 12 additions & 0 deletions src/views/AboutView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import { Link } from 'react-router';

const AboutView = () => (
<div className='container text-center'>
<h1>This is the about view!</h1>
<hr />
<Link to='/'>Back To Home View</Link>
</div>
);

export default AboutView;
3 changes: 3 additions & 0 deletions src/views/HomeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import counterActions from 'actions/counter';
import { Link } from 'react-router';

// We define mapStateToProps and mapDispatchToProps where we'd normally use
// the @connect decorator so the data requirements are clear upfront, but then
Expand Down Expand Up @@ -30,6 +31,8 @@ export class HomeView extends React.Component {
onClick={this.props.actions.increment}>
Increment
</button>
<hr />
<Link to='/about'>Go To About View</Link>
</div>
);
}
Expand Down

0 comments on commit db66626

Please sign in to comment.