Skip to content

Commit ca4c94b

Browse files
committed
wip
1 parent 95f129a commit ca4c94b

21 files changed

+61391
-41732
lines changed

app/assets/bundle/app/DevTools.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
3+
// Exported from redux-devtools
4+
import { createDevTools } from 'redux-devtools';
5+
6+
// Monitors are separate packages, and you can make a custom one
7+
import LogMonitor from 'redux-devtools-log-monitor';
8+
import DockMonitor from 'redux-devtools-dock-monitor';
9+
10+
// createDevTools takes a monitor and produces a DevTools component
11+
const DevTools = createDevTools(
12+
// Monitors are individually adjustable with props.
13+
// Consult their repositories to learn about those props.
14+
// Here, we put LogMonitor inside a DockMonitor.
15+
// Note: DockMonitor is visible by default.
16+
<DockMonitor toggleVisibilityKey='ctrl-h'
17+
changePositionKey='ctrl-q'
18+
defaultIsVisible={true}>
19+
<LogMonitor theme='tomorrow' />
20+
</DockMonitor>
21+
);
22+
23+
export default DevTools;

app/assets/bundle/app/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import history from './history';
2727
import i18next from 'i18next';
2828
import XHR from 'i18next-xhr-backend';
2929
import LngDetector from 'i18next-browser-languagedetector';
30-
3130
import App from './App';
31+
import DevTools from './DevTools';
3232
// Build the middleware for intercepting and dispatching navigation actions
3333

3434
const Provider = ReactRedux.Provider;
@@ -51,6 +51,7 @@ class CRM extends React.Component {
5151
<JssProvider generateClassName={createGenerateClassName()}>
5252
<MuiThemeProvider theme={MuiTheme}>
5353
<App history={history} store={store} />
54+
<DevTools />
5455
</MuiThemeProvider>
5556
</JssProvider>
5657
</ConnectedRouter>

app/assets/bundle/app/reducers.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,18 @@ export {
3434
// import {ApiTableReducer} from './ApiTable/reducers';
3535

3636
export default function createReducer(asyncReducers = {}) {
37+
console.log('createReducer', asyncReducers);
3738
const reducers = {
3839
router: routerReducer,
3940
// apiTable: ApiTableReducer,
4041
LoadedModules,
4142
form,
43+
bar: (state={}, ...args) => {
44+
console.log('bar', state, args);
45+
return state;
46+
},
4247
...asyncReducers
4348
};
44-
console.log('!reducers', reducers);
45-
return combineReducers(reducers, {});
49+
console.log(reducers);
50+
return combineReducers(reducers);
4651
}

app/assets/bundle/app/store.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,39 @@
1-
import { createStore, applyMiddleware } from 'redux';
1+
import { createStore, applyMiddleware, compose } from 'redux';
22
import createReducer from './reducers';
33
import ReduxThunk from 'redux-thunk';
44
import {composeWithDevTools} from 'redux-devtools-extension';
55
import { connectRouter, routerMiddleware } from 'connected-react-router';
66
import history from './history';
7+
import DevTools from './DevTools';
8+
79

810
const ReactRouterMiddleware = routerMiddleware(history);
911
const composeEnhancers = composeWithDevTools({
1012
// options like actionSanitizer, stateSanitizer
1113
});
1214

13-
export default function configureStore(initialState = {}) {
15+
export const loggerMiddleware = store => next => action => {
16+
console.group(action.type); // eslint-disable-line no-console
17+
console.info('dispatching', action); // eslint-disable-line no-console
18+
const result = next(action);
19+
// OMIT toJS if you're not using immutable
20+
console.log('next state', store.getState()); // eslint-disable-line no-console
21+
console.groupEnd(action.type); // eslint-disable-line no-console
22+
return result;
23+
};
1424

25+
const monitorReducer = (state = {}, action) => state;
1526

27+
export default function configureStore(initialState = {}) {
1628
const store = createStore(
1729
connectRouter(history)(createReducer()),
1830
initialState,
19-
composeEnhancers(
31+
compose(
2032
applyMiddleware(ReactRouterMiddleware),
2133
applyMiddleware(ReduxThunk),
22-
// applyMiddleware(logger),
34+
applyMiddleware(loggerMiddleware),
35+
DevTools.instrument(),
36+
// instrument(monitorReducer, { maxAge: 50 })
2337
)
2438
);
2539
store.asyncReducers = {};
@@ -29,8 +43,7 @@ export default function configureStore(initialState = {}) {
2943
export function injectAsyncReducer(store, name, asyncReducer) {
3044

3145
store.asyncReducers[name] = asyncReducer;
32-
const reducers = createReducer(store.asyncReducers);
33-
console.log('reducers', reducers);
46+
const reducers = connectRouter(history)(createReducer(store.asyncReducers));
3447
store.replaceReducer(reducers);
3548

3649
}

app/assets/bundle/dist-dev/app.bundle.js

+92-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/assets/bundle/dist-dev/app.bundle.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)