Skip to content

Commit a414ab0

Browse files
committed
fix: fallback raf to setTimeout
1 parent a78fe11 commit a414ab0

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/utils.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1-
export /* istanbul ignore next */ var raf = typeof window !== 'undefined' ?
2-
(
3-
(
1+
export /* istanbul ignore next */ var raf = (function() {
2+
if (typeof window !== 'undefined') {
3+
var rAF = (
44
window.requestAnimationFrame ||
55
window.mozRequestAnimationFrame ||
66
window.webkitRequestAnimationFrame
7-
) ||
8-
function(cb) {
9-
return setTimeout(cb, 50 / 3);
10-
}
11-
).bind(window)
12-
: () => {};
7+
);
8+
if (rAF) return rAF.bind(window);
9+
}
10+
return function(cb) {
11+
return setTimeout(cb, 50 / 3);
12+
};
13+
})();
1314

14-
export /* istanbul ignore next */ var caf = typeof window !== 'undefined' ?
15-
(
16-
(
15+
export /* istanbul ignore next */ var caf = (function() {
16+
if (typeof window !== 'undefined') {
17+
var cAF = (
1718
window.cancelAnimationFrame ||
1819
window.mozCancelAnimationFrame ||
1920
window.webkitCancelAnimationFrame
20-
) ||
21-
clearTimeout
22-
).bind(window)
23-
: () => {};
21+
);
22+
if (cAF) return cAF.bind(window);
23+
}
24+
return clearTimeout;
25+
})();
2426

2527
export function binsearch(arr, prop, key) {
2628
var mid = 0;

0 commit comments

Comments
 (0)