forked from bazaarvoice/bv-ui-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetEntries.js
More file actions
42 lines (35 loc) · 1.13 KB
/
Copy pathgetEntries.js
File metadata and controls
42 lines (35 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* @fileOverview
* Performance.getEntries uses the native User Timing API
* when available and falls back to a manual implementation if not
*/
// Imports
var global = require('../global');
var timeline = require('./entries').timeline;
// Determine now (once) if we can use the native User Timing API
// Cache references to native implementation in case they are modified later
var performance = global.performance;
var nativeGetEntries = performance && performance.getEntries;
// Is the User Timing API natively supported?
var isNativeSupported = (typeof nativeGetEntries === 'function');
/**
* Native Implementation
* Uses the native-supported performance.getEntries function
*/
function nativeImplementation () {
return nativeGetEntries.call(performance);
}
/**
* Polyfill Implementation
* Manually provides similar functionality to native performance.getEntries
* using an in-memory array of timeline events
*/
function polyfillImplementation () {
return timeline;
}
module.exports = {
getEntries: function () {
var func = (isNativeSupported ? nativeImplementation : polyfillImplementation);
return func();
}
};