mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[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:
committed by
Géry Debongnie
parent
9f93da4765
commit
9106c19066
+20
-3
@@ -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;
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user