Skip to content

Commit

Permalink
fix: requestAnimationFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
load1n9 committed Jan 24, 2024
1 parent 1a98364 commit c3bef22
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

"lint": {
"rules": {
"exclude": ["no-unused-vars"]
"exclude": ["no-unused-vars", "no-window"]
}
}
}
18 changes: 18 additions & 0 deletions src/core/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,24 @@ export class WindowDropEvent extends WindowEvent {
export type AnimationFrameCallback = (time: number) => unknown;
export const animationFrames = new Map<number, AnimationFrameCallback>();

let animationFrameId = 0;

export function _requestAnimationFrameImpl(callback: AnimationFrameCallback) {
animationFrameId++;
animationFrames.set(animationFrameId, callback);
return animationFrameId;
}

export function _cancelAnimationFrameImpl(id: number) {
animationFrames.delete(id);
}

// deno-lint-ignore no-window
Object.assign(window, {
requestAnimationFrame: _requestAnimationFrameImpl,
cancelAnimationFrame: _cancelAnimationFrameImpl,
});

declare global {
interface WindowEventMap {
close: WindowCloseEvent;
Expand Down

0 comments on commit c3bef22

Please sign in to comment.