UNPKG

redux-user-timing

Version:
30 lines (26 loc) 682 B
const middleware = () => next => action => { if (!performance || !performance.mark) { return next(action); } if ( typeof action !== 'object' || !action.type || typeof action.type !== 'string' ) { // eslint-disable-next-line no-console console.error( 'Warning: action type is not valid. Performance measurement is not working properly.', ); 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; }; export default middleware;