[IMP] component: simplify constructor API

It now takes two arguments: parent (optional, only for non-root
components) and props (optional). In the case of the root component,
the env is taken from the config (config.defaultEnv). If it doesn't
exists, the default env is created on the fly.

Closes #306
This commit is contained in:
Aaron Bohy
2019-10-14 15:09:17 +02:00
committed by Géry Debongnie
parent 9f93da4765
commit 9106c19066
14 changed files with 406 additions and 386 deletions
+20 -3
View File
@@ -1,17 +1,20 @@
import { QWeb } from "./qweb/index";
import { Env } from "./component/component";
/**
* This file creates and exports the OWL 'config' object, with keys:
* - 'mode': 'prod' or 'dev',
* - 'env': the environment to use in root components.
*/
interface Config {
env: Env;
mode: string;
}
const _config:Partial<Config> = {};
export const config = {} as Config;
Object.defineProperty(_config, "mode", {
Object.defineProperty(config, "mode", {
get() {
return QWeb.dev ? "dev" : "prod";
},
@@ -28,4 +31,18 @@ Object.defineProperty(_config, "mode", {
},
});
export const config:Config = _config as Config;
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;
},
});