Skip to content

Commit c3bef22

Browse files
committed
fix: requestAnimationFrame
1 parent 1a98364 commit c3bef22

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

deno.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
"lint": {
2525
"rules": {
26-
"exclude": ["no-unused-vars"]
26+
"exclude": ["no-unused-vars", "no-window"]
2727
}
2828
}
2929
}

src/core/event.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,24 @@ export class WindowDropEvent extends WindowEvent {
244244
export type AnimationFrameCallback = (time: number) => unknown;
245245
export const animationFrames = new Map<number, AnimationFrameCallback>();
246246

247+
let animationFrameId = 0;
248+
249+
export function _requestAnimationFrameImpl(callback: AnimationFrameCallback) {
250+
animationFrameId++;
251+
animationFrames.set(animationFrameId, callback);
252+
return animationFrameId;
253+
}
254+
255+
export function _cancelAnimationFrameImpl(id: number) {
256+
animationFrames.delete(id);
257+
}
258+
259+
// deno-lint-ignore no-window
260+
Object.assign(window, {
261+
requestAnimationFrame: _requestAnimationFrameImpl,
262+
cancelAnimationFrame: _cancelAnimationFrameImpl,
263+
});
264+
247265
declare global {
248266
interface WindowEventMap {
249267
close: WindowCloseEvent;

0 commit comments

Comments
 (0)