1 | /**
|
2 | * Logs action type, payload, and result state to the browser console.
|
3 | * @param {*} reducer a reducing function to wrap with logging
|
4 | * @returns {Function} a wrapped reducer function
|
5 | */
|
6 | const withLogger = reducer => (state, action) => {
|
7 | const result = reducer(state, action);
|
8 |
|
9 | console.groupCollapsed(action.type);
|
10 | console.group('payload');
|
11 | console.log(action.payload);
|
12 | console.groupEnd();
|
13 | console.group('next state');
|
14 | console.log(result);
|
15 | console.groupEnd();
|
16 | console.groupEnd();
|
17 |
|
18 | return result;
|
19 | };
|
20 |
|
21 | export default withLogger;
|