main-thread-scheduling
Advanced tools
Comparing version 4.0.0-0 to 4.0.0-1
{ | ||
"name": "main-thread-scheduling", | ||
"version": "4.0.0-0", | ||
"version": "4.0.0-1", | ||
"description": "Consistently responsive apps while staying on the main thread", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -0,22 +1,39 @@ | ||
import nextTask from './nextTask'; | ||
// #hack | ||
let shouldRequestAnimationFrame = false; | ||
const idlePhaseTracker = createPhaseTracker((callback) => { | ||
if (typeof requestIdleCallback === 'undefined') { | ||
return; | ||
} | ||
const handleIdleCallback = () => { | ||
requestIdleCallback((deadline) => { | ||
shouldRequestAnimationFrame = true; | ||
callback({ | ||
deadline, | ||
start: Date.now(), | ||
if (typeof requestIdleCallback === 'undefined') { | ||
nextTask(() => { | ||
shouldRequestAnimationFrame = true; | ||
const start = Date.now(); | ||
const deadline = start + 16; | ||
callback({ | ||
start: start, | ||
deadline: { | ||
timeRemaining() { | ||
return Math.max(deadline - Date.now(), 0); | ||
}, | ||
didTimeout: false, | ||
}, | ||
}); | ||
shouldRequestAnimationFrame = false; | ||
}); | ||
shouldRequestAnimationFrame = false; | ||
}, { | ||
// #WET 2021-06-05T3:07:18+03:00 | ||
// #connection 2021-06-05T3:07:18+03:00 | ||
// call at least once per frame | ||
// asuming 60 fps, 1000/60 = 16.667 | ||
timeout: 16, | ||
}); | ||
} | ||
else { | ||
requestIdleCallback((deadline) => { | ||
shouldRequestAnimationFrame = true; | ||
callback({ | ||
deadline, | ||
start: Date.now(), | ||
}); | ||
shouldRequestAnimationFrame = false; | ||
}, { | ||
// #WET 2021-06-05T3:07:18+03:00 | ||
// #connection 2021-06-05T3:07:18+03:00 | ||
// call at least once per frame | ||
// asuming 60 fps, 1000/60 = 16.667 | ||
timeout: 16, | ||
}); | ||
} | ||
}; | ||
@@ -23,0 +40,0 @@ if (shouldRequestAnimationFrame) { |
26936
444