mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-21 06:45:09 +01:00
ee3f408c7d
* feat: impl IdleRender * test: pin time on Chromatic * test: pin time on Chromatic * fix: typo * style: rename * style: rename * chore: back to setTimeout * style: linebreak * refactor: remove unused budget option * refactor: use raw unix time * fix: conflict error * fix: floor * fix: subtract * Revert "fix: subtract" This reverts commit2ef4afaafc
. * Revert "fix: floor" This reverts commitbef8ecdf45
. * Revert "refactor: use raw unix time" This reverts commit5199e13cb2
.
38 lines
903 B
TypeScript
38 lines
903 B
TypeScript
class IdlingRenderScheduler {
|
|
#renderers: Set<FrameRequestCallback>;
|
|
#rafId: number;
|
|
#ricId: number;
|
|
|
|
constructor() {
|
|
this.#renderers = new Set();
|
|
this.#rafId = 0;
|
|
this.#ricId = requestIdleCallback((deadline) => this.#schedule(deadline));
|
|
}
|
|
|
|
#schedule(deadline: IdleDeadline): void {
|
|
if (deadline.timeRemaining()) {
|
|
this.#rafId = requestAnimationFrame((time) => {
|
|
for (const renderer of this.#renderers) {
|
|
renderer(time);
|
|
}
|
|
});
|
|
}
|
|
this.#ricId = requestIdleCallback((arg) => this.#schedule(arg));
|
|
}
|
|
|
|
add(renderer: FrameRequestCallback): void {
|
|
this.#renderers.add(renderer);
|
|
}
|
|
|
|
delete(renderer: FrameRequestCallback): void {
|
|
this.#renderers.delete(renderer);
|
|
}
|
|
|
|
dispose(): void {
|
|
this.#renderers.clear();
|
|
cancelAnimationFrame(this.#rafId);
|
|
cancelIdleCallback(this.#ricId);
|
|
}
|
|
}
|
|
|
|
export const defaultIdlingRenderScheduler = new IdlingRenderScheduler();
|