UNPKG

@nent/core

Version:

Functional elements to add routing, data-binding, dynamic HTML, declarative actions, audio, video, and so much more. Supercharge static HTML files into web apps without script or builds.

39 lines (38 loc) 929 B
/*! * NENT 2022 */ /* istanbul ignore file */ export class RequestAnimationFrameMockSession { constructor() { this.handleCounter = 0; this.time = new Date().getTime(); this.handleCounter = 0; this.queue = new Map(); } requestAnimationFrame(callback) { const handle = this.handleCounter++; this.queue.set(handle, callback); return handle; } cancelAnimationFrame(handle) { this.queue.delete(handle); } triggerNextAnimationFrame(time) { this.time = time; const nextEntry = this.queue.entries().next().value; if (nextEntry === undefined) return; const [nextHandle, nextCallback] = nextEntry; nextCallback(time); this.queue.delete(nextHandle); } triggerAllAnimationFrames(time) { this.time = time; while (this.queue.size > 0) this.triggerNextAnimationFrame(time); } reset() { this.queue.clear(); this.handleCounter = 0; } }