timing.js (841B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ 4 5 /** 6 * Redux middleware that sets performance markers for all actions such that they 7 * will appear in performance tooling under the User Timing API 8 */ 9 10 const mark = window.performance?.mark 11 ? window.performance.mark.bind(window.performance) 12 : () => {}; 13 14 const measure = window.performance?.measure 15 ? window.performance.measure.bind(window.performance) 16 : () => {}; 17 18 export function timing() { 19 return next => action => { 20 mark(`${action.type}_start`); 21 const result = next(action); 22 mark(`${action.type}_end`); 23 measure(`${action.type}`, `${action.type}_start`, `${action.type}_end`); 24 return result; 25 }; 26 }