From 8e36a11b6e5949cc7db0654802d5d95674f7dd06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Thu, 20 Jan 2022 10:13:17 +0100 Subject: [PATCH] [REF] scheduler: capture requestAnimationFrame asap This is useful to prevent interactions with other testing code. --- src/app/app.ts | 2 +- src/component/scheduler.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/app/app.ts b/src/app/app.ts index eebf26ed..a4e8f84d 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -25,7 +25,7 @@ export class App extends TemplateSet { Root: T; props: any; env: Env; - scheduler = new Scheduler(window.requestAnimationFrame.bind(window)); + scheduler = new Scheduler(); root: ComponentNode | null = null; constructor(Root: T, config: AppConfig = {}) { diff --git a/src/component/scheduler.ts b/src/component/scheduler.ts index 2b868d08..3a8e4be4 100644 --- a/src/component/scheduler.ts +++ b/src/component/scheduler.ts @@ -7,11 +7,14 @@ import { STATUS } from "./status"; // ----------------------------------------------------------------------------- export class Scheduler { + // capture the value of requestAnimationFrame as soon as possible, to avoid + // interactions with other code, such as test frameworks that override them + static requestAnimationFrame = window.requestAnimationFrame.bind(this); tasks: Set = new Set(); isRunning: boolean = false; requestAnimationFrame: Window["requestAnimationFrame"]; - constructor(requestAnimationFrame: Window["requestAnimationFrame"]) { + constructor() { this.requestAnimationFrame = requestAnimationFrame; }