Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add redux-devtools #27

Closed
wants to merge 5 commits into from
Closed
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
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-slingshot",
"version": "1.0.1",
"version": "1.0.3",
"description": "Starter kit for creating apps with React and Redux",
"scripts": {
"prestart": "npm run remove-dist",
Expand All @@ -20,6 +20,9 @@
"test:watch": "npm run test -- --watch"
},
"author": "Cory House",
"contributors": [
"Barry Staes (http://barrystaes.nl/)"
],
"license": "MIT",
"dependencies": {
"object-assign": "4.0.1",
Expand Down Expand Up @@ -50,6 +53,8 @@
"react-transform-catch-errors": "1.0.0",
"react-transform-hmr": "1.0.1",
"redbox-react": "1.2.0",
"redux-devtools": "3.0.1",
"redux-devtools-log-monitor": "1.0.2",
"rimraf": "2.5.0",
"sass-loader": "3.1.2",
"style-loader": "0.12.3",
Expand Down
2 changes: 2 additions & 0 deletions src/containers/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class App extends React.Component {
const { fuelSavingsAppState, actions } = this.props;

return (
<div>
<FuelSavingsApp fuelSavingsAppState={fuelSavingsAppState} actions={actions} />
</div>
);
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/containers/DevTools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';

import { createDevTools } from 'redux-devtools';
import LogMonitor from 'redux-devtools-log-monitor';

const DevTools = createDevTools(
<LogMonitor theme="solarized" />
);

export default DevTools;
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ render(
<App />
</Provider>, document.getElementById('app')
);

if (process.env.NODE_ENV !== 'production') {
const showDevTools = require('./showDevTools');
showDevTools(store);
}
17 changes: 17 additions & 0 deletions src/showDevTools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import { render } from 'react-dom';
import DevTools from './containers/DevTools';

export default function showDevTools(store) {
const popup = window.open(null, 'Redux DevTools', 'menubar=no,location=no,resizable=yes,scrollbars=no,status=no');
// Reload in case it already exists
popup.location.reload();

setTimeout(() => {
popup.document.write('<div id="react-devtools-root"></div>');
render(
<DevTools store={store} />,
popup.document.getElementById('react-devtools-root')
);
}, 10);
}
30 changes: 30 additions & 0 deletions src/store/configureStore.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//Remember to keep the production/development version of this file in sync.
//This boilerplate file is likely to be the same for each project that uses Redux.
//With Redux, the actual stores are in /reducers.

import { createStore, compose } from 'redux';
import rootReducer from '../reducers';
import DevTools from '../containers/DevTools';

const finalCreateStore = compose(
// Middleware you want to use in development:
//applyMiddleware(d1, d2, d3),
// Required! Enable Redux DevTools with the monitors you chose
DevTools.instrument()
)(createStore);

export default function configureStore(initialState) {
// Add middleware
const store = finalCreateStore(rootReducer, initialState);

// Configure the store for hot reloading
if (module.hot) {
// Enable Webpack hot module replacement for reducers
module.hot.accept('../reducers', () => {
const nextReducer = require('../reducers');
store.replaceReducer(nextReducer);
});
}

return store;
}
25 changes: 6 additions & 19 deletions src/store/configureStore.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
//This file merely configures the store for hot reloading.
//This boilerplate file is likely to be the same for each project that uses Redux.
//With Redux, the actual stores are in /reducers.

import { createStore } from 'redux';
import rootReducer from '../reducers';

export default function configureStore(initialState) {
const store = createStore(rootReducer, initialState);

if (module.hot) {
// Enable Webpack hot module replacement for reducers
module.hot.accept('../reducers', () => {
const nextReducer = require('../reducers');
store.replaceReducer(nextReducer);
});
}

return store;
// Use DefinePlugin (Webpack) or loose-envify (Browserify)
// together with Uglify to strip the dev branch in prod build.
if (process.env.NODE_ENV === 'production') {
module.exports = require('./configureStore.prod');
} else {
module.exports = require('./configureStore.dev');
}
17 changes: 17 additions & 0 deletions src/store/configureStore.prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//Remember to keep the production/development version of this file in sync.
//This boilerplate file is likely to be the same for each project that uses Redux.
//With Redux, the actual stores are in /reducers.

import { createStore, compose } from 'redux';
import rootReducer from '../reducers';

const finalCreateStore = compose(
// Middleware you want to use in production:
//applyMiddleware(d1, d2, d3),
// Other store enhancers if you use any
)(createStore);

export default function configureStore(initialState) {
// Add middleware
return finalCreateStore(rootReducer, initialState);
}
3 changes: 3 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ var getPlugins = function(env) {
break;
}

// This allows DevTools component to be included
plugins.push(new webpack.DefinePlugin({'process.env.NODE_ENV': JSON.stringify(env)}));

return plugins;
};

Expand Down