-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
16 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
import { createStore, applyMiddleware } from 'redux'; | ||
/* eslint no-console: 0 */ | ||
|
||
function logger({ getState }) { | ||
return (next) => (action) => { | ||
export default function logger({ getState }) { | ||
return next => action => { | ||
console.log('will dispatch', action); | ||
|
||
// Call the next dispatch method in the middleware chain. | ||
let returnValue = next(action); | ||
const result = next(action); | ||
|
||
console.log('state after dispatch', getState()); | ||
// We can't _read_ immutable objects in console out-of-the-box. | ||
const immutableState = getState(); | ||
const readableState = {}; | ||
for (const storeItem in immutableState) { | ||
if (immutableState.hasOwnProperty(storeItem)) { | ||
readableState[storeItem] = immutableState[storeItem].toJS(); | ||
} | ||
} | ||
console.log('state after dispatch', readableState); | ||
|
||
// This will likely be the action itself, unless | ||
// a middleware further in chain changed it. | ||
return returnValue; | ||
return result; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
import { createStore, applyMiddleware, combineReducers } from 'redux'; | ||
import thunk from 'redux-thunk'; | ||
import reducers from '../reducers'; | ||
|
||
// Smth wrong with this one, off for now | ||
// import loggerMiddleware from '../middleware/loggerMiddleware'; | ||
import loggerMiddleware from '../middleware/loggerMiddleware'; | ||
|
||
// applyMiddleware supercharges createStore with middleware: | ||
const createStoreWithMiddleware = applyMiddleware(thunk)(createStore); | ||
const createStoreWithMiddleware = applyMiddleware(thunk, loggerMiddleware)(createStore); | ||
export default createStoreWithMiddleware(combineReducers(reducers)); |