Skip to content

Commit

Permalink
chore(wait): Update polyfill.ts with type annotations and prettier-ig…
Browse files Browse the repository at this point in the history
…nore
  • Loading branch information
alimd committed Jan 3, 2024
1 parent 75e40f9 commit 572eabb
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/wait/src/polyfill.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import {globalScope} from '@alwatr/global-scope';

import type {Dictionary} from '@alwatr/type-helper';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const win = globalScope as Record<string, any>;
export const win = globalScope as Dictionary<any>;

const requestAnimationFrameFallback = (callback: FrameRequestCallback): ReturnType<typeof setTimeout> =>
setTimeout(() => callback(Date.now()), 1000 / 60);
// prettier-ignore
const requestAnimationFrameFallback =
(callback: FrameRequestCallback): ReturnType<typeof setTimeout> =>
setTimeout(() => callback(Date.now()), 1000 / 60);

// prettier-ignore
export const requestAnimationFrame: typeof globalScope.requestAnimationFrame =
win.requestAnimationFrame ||
win.webkitRequestAnimationFrame ||
win.mozRequestAnimationFrame ||
requestAnimationFrameFallback;

const requestIdleCallbackFallback = (callback: () => void, options?: IdleRequestOptions): ReturnType<typeof setTimeout> =>
setTimeout(callback, options?.timeout ?? 2000);
// prettier-ignore
const requestIdleCallbackFallback =
(callback: () => void, options?: IdleRequestOptions): ReturnType<typeof setTimeout> =>
setTimeout(callback, options?.timeout ?? 2000);

// prettier-ignore
export const requestIdleCallback: typeof globalScope.requestIdleCallback =
win.requestIdleCallback ||
win.webkitRequestIdleCallback ||
Expand Down

0 comments on commit 572eabb

Please sign in to comment.