Skip to content

Instantly share code, notes, and snippets.

@vcarl
Forked from clarkbw/redux-performance-mark.js
Last active February 8, 2024 05:05
Show Gist options
  • Save vcarl/9f5f38cd3f0666086c7e67674613962e to your computer and use it in GitHub Desktop.
Save vcarl/9f5f38cd3f0666086c7e67674613962e to your computer and use it in GitHub Desktop.
A User Timing middleware for redux to create performance markers for dispatched actions
const userTiming = () => (next) => (action) => {
if (performance.mark === undefined) return next(action);
performance.mark(`${action.type}_start`);
const result = next(action);
performance.mark(`${action.type}_end`);
performance.measure(
`${action.type}`,
`${action.type}_start`,
`${action.type}_end`,
);
return result;
}
@Harrisonkamau
Copy link

Nice one @vcarl!
I wrote a similar blog a while back:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment