[REF] scheduler: capture requestAnimationFrame asap

This is useful to prevent interactions with other testing code.
This commit is contained in:
Géry Debongnie
2022-01-20 10:13:17 +01:00
committed by Samuel Degueldre
parent 9a54afcdf5
commit 8e36a11b6e
2 changed files with 5 additions and 2 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ export class App<T extends typeof Component = any> extends TemplateSet {
Root: T; Root: T;
props: any; props: any;
env: Env; env: Env;
scheduler = new Scheduler(window.requestAnimationFrame.bind(window)); scheduler = new Scheduler();
root: ComponentNode | null = null; root: ComponentNode | null = null;
constructor(Root: T, config: AppConfig = {}) { constructor(Root: T, config: AppConfig = {}) {
+4 -1
View File
@@ -7,11 +7,14 @@ import { STATUS } from "./status";
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
export class Scheduler { 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<RootFiber> = new Set(); tasks: Set<RootFiber> = new Set();
isRunning: boolean = false; isRunning: boolean = false;
requestAnimationFrame: Window["requestAnimationFrame"]; requestAnimationFrame: Window["requestAnimationFrame"];
constructor(requestAnimationFrame: Window["requestAnimationFrame"]) { constructor() {
this.requestAnimationFrame = requestAnimationFrame; this.requestAnimationFrame = requestAnimationFrame;
} }