mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-24 05:03:06 +00:00
28 lines
719 B
JavaScript
28 lines
719 B
JavaScript
const requestIdleCallback =
|
|
(typeof self !== 'undefined' &&
|
|
self.requestIdleCallback &&
|
|
self.requestIdleCallback.bind(window)) ||
|
|
function (cb) {
|
|
const start = Date.now();
|
|
return setTimeout(() => {
|
|
cb({
|
|
didTimeout: false,
|
|
timeRemaining: function () {
|
|
return Math.max(0, 50 - (Date.now() - start));
|
|
},
|
|
});
|
|
}, 1);
|
|
};
|
|
|
|
const cancelIdleCallback =
|
|
(typeof self !== 'undefined' &&
|
|
self.cancelIdleCallback &&
|
|
self.cancelIdleCallback.bind(window)) ||
|
|
function (id) {
|
|
return clearTimeout(id);
|
|
};
|
|
|
|
if (typeof window !== 'undefined') {
|
|
window.requestIdleCallback = requestIdleCallback;
|
|
window.cancelIdleCallback = cancelIdleCallback;
|
|
}
|