Skip to content

Commit 137fc96

Browse files
committed
Simplify requestAnimationFrame polyfill
1 parent 044e714 commit 137fc96

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

src/util.js

+6-26
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,11 @@ export function filterNullChildren(children) {
1414
return children && children.filter(i => i !== null);
1515
}
1616

17-
export const requestAnimationFrame = (() => {
18-
let raf;
19-
20-
if (typeof window !== 'undefined') {
21-
raf = window.requestAnimationFrame;
22-
const prefixes = ['ms', 'moz', 'webkit', 'o'];
23-
for (let i = 0; i < prefixes.length; i++) {
24-
if (raf) break;
25-
raf = window[`${prefixes[i]}RequestAnimationFrame}`];
26-
}
17+
export const requestAnimationFrame = (callback) => {
18+
if (typeof window !== 'undefined' && window.requestAnimationFrame) {
19+
window.requestAnimationFrame(callback);
2720
}
28-
29-
if (!raf) {
30-
let timeLast = 0;
31-
raf = (callback) => {
32-
const timeCurrent = new Date().getTime();
33-
34-
/* Dynamically set the delay on a per-tick basis to more closely match 60fps. */
35-
/* Technique by Erik Moller. MIT license: https://gist.github.com/paulirish/1579671. */
36-
const timeDelta = Math.max(0, 16 - (timeCurrent - timeLast));
37-
timeLast = timeCurrent + timeDelta;
38-
39-
return setTimeout(() => { callback(timeCurrent + timeDelta); }, timeDelta);
40-
};
21+
else {
22+
setTimeout(callback, 17);
4123
}
42-
43-
return raf;
44-
})();
24+
};

0 commit comments

Comments
 (0)