2020-04-08 14:13:33 +05:30
|
|
|
/**
|
2020-07-28 23:09:34 +05:30
|
|
|
* Polyfill
|
|
|
|
* @what requestIdleCallback
|
|
|
|
* @why To align browser features
|
|
|
|
* @browsers Safari (all versions)
|
|
|
|
* @see https://caniuse.com/#feat=requestidlecallback
|
2020-04-08 14:13:33 +05:30
|
|
|
*/
|
2020-07-28 23:09:34 +05:30
|
|
|
window.requestIdleCallback =
|
|
|
|
window.requestIdleCallback ||
|
|
|
|
function requestShim(cb) {
|
|
|
|
const start = Date.now();
|
|
|
|
return setTimeout(() => {
|
|
|
|
cb({
|
|
|
|
didTimeout: false,
|
|
|
|
timeRemaining: () => Math.max(0, 50 - (Date.now() - start)),
|
|
|
|
});
|
|
|
|
}, 1);
|
|
|
|
};
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
window.cancelIdleCallback =
|
|
|
|
window.cancelIdleCallback ||
|
|
|
|
function cancelShim(id) {
|
|
|
|
clearTimeout(id);
|
|
|
|
};
|