[IMP] component: get env from constructor

closes #430
This commit is contained in:
Aaron Bohy
2019-10-31 13:31:10 +01:00
committed by Géry Debongnie
parent 8fbf2172c5
commit 05a678c039
14 changed files with 48 additions and 47 deletions
+5 -2
View File
@@ -1,7 +1,6 @@
import { Observer } from "../core/observer";
import { CompiledTemplate, QWeb } from "../qweb/index";
import { h, patch, VNode } from "../vdom/index";
import { config } from "../config";
import "./directive";
import { Fiber } from "./fiber";
import "./props_validation";
@@ -88,6 +87,7 @@ export class Component<T extends Env, Props extends {}> {
static components = {};
static props?: any;
static defaultProps?: any;
static env: any = {};
/**
* The `el` is the root element of the component. Note that it could be null:
@@ -131,7 +131,10 @@ export class Component<T extends Env, Props extends {}> {
depth = __powl__.depth + 1;
} else {
// we are the root component
this.env = config.env as T;
this.env = (this.constructor as any).env;
if (!this.env.qweb) {
this.env.qweb = new QWeb();
}
this.props = undefined as unknown as Props;
this.env.qweb.on("update", this, () => {
if (this.__owl__.isMounted) {
-18
View File
@@ -1,5 +1,4 @@
import { QWeb } from "./qweb/index";
import { Env } from "./component/component";
/**
* This file creates and exports the OWL 'config' object, with keys:
@@ -8,7 +7,6 @@ import { Env } from "./component/component";
*/
interface Config {
env: Env;
mode: string;
}
@@ -30,19 +28,3 @@ Object.defineProperty(config, "mode", {
}
},
});
let env:Env;
Object.defineProperty(config, "env", {
get() {
if (!env) {
env = {} as Env;
}
if (!env.qweb) {
env.qweb = new QWeb();
}
return env;
},
set(newEnv: Env) {
env = newEnv;
},
});