forked from shakacode/react-webpack-rails-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloggerMiddleware.js
32 lines (25 loc) · 967 Bytes
/
loggerMiddleware.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* eslint no-console: 0 */
export default function logger({ getState }) {
return (next) => (action) => {
// TODO: Replace this file with redux-logger and move this conditional to helper
// TODO: where we're setting up the included middleware.
if (process.env.NODE_ENV !== 'development') {
return next(action);
}
console.log('will dispatch', action);
// Call the next dispatch method in the middleware chain.
const result = next(action);
// We can't _read_ immutable objects in console out-of-the-box.
const state = getState();
const readableState = {};
Object.keys(state).forEach((storeItem) => {
readableState[storeItem] = (
state[storeItem].toJS ? state[storeItem].toJS() : state[storeItem]
);
});
console.log('state after dispatch', readableState);
// This will likely be the action itself, unless
// a middleware further in chain changed it.
return result;
};
}