@grafana/faro-web-sdk
Version:
Faro instrumentations, metas, transports for web.
35 lines • 1.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.monitorPerformanceEntries = monitorPerformanceEntries;
exports.__resetPerformanceEntriesMonitorForTests = __resetPerformanceEntriesMonitorForTests;
const faro_core_1 = require("@grafana/faro-core");
const instrumentation_1 = require("../../performance/instrumentation");
const performanceConstants_1 = require("../../performance/performanceConstants");
const const_1 = require("./const");
let performanceObservable;
let isSubscribed = false;
let subscription;
function monitorPerformanceEntries() {
if (!performanceObservable) {
performanceObservable = new faro_core_1.Observable();
}
if (!isSubscribed) {
subscription = instrumentation_1.performanceEntriesSubscription.subscribe((data) => {
if (data.type === performanceConstants_1.RESOURCE_ENTRY) {
performanceObservable.notify({ type: const_1.MESSAGE_TYPE_RESOURCE_ENTRY });
}
});
isSubscribed = true;
}
return performanceObservable;
}
// Test-only utility to reset state between tests
function __resetPerformanceEntriesMonitorForTests() {
if (subscription) {
subscription.unsubscribe();
}
subscription = undefined;
isSubscribed = false;
performanceObservable = undefined;
}
//# sourceMappingURL=performanceEntriesMonitor.js.map