UNPKG

@grafana/faro-web-sdk

Version:

Faro instrumentations, metas, transports for web.

35 lines 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.monitorPerformanceEntries = monitorPerformanceEntries; exports.__resetPerformanceEntriesMonitorForTests = __resetPerformanceEntriesMonitorForTests; var faro_core_1 = require("@grafana/faro-core"); var instrumentation_1 = require("../../performance/instrumentation"); var performanceConstants_1 = require("../../performance/performanceConstants"); var const_1 = require("./const"); var performanceObservable; var isSubscribed = false; var subscription; function monitorPerformanceEntries() { if (!performanceObservable) { performanceObservable = new faro_core_1.Observable(); } if (!isSubscribed) { subscription = instrumentation_1.performanceEntriesSubscription.subscribe(function (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