Skip to content

Commit bf2baaa

Browse files
committed
fix: raf
1 parent ff1f1e0 commit bf2baaa

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/utils/Raf.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
var now = require('performance-now'),
2-
root = typeof window === 'undefined' ? global : window,
1+
import now from 'performance-now'
2+
3+
var root = typeof window === 'undefined' ? global : window,
34
vendors = ['moz', 'webkit'],
45
suffix = 'AnimationFrame',
56
raf = root['request' + suffix],
@@ -19,12 +20,12 @@ if (!raf || !caf) {
1920
queue = [],
2021
frameDuration = 1000 / 60
2122

22-
raf = function(callback) {
23+
raf = function (callback) {
2324
if (queue.length === 0) {
2425
var _now = now(),
2526
next = Math.max(0, frameDuration - (_now - last))
2627
last = next + _now
27-
setTimeout(function() {
28+
setTimeout(function () {
2829
var cp = queue.slice(0)
2930
// Clear queue here to prevent
3031
// callbacks from appending listeners
@@ -35,7 +36,7 @@ if (!raf || !caf) {
3536
try {
3637
cp[i].callback(last)
3738
} catch (e) {
38-
setTimeout(function() {
39+
setTimeout(function () {
3940
throw e
4041
}, 0)
4142
}
@@ -51,7 +52,7 @@ if (!raf || !caf) {
5152
return id
5253
}
5354

54-
caf = function(handle) {
55+
caf = function (handle) {
5556
for (var i = 0; i < queue.length; i++) {
5657
if (queue[i].handle === handle) {
5758
queue[i].cancelled = true
@@ -67,11 +68,11 @@ export default function Raf(fn) {
6768
return raf.call(root, fn)
6869
}
6970

70-
Raf.cancel = function() {
71+
Raf.cancel = function () {
7172
caf.apply(root, arguments)
7273
}
7374

74-
Raf.polyfill = function(object) {
75+
Raf.polyfill = function (object) {
7576
if (!object) {
7677
object = root
7778
}

0 commit comments

Comments
 (0)