Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import configureStore from '../common/store/configureStore';
import Root from '../common/views/Root';

const history = createHashHistory({ queryKey: false });
const store = configureStore(window.__INITIAL_STATE__);
const store = configureStore(window.__INITIAL_STATE__, { history });
const node = <Root history={history} store={store} />;
const $target = document.getElementById('mount');

Expand Down
16 changes: 14 additions & 2 deletions common/store/configureStore.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@ import {applyMiddleware, createStore, compose} from 'redux';
import instance from './';
import reducers from '../modules';
import thunk from 'redux-thunk';
import {syncHistory} from 'redux-simple-router';
import DevTools from '../components/DevTools';

export default function configureStore(initialState) {
/**
* @param {object} initialState
* @param {object} drivers Used to inject dependencies
* @param {object} drivers.history History instance
*/
export default function configureStore(initialState, {history}) {
const reduxRouterMiddleware = syncHistory(history);
const createStoreWithMiddleware = compose(
applyMiddleware(thunk),
applyMiddleware(thunk, reduxRouterMiddleware),
DevTools.instrument()
);
const finalCreateStore = createStoreWithMiddleware(createStore);
const store = finalCreateStore(reducers, initialState);

// Required for redux-simple-router to replay actions from devtools to work
if ( process.env.REDUX_DEVTOOLS ) {
reduxRouterMiddleware.listenForReplays(store);
}

instance.set(store);

return store;
Expand Down
14 changes: 11 additions & 3 deletions common/store/configureStore.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ import {applyMiddleware, createStore, compose} from 'redux';
import instance from './';
import reducers from '../modules';
import thunk from 'redux-thunk';
import {syncHistory} from 'redux-simple-router';

export default function configureStore(initialState) {
const createStoreWithMiddleware = compose(
applyMiddleware(thunk)
/**
* @param {object} initialState
* @param {object} drivers Used to inject dependencies
* @param {object} drivers.history History instance
*/
export default function configureStore(initialState, {history}) {
const reduxRouterMiddleware = syncHistory(history);
const createStoreWithMiddleware = applyMiddleware(
thunk,
reduxRouterMiddleware
);
const finalCreateStore = createStoreWithMiddleware(createStore);
const store = finalCreateStore(reducers, initialState);
Expand Down
11 changes: 0 additions & 11 deletions common/views/Root.dev.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@ import React, { PropTypes } from 'react';

import {Provider} from 'react-redux';
import {Router} from 'react-router';
import {syncReduxAndRouter} from 'redux-simple-router';
import routes from '../routes';
import Helmet from 'react-helmet';
import DevTools from '../components/DevTools';

class Root extends React.Component {
constructor(props, context) {
super(props, context);

this.bootstrapReduxRouter();
}

render() {
return (
<div>
Expand All @@ -35,10 +28,6 @@ class Root extends React.Component {
renderDevTools() {
return _REDUX_DEVTOOLS_ ? <DevTools /> : null;
}

bootstrapReduxRouter() {
syncReduxAndRouter(this.props.history, this.props.store);
}
}

Root.propTypes = {
Expand Down
11 changes: 0 additions & 11 deletions common/views/Root.prod.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@ import React, { PropTypes } from 'react';

import {Provider} from 'react-redux';
import {Router} from 'react-router';
import {syncReduxAndRouter} from 'redux-simple-router';
import routes from '../routes';
import Helmet from 'react-helmet';

class Root extends React.Component {
constructor(props, context) {
super(props, context);

this.bootstrapReduxRouter();
}

render() {
return (
<div>
Expand All @@ -26,10 +19,6 @@ class Root extends React.Component {
</div>
);
}

bootstrapReduxRouter() {
syncReduxAndRouter(this.props.history, this.props.store);
}
}

Root.propTypes = {
Expand Down
6 changes: 3 additions & 3 deletions common/views/home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class HomeView extends React.Component {
}

render() {
console.log(this.props);

return (
<div>
Clicks: {this.props.counter}
Expand All @@ -33,9 +35,7 @@ HomeView.propTypes = {
};

function mapStateToProps (state) {
return {
counter: state.counter
};
return state;
}

function mapDispatchToProps (dispatch) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"react-resolver": "^2.0.5",
"react-router": "^1.0.0",
"redux": "^3.0.4",
"redux-simple-router": "^1.0.2",
"redux-simple-router": "^2.0.3",
"redux-thunk": "^1.0.0",
"url-join": "0.0.1"
},
Expand Down
2 changes: 1 addition & 1 deletion server/middlewares/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const htmlRegex = /\${html}/g;

export default function *appMiddleware() {
const history = createMemoryHistory();
const store = configureStore();
const store = configureStore(null, { history });

match({ routes, location: this.request.url }, (err, redirect, props) => {
if ( err ) {
Expand Down