From 6a391268e5b7d2a444ae331bff6f7386ac315168 Mon Sep 17 00:00:00 2001 From: Louis St-Amour Date: Thu, 20 Jul 2017 15:09:07 -0400 Subject: [PATCH] Adding react and redux dev tools (#327) * Adding react & redux dev tools To dev builds, using electron-devtools-installer * Corrected lint error * Updating package-lock. --- app/main.development.js | 8 ++++++++ app/ui/redux/create.js | 14 ++++++++++++-- package-lock.json | 18 ++++++++++++++++++ package.json | 1 + 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/app/main.development.js b/app/main.development.js index 23526987a..99e388f27 100644 --- a/app/main.development.js +++ b/app/main.development.js @@ -4,6 +4,7 @@ import {isDevelopment, isMac} from './common/constants'; import * as errorHandling from './main/error-handling'; import * as updates from './main/updates'; import * as windowUtils from './main/window-utils'; +import installExtension, { REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS } from 'electron-devtools-installer'; // Handle potential auto-update if (needsRestart) { @@ -55,6 +56,13 @@ app.on('activate', (e, hasVisibleWindows) => { // When the app is first launched app.on('ready', () => { + installExtension(REACT_DEVELOPER_TOOLS) + .then((name) => console.log(`Added Extension: ${name}`)) + .catch((err) => console.log('An error occurred: ', err)); + installExtension(REDUX_DEVTOOLS) + .then((name) => console.log(`Added Extension: ${name}`)) + .catch((err) => console.log('An error occurred: ', err)); + app.removeListener('open-url', addUrlToOpen); const window = windowUtils.createWindow(); diff --git a/app/ui/redux/create.js b/app/ui/redux/create.js index 89ba9ecdd..76416a702 100644 --- a/app/ui/redux/create.js +++ b/app/ui/redux/create.js @@ -1,10 +1,20 @@ -import {createStore, applyMiddleware} from 'redux'; +import {createStore, applyMiddleware, compose} from 'redux'; import thunkMiddleware from 'redux-thunk'; import {reducer} from './modules'; export default function () { + const composeEnhancers = + typeof window === 'object' && + window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ + ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({ + // Specify extension’s options like name, actionsBlacklist, actionsCreators, serialize... + }) : compose; const middleware = [thunkMiddleware]; - const store = createStore(reducer, applyMiddleware(...middleware)); + const enhancer = composeEnhancers( + applyMiddleware(...middleware), + // other store enhancers if any + ); + const store = createStore(reducer, enhancer); if (__DEV__ && module.hot) { module.hot.accept('./modules/index', () => { store.replaceReducer(reducer); diff --git a/package-lock.json b/package-lock.json index 1ccbd2e5f..0dddf9315 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,12 @@ "integrity": "sha512-7+0Ai8r8Xt6NNVM0Eo+XSqiZsBUYXg2yrCwyBhQzSfFHTGQWzFv/pk9106vPR8HWjKmGK+zzUj244POs4xfO2g==", "dev": true }, + "7zip": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/7zip/-/7zip-0.0.6.tgz", + "integrity": "sha1-nK+xca+CMpSQNTtIFvAzR6oVCjA=", + "dev": true + }, "7zip-bin": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/7zip-bin/-/7zip-bin-2.0.4.tgz", @@ -1633,6 +1639,12 @@ "integrity": "sha1-vWf5bAfvtjA7f+lMHpefiEeOCjk=", "dev": true }, + "cross-unzip": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/cross-unzip/-/cross-unzip-0.0.2.tgz", + "integrity": "sha1-UYO8R6CVWb78+YzEZXlkmZNZNy8=", + "dev": true + }, "cryptiles": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-2.0.5.tgz", @@ -2053,6 +2065,12 @@ "resolved": "https://registry.npmjs.org/electron-context-menu/-/electron-context-menu-0.9.0.tgz", "integrity": "sha1-ima+9QLwUkJVoTUKK0cE26rP1QM=" }, + "electron-devtools-installer": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/electron-devtools-installer/-/electron-devtools-installer-2.2.0.tgz", + "integrity": "sha1-mBPmgRr81p3co8rlQW23Lqfs+2o=", + "dev": true + }, "electron-dl": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/electron-dl/-/electron-dl-1.9.0.tgz", diff --git a/package.json b/package.json index 8ab3f061e..f95fecbbe 100644 --- a/package.json +++ b/package.json @@ -172,6 +172,7 @@ "css-loader": "^0.26.2", "electron": "^1.6.11", "electron-builder": "^10.17.3", + "electron-devtools-installer": "^2.2.0", "electron-rebuild": "^1.5.7", "eslint": "^3.16.1", "eslint-config-semistandard": "^7.0.0",