reactotron-core-client
Version:
Grants Reactotron clients the ability to talk to a Reactotron server.
44 lines (37 loc) • 1.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.start = void 0;
/// <reference types="node" />
const hasHirezNodeTimer = false && typeof process === "object" && process && process.hrtime && typeof process.hrtime === "function";
// the default timer
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const defaultPerformanceNow = started => Date.now();
// try to find the browser-based performance timer
const nativePerformance = typeof window !== "undefined" && window && (window.performance || window.msPerformance || window.webkitPerformance);
// the function we're trying to assign
let performanceNow = defaultPerformanceNow;
// accepts an already started time and returns the number of milliseconds
let delta = started => performanceNow() - started;
if (hasHirezNodeTimer) {
performanceNow = process.hrtime;
delta = started => performanceNow(started)[1] / 1000000;
} else if (global.nativePerformanceNow) {
// react native 47
performanceNow = global.nativePerformanceNow;
} else if (nativePerformance) {
// browsers + safely check for react native < 47
performanceNow = () => nativePerformance.now && nativePerformance.now();
}
/**
* Starts a lame, low-res timer. Returns a function which when invoked,
* gives you the number of milliseconds since passing. ish.
*/
const start = () => {
// record the start time
const started = performanceNow();
return () => delta(started);
};
exports.start = start;
//# sourceMappingURL=stopwatch.js.map