[IMP] component: expose scheduler instance

Closes #433
This commit is contained in:
Aaron Bohy
2019-11-05 08:47:19 +01:00
committed by Géry Debongnie
parent 1226f015d7
commit 5731358607
+6 -2
View File
@@ -4,7 +4,7 @@ import { h, patch, VNode } from "../vdom/index";
import "./directive"; import "./directive";
import { Fiber } from "./fiber"; import { Fiber } from "./fiber";
import "./props_validation"; import "./props_validation";
import { scheduler } from "./scheduler"; import { Scheduler, scheduler } from "./scheduler";
/** /**
* Owl Component System * Owl Component System
@@ -88,6 +88,8 @@ export class Component<T extends Env, Props extends {}> {
static props?: any; static props?: any;
static defaultProps?: any; static defaultProps?: any;
static env: any = {}; static env: any = {};
// expose scheduler s.t. it can be mocked for testing purposes
static scheduler: Scheduler = scheduler;
/** /**
* The `el` is the root element of the component. Note that it could be null: * The `el` is the root element of the component. Note that it could be null:
@@ -287,7 +289,9 @@ export class Component<T extends Env, Props extends {}> {
return; return;
} }
if (!(target instanceof HTMLElement)) { if (!(target instanceof HTMLElement)) {
let message = `Component '${this.constructor.name}' cannot be mounted: the target is not a valid DOM node.`; let message = `Component '${
this.constructor.name
}' cannot be mounted: the target is not a valid DOM node.`;
message += `\nMaybe the DOM is not ready yet? (in that case, you can use owl.utils.whenReady)`; message += `\nMaybe the DOM is not ready yet? (in that case, you can use owl.utils.whenReady)`;
throw new Error(message); throw new Error(message);
} }