mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-01-15 16:22:07 +05:30
Add redux dev tools (ctrl+h to show)
This commit is contained in:
parent
da6a8cc1b2
commit
54842aea9e
@ -81,6 +81,9 @@
|
|||||||
"postcss-url": "^5.1.1",
|
"postcss-url": "^5.1.1",
|
||||||
"raw-loader": "^0.5.1",
|
"raw-loader": "^0.5.1",
|
||||||
"react-addons-test-utils": "^15.0.2",
|
"react-addons-test-utils": "^15.0.2",
|
||||||
|
"redux-devtools": "^3.3.1",
|
||||||
|
"redux-devtools-dock-monitor": "^1.1.1",
|
||||||
|
"redux-devtools-log-monitor": "^1.0.11",
|
||||||
"sass-loader": "^3.1.2",
|
"sass-loader": "^3.1.2",
|
||||||
"sinon": "^1.15.3",
|
"sinon": "^1.15.3",
|
||||||
"style-loader": "^0.13.0",
|
"style-loader": "^0.13.0",
|
||||||
|
24
src/containers/DevTools.jsx
Normal file
24
src/containers/DevTools.jsx
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
// Exported from redux-devtools
|
||||||
|
import { createDevTools } from 'redux-devtools';
|
||||||
|
|
||||||
|
// Monitors are separate packages, and you can make a custom one
|
||||||
|
import LogMonitor from 'redux-devtools-log-monitor';
|
||||||
|
import DockMonitor from 'redux-devtools-dock-monitor';
|
||||||
|
|
||||||
|
// createDevTools takes a monitor and produces a DevTools component
|
||||||
|
const DevTools = createDevTools(
|
||||||
|
// Monitors are individually adjustable with props.
|
||||||
|
// Consult their repositories to learn about those props.
|
||||||
|
// Here, we put LogMonitor inside a DockMonitor.
|
||||||
|
// Note: DockMonitor is visible by default.
|
||||||
|
<DockMonitor toggleVisibilityKey="ctrl-h"
|
||||||
|
changePositionKey="ctrl-d"
|
||||||
|
defaultIsVisible={false}
|
||||||
|
>
|
||||||
|
<LogMonitor theme="tomorrow" />
|
||||||
|
</DockMonitor>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default DevTools;
|
26
src/index.js
26
src/index.js
@ -3,39 +3,20 @@ import 'polyfills';
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
|
|
||||||
import { createStore, combineReducers, applyMiddleware } from 'redux';
|
|
||||||
import { Provider as ReduxProvider } from 'react-redux';
|
import { Provider as ReduxProvider } from 'react-redux';
|
||||||
|
|
||||||
// midleware, который позволяет возвращать из экшенов функции
|
|
||||||
// это полезно для работы с асинхронными действиями,
|
|
||||||
// а также дает возможность проверить какие-либо условия перед запуском экшена
|
|
||||||
// или даже вообще его не запускать в зависимости от условий
|
|
||||||
import thunk from 'redux-thunk';
|
|
||||||
|
|
||||||
import { Router, browserHistory } from 'react-router';
|
import { Router, browserHistory } from 'react-router';
|
||||||
import { syncHistory, routeReducer } from 'react-router-redux';
|
|
||||||
|
|
||||||
import { factory as userFactory } from 'components/user/factory';
|
import { factory as userFactory } from 'components/user/factory';
|
||||||
import { IntlProvider } from 'components/i18n';
|
import { IntlProvider } from 'components/i18n';
|
||||||
import reducers from 'reducers';
|
|
||||||
import routesFactory from 'routes';
|
import routesFactory from 'routes';
|
||||||
|
import storeFactory from 'storeFactory';
|
||||||
|
|
||||||
const reducer = combineReducers({
|
const store = storeFactory();
|
||||||
...reducers,
|
|
||||||
routing: routeReducer
|
|
||||||
});
|
|
||||||
|
|
||||||
const reduxRouterMiddleware = syncHistory(browserHistory);
|
|
||||||
|
|
||||||
const store = applyMiddleware(
|
|
||||||
reduxRouterMiddleware,
|
|
||||||
thunk
|
|
||||||
)(createStore)(reducer);
|
|
||||||
|
|
||||||
userFactory(store)
|
userFactory(store)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// allow :active styles in mobile Safary
|
// allow :active styles in mobile Safary
|
||||||
document.addEventListener("touchstart", () => {}, true);
|
document.addEventListener('touchstart', () => {}, true);
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<ReduxProvider store={store}>
|
<ReduxProvider store={store}>
|
||||||
@ -50,7 +31,6 @@ userFactory(store)
|
|||||||
</ReduxProvider>,
|
</ReduxProvider>,
|
||||||
document.getElementById('app')
|
document.getElementById('app')
|
||||||
);
|
);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
import scrollTo from 'components/ui/scrollTo';
|
import scrollTo from 'components/ui/scrollTo';
|
||||||
|
@ -6,6 +6,7 @@ import classNames from 'classnames';
|
|||||||
|
|
||||||
import Userbar from 'components/userbar/Userbar';
|
import Userbar from 'components/userbar/Userbar';
|
||||||
import PopupStack from 'components/ui/popup/PopupStack';
|
import PopupStack from 'components/ui/popup/PopupStack';
|
||||||
|
import DevTools from 'containers/DevTools';
|
||||||
|
|
||||||
import styles from './root.scss';
|
import styles from './root.scss';
|
||||||
|
|
||||||
@ -14,6 +15,7 @@ import messages from './RootPage.intl.json';
|
|||||||
function RootPage(props) {
|
function RootPage(props) {
|
||||||
const isRegisterPage = props.location.pathname === '/register';
|
const isRegisterPage = props.location.pathname === '/register';
|
||||||
|
|
||||||
|
/* global process: false */
|
||||||
return (
|
return (
|
||||||
<div className={styles.root}>
|
<div className={styles.root}>
|
||||||
<div id="view-port" className={classNames(styles.viewPort, {
|
<div id="view-port" className={classNames(styles.viewPort, {
|
||||||
@ -37,6 +39,7 @@ function RootPage(props) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<PopupStack />
|
<PopupStack />
|
||||||
|
{process.env.NODE_ENV === 'production' ? null : <DevTools /> }
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
|
import { combineReducers } from 'redux';
|
||||||
|
|
||||||
|
import { routeReducer } from 'react-router-redux';
|
||||||
|
|
||||||
import auth from 'components/auth/reducer';
|
import auth from 'components/auth/reducer';
|
||||||
import user from 'components/user/reducer';
|
import user from 'components/user/reducer';
|
||||||
import i18n from 'components/i18n/reducer';
|
import i18n from 'components/i18n/reducer';
|
||||||
import popup from 'components/ui/popup/reducer';
|
import popup from 'components/ui/popup/reducer';
|
||||||
|
|
||||||
export default {
|
export default combineReducers({
|
||||||
auth,
|
auth,
|
||||||
user,
|
user,
|
||||||
i18n,
|
i18n,
|
||||||
popup
|
popup,
|
||||||
};
|
routing: routeReducer
|
||||||
|
});
|
||||||
|
38
src/storeFactory.js
Normal file
38
src/storeFactory.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import { createStore, applyMiddleware, compose } from 'redux';
|
||||||
|
// midleware, который позволяет возвращать из экшенов функции
|
||||||
|
// это полезно для работы с асинхронными действиями,
|
||||||
|
// а также дает возможность проверить какие-либо условия перед запуском экшена
|
||||||
|
// или даже вообще его не запускать в зависимости от условий
|
||||||
|
import thunk from 'redux-thunk';
|
||||||
|
import { syncHistory } from 'react-router-redux';
|
||||||
|
import { browserHistory } from 'react-router';
|
||||||
|
|
||||||
|
import reducers from 'reducers';
|
||||||
|
import DevTools from 'containers/DevTools';
|
||||||
|
|
||||||
|
export default function storeFactory() {
|
||||||
|
const reduxRouterMiddleware = syncHistory(browserHistory);
|
||||||
|
const middlewares = applyMiddleware(
|
||||||
|
reduxRouterMiddleware,
|
||||||
|
thunk
|
||||||
|
);
|
||||||
|
|
||||||
|
/* global process: false */
|
||||||
|
let enhancer;
|
||||||
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
enhancer = compose(middlewares);
|
||||||
|
} else {
|
||||||
|
enhancer = compose(middlewares, DevTools.instrument());
|
||||||
|
}
|
||||||
|
|
||||||
|
const store = createStore(reducers, {}, enhancer);
|
||||||
|
|
||||||
|
// Hot reload reducers
|
||||||
|
if (module.hot) {
|
||||||
|
module.hot.accept('reducers', () =>
|
||||||
|
store.replaceReducer(require('reducers').default)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return store;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user