diff --git a/doc/readme.md b/doc/readme.md index f08741df..7aa494f3 100644 --- a/doc/readme.md +++ b/doc/readme.md @@ -13,4 +13,5 @@ ## Miscellaneous - [Quick Start](quick_start.md) - [Animations](animations.md) +- [Tooling](tooling.md) - [Comparison with React/Vue](comparison.md) diff --git a/doc/tooling.md b/doc/tooling.md new file mode 100644 index 00000000..93dd1a51 --- /dev/null +++ b/doc/tooling.md @@ -0,0 +1,18 @@ +# 🦉 Tooling 🦉 + +## Development mode + +By default, Owl is in *production* mode, this means that it will try to do its +job fast, and skip some expensive operations. However, in some cases, it is +convenient to have better information on what is going on, this is the purpose +of the dev mode. + +Owl has a mode flag, in `owl.__info__.mode`. Its default value is `prod`, but +it can be set to `dev`: + +```js +owl.__info__.mode = 'dev'; +``` + +Note that templates compiled with the `prod` settings will not be recompiled. +So, changing this setting is best done at startup. \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index dfccbf1e..8693ca8c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,12 +12,26 @@ export { Observer } from "./observer"; // themselves in QWeb, otherwise these files will not even be loaded. import "./qweb_directives"; import "./qweb_extensions"; -export { QWeb } from "./qweb_core"; +import { QWeb } from "./qweb_core"; +export { QWeb }; export { connect, Store } from "./store"; import * as _utils from "./utils"; -export const __info__ = {} - +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.` + ); + } + } +}); export const utils = _utils; diff --git a/src/qweb_core.ts b/src/qweb_core.ts index a007a7ab..4bf478b5 100644 --- a/src/qweb_core.ts +++ b/src/qweb_core.ts @@ -127,6 +127,9 @@ export class QWeb { templates: { [name: string]: Template } = {}; utils = UTILS; + // dev mode enables better error messages or more costly validations + static dev: boolean = false; + // the id field is useful to be able to hash qweb instances. The current // use case is that component's templates are qweb dependant, and need to be // able to map a qweb instance to a template name.