Last active
May 5, 2021 08:21
-
-
Save stevekinney/f0009452e07db459e093086b0a8e03c2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 logEnhancer = (createStore) => (reducer, initialState, enhancer) => { | |
// Do stuff like wrap the reducer in a higher-order function. | |
const reducerWithConsoleLogs = (previousState, action) => { | |
const nextState = reducer(previousState, action); | |
console.log({ action, previousState, nextState }); | |
return nextState; | |
}; | |
return createStore(reducerWithConsoleLogs, initialState, enhancer); | |
}; |
This file contains hidden or 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 monitorMiddleware = (store) => (next) => (action) => { | |
const start = performance.now(); | |
next(action); | |
const end = performance.now(); | |
const diff = round(end - start); | |
console.log("reducer process time:", diff); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment