Created
May 17, 2017 17:41
-
-
Save TheBox193/634be9e66f7731de6d6c9afcd4c7647a to your computer and use it in GitHub Desktop.
Redux Middleware that tracks a history of dispatched actions for debugging.
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
const redux_log = []; | |
const errorLogMiddleware = (store) => (next) => (action) => { | |
const type = (action && action.type) || 'unknown action'; | |
if ( type === 'LOG_ERROR' ) { | |
const log_str = redux_log.join(' -> '); | |
const error_str = (action && action.payload && action.payload.error) || 'Redux Error'; | |
console.error(error_str + ': ' + log_str); | |
} else { | |
// add last action to log | |
redux_log.push(type); | |
if (redux_log.length > 10) { | |
redux_log.shift(); | |
} | |
} | |
return next(action); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment