Skip to content

Commit

Permalink
fix: bind requestAnimationFrame and cancelAnimationFrame to window co…
Browse files Browse the repository at this point in the history
…ntext (#322)
  • Loading branch information
ph0ngp authored Nov 13, 2024
1 parent 22cafa6 commit 7850090
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ const globalObj = typeof window === 'undefined' ? global : window;
export const performanceNow =
(globalObj.performance && (() => globalObj.performance.now())) || (() => Date.now());
export const requestAnimationFrame =
globalObj.requestAnimationFrame ||
globalObj.requestAnimationFrame?.bind(globalObj) ||
((callback) => setTimeout(() => callback(performanceNow()), 1000 / 60));
export const cancelAnimationFrame = globalObj.cancelAnimationFrame || clearTimeout;
export const cancelAnimationFrame =
globalObj.cancelAnimationFrame?.bind(globalObj) || clearTimeout;

// Object.assign polyfill, because IE :/
export const _assign = function (target: any, ...overrides: any[]) {
Expand Down

0 comments on commit 7850090

Please sign in to comment.