Skip to content

Instantly share code, notes, and snippets.

@stevekinney
Last active May 5, 2021 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevekinney/f0009452e07db459e093086b0a8e03c2 to your computer and use it in GitHub Desktop.
Save stevekinney/f0009452e07db459e093086b0a8e03c2 to your computer and use it in GitHub Desktop.
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);
};
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