From 9f93da4765c2bc58fa38ed1fede3fff297e7a7b3 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Mon, 14 Oct 2019 13:10:33 +0200 Subject: [PATCH] [REF] config: move `mode` from owl.__info__ to owl.config and move it to its own file. --- src/config.ts | 31 +++++++++++++++++++++++++++++++ src/index.ts | 19 ++----------------- 2 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 src/config.ts diff --git a/src/config.ts b/src/config.ts new file mode 100644 index 00000000..0c39c60c --- /dev/null +++ b/src/config.ts @@ -0,0 +1,31 @@ +import { QWeb } from "./qweb/index"; + +/** + * This file creates and exports the OWL 'config' object, with keys: + * - 'mode': 'prod' or 'dev', + */ + +interface Config { + mode: string; +} + +const _config:Partial = {}; + +Object.defineProperty(_config, "mode", { + get() { + return QWeb.dev ? "dev" : "prod"; + }, + set(mode: string) { + QWeb.dev = mode === "dev"; + if (QWeb.dev) { + const url = `https://github.com/odoo/owl/blob/master/doc/tooling.md#development-mode`; + console.warn( + `Owl is running in 'dev' mode. This is not suitable for production use. See ${url} for more information.` + ); + } else { + console.log(`Owl is now running in 'prod' mode.`); + } + }, +}); + +export const config:Config = _config as Config; diff --git a/src/index.ts b/src/index.ts index a1e3d515..3feef049 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,7 @@ import { EventBus } from "./core/event_bus"; import { Observer } from "./core/observer"; import { QWeb } from "./qweb/index"; +import { config } from "./config"; import * as _store from "./store"; import * as _utils from "./utils"; import * as _tags from "./tags"; @@ -19,6 +20,7 @@ import { Router } from "./router/router"; export { Component } from "./component/component"; export { QWeb }; +export { config }; export const Context = _context.Context; export const useState = _hooks.useState; @@ -35,20 +37,3 @@ export const hooks = Object.assign({}, _hooks, { useStore: _store.useStore }); export const __info__ = {}; - -Object.defineProperty(__info__, "mode", { - get() { - return QWeb.dev ? "dev" : "prod"; - }, - set(mode: string) { - QWeb.dev = mode === "dev"; - if (QWeb.dev) { - const url = `https://github.com/odoo/owl/blob/master/doc/tooling.md#development-mode`; - console.warn( - `Owl is running in 'dev' mode. This is not suitable for production use. See ${url} for more information.` - ); - } else { - console.log(`Owl is now running in 'prod' mode.`); - } - } -});