@cloudcare/browser-core 3.2.3 → 3.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/helper/requestIdleCallback.js +46 -0
- package/cjs/helper/requestIdleCallback.js.map +1 -0
- package/cjs/helper/taskQueue.js +59 -0
- package/cjs/helper/taskQueue.js.map +1 -0
- package/cjs/helper/tools.js +1 -1
- package/cjs/helper/tools.js.map +1 -1
- package/cjs/index.js +22 -0
- package/cjs/index.js.map +1 -1
- package/esm/helper/requestIdleCallback.js +38 -0
- package/esm/helper/requestIdleCallback.js.map +1 -0
- package/esm/helper/taskQueue.js +52 -0
- package/esm/helper/taskQueue.js.map +1 -0
- package/esm/helper/tools.js +1 -1
- package/esm/helper/tools.js.map +1 -1
- package/esm/index.js +2 -0
- package/esm/index.js.map +1 -1
- package/package.json +2 -2
- package/src/helper/requestIdleCallback.js +38 -0
- package/src/helper/taskQueue.js +55 -0
- package/src/helper/tools.js +6 -1
- package/src/index.js +2 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { setTimeout, clearTimeout } from './timer'
|
|
2
|
+
import { monitor } from './monitor'
|
|
3
|
+
import { dateNow } from './tools'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 'requestIdleCallback' with a shim.
|
|
7
|
+
*/
|
|
8
|
+
export function requestIdleCallback(callback, opts) {
|
|
9
|
+
// Note: check both 'requestIdleCallback' and 'cancelIdleCallback' existence because some polyfills only implement 'requestIdleCallback'.
|
|
10
|
+
if (window.requestIdleCallback && window.cancelIdleCallback) {
|
|
11
|
+
const id = window.requestIdleCallback(monitor(callback), opts)
|
|
12
|
+
return function () {
|
|
13
|
+
return window.cancelIdleCallback(id)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return requestIdleCallbackShim(callback)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const MAX_TASK_TIME = 50
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* Shim from https://developer.chrome.com/blog/using-requestidlecallback#checking_for_requestidlecallback
|
|
23
|
+
* Note: there is no simple way to support the "timeout" option, so we ignore it.
|
|
24
|
+
*/
|
|
25
|
+
export function requestIdleCallbackShim(callback) {
|
|
26
|
+
const start = dateNow()
|
|
27
|
+
const timeoutId = setTimeout(function () {
|
|
28
|
+
callback({
|
|
29
|
+
didTimeout: false,
|
|
30
|
+
timeRemaining: function () {
|
|
31
|
+
return Math.max(0, MAX_TASK_TIME - (dateNow() - start))
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
}, 0)
|
|
35
|
+
return function () {
|
|
36
|
+
return clearTimeout(timeoutId)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ONE_SECOND } from './tools'
|
|
2
|
+
import { requestIdleCallback } from './requestIdleCallback'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Maximum delay before starting to execute tasks in the queue. We don't want to wait too long
|
|
6
|
+
* before running tasks, as it might hurt reliability (ex: if the user navigates away, we might lose
|
|
7
|
+
* the opportunity to send some data). We also don't want to run tasks too often, as it might hurt
|
|
8
|
+
* performance.
|
|
9
|
+
*/
|
|
10
|
+
const IDLE_CALLBACK_TIMEOUT = ONE_SECOND
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Maximum amount of time allocated to running tasks when a timeout (`IDLE_CALLBACK_TIMEOUT`) is
|
|
14
|
+
* reached. We should not run tasks for too long as it will hurt performance, but we should still
|
|
15
|
+
* run some tasks to avoid postponing them forever.
|
|
16
|
+
*
|
|
17
|
+
* Rational: Running tasks for 30ms every second (IDLE_CALLBACK_TIMEOUT) should be acceptable.
|
|
18
|
+
*/
|
|
19
|
+
export const MAX_EXECUTION_TIME_ON_TIMEOUT = 30
|
|
20
|
+
|
|
21
|
+
export function createTaskQueue() {
|
|
22
|
+
const pendingTasks = []
|
|
23
|
+
|
|
24
|
+
function run(deadline) {
|
|
25
|
+
let executionTimeRemaining
|
|
26
|
+
if (deadline.didTimeout) {
|
|
27
|
+
const start = performance.now()
|
|
28
|
+
executionTimeRemaining = function () {
|
|
29
|
+
return MAX_EXECUTION_TIME_ON_TIMEOUT - (performance.now() - start)
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
executionTimeRemaining = deadline.timeRemaining.bind(deadline)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
while (executionTimeRemaining() > 0 && pendingTasks.length) {
|
|
36
|
+
pendingTasks.shift()()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (pendingTasks.length) {
|
|
40
|
+
scheduleNextRun()
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function scheduleNextRun() {
|
|
45
|
+
requestIdleCallback(run, { timeout: IDLE_CALLBACK_TIMEOUT })
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
push(task) {
|
|
50
|
+
if (pendingTasks.push(task) === 1) {
|
|
51
|
+
scheduleNextRun()
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
package/src/helper/tools.js
CHANGED
|
@@ -1553,7 +1553,12 @@ export function findByPath(source, path) {
|
|
|
1553
1553
|
var pathArr = path.split('.')
|
|
1554
1554
|
while (pathArr.length) {
|
|
1555
1555
|
var key = pathArr.shift()
|
|
1556
|
-
if (
|
|
1556
|
+
if (
|
|
1557
|
+
source &&
|
|
1558
|
+
isObject(source) &&
|
|
1559
|
+
key in source &&
|
|
1560
|
+
hasOwnProperty.call(source, key)
|
|
1561
|
+
) {
|
|
1557
1562
|
source = source[key]
|
|
1558
1563
|
} else {
|
|
1559
1564
|
return undefined
|
package/src/index.js
CHANGED
|
@@ -22,6 +22,8 @@ export * from './helper/mobileUtil'
|
|
|
22
22
|
export * from './helper/getZoneJsOriginalValue'
|
|
23
23
|
export * from './helper/timer'
|
|
24
24
|
export * from './helper/readBytesFromStream'
|
|
25
|
+
export * from './helper/requestIdleCallback'
|
|
26
|
+
export * from './helper/taskQueue'
|
|
25
27
|
export * from './tracekit'
|
|
26
28
|
export * from './configuration/configuration'
|
|
27
29
|
export * from './configuration/transportConfiguration'
|