[IMP] app: introduce test mode

Same as `dev` mode, but without warning in console
This commit is contained in:
Géry Debongnie
2022-01-28 13:39:03 +01:00
committed by Aaron Bohy
parent a7305a5cdb
commit 722abd6d5f
2 changed files with 26 additions and 17 deletions
+21 -16
View File
@@ -3,6 +3,7 @@
## Content ## Content
- [Overview](#overview) - [Overview](#overview)
- [API](#api)
- [Configuration](#configuration) - [Configuration](#configuration)
- [`mount` helper](#mount-helper) - [`mount` helper](#mount-helper)
- [Loading templates](#loading-templates) - [Loading templates](#loading-templates)
@@ -26,24 +27,10 @@ The basic workflow is: create an `App` instance configured with the root
component, the templates, and possibly other settings. Then, we mount that component, the templates, and possibly other settings. Then, we mount that
instance somewhere in the DOM. instance somewhere in the DOM.
## Configuration ## API
- **`constructor(Root[, config])`**: first argument should be a component class (not - **`constructor(Root[, config])`**: first argument should be a component class (not
an instance), and the optional second argument is a configuration object. an instance), and the optional second argument is a configuration object (see below).
The `config` object is an object with some of the following keys:
- **`env (object)`**: if given, this will be the shared `env` given to each component
- **`props (object)`**: the props given to the root component
- **`dev (boolean, default=false)`**: if `true`, the application is rendered in `dev`
mode, which activates some additional checks (in particular, the props validation
code is only performed in dev mode)
- **`translatableAttributes (string[])`**: a list of additional attributes that should
be translated (see [translations](translations.md))
- **`translateFn (function)`**: a function that will be called by owl to translate
templates (see [translations](translations.md))
- **`templates (string | xml document)`**: all the templates that will be used by
the components created by the application.
- **`mount(target, options)`**: first argument is an html element, and the optional - **`mount(target, options)`**: first argument is an html element, and the optional
second argument is an object with mounting options (see below). Mount the app second argument is an object with mounting options (see below). Mount the app
@@ -58,6 +45,24 @@ instance somewhere in the DOM.
- **`destroy()`**: destroys the application - **`destroy()`**: destroys the application
## Configuration
The `config` object is an object with some of the following keys:
- **`env (object)`**: if given, this will be the shared `env` given to each component
- **`props (object)`**: the props given to the root component
- **`dev (boolean, default=false)`**: if `true`, the application is rendered in `dev`
mode, which activates some additional checks (in particular, the props validation
code is only performed in dev mode)
- **`test (boolean, default=false)`**: `test` mode is the same as `dev` mode, except
that Owll will not log a message to warn that Owl is in `dev` mode.
- **`translatableAttributes (string[])`**: a list of additional attributes that should
be translated (see [translations](translations.md))
- **`translateFn (function)`**: a function that will be called by owl to translate
templates (see [translations](translations.md))
- **`templates (string | xml document)`**: all the templates that will be used by
the components created by the application.
## `mount` helper ## `mount` helper
Note that there is a `mount` helper to do that in just a line: Note that there is a `mount` helper to do that in just a line:
+5 -1
View File
@@ -14,6 +14,7 @@ export interface Env {
export interface AppConfig<P, E> extends TemplateSetConfig { export interface AppConfig<P, E> extends TemplateSetConfig {
props?: P; props?: P;
env?: E; env?: E;
test?: boolean;
} }
export const DEV_MSG = `Owl is running in 'dev' mode. export const DEV_MSG = `Owl is running in 'dev' mode.
@@ -35,7 +36,10 @@ export class App<
constructor(Root: ComponentConstructor<P, E>, config: AppConfig<P, E> = {}) { constructor(Root: ComponentConstructor<P, E>, config: AppConfig<P, E> = {}) {
super(config); super(config);
this.Root = Root; this.Root = Root;
if (config.dev) { if (config.test) {
this.dev = true;
}
if (this.dev && !config.test) {
console.info(DEV_MSG); console.info(DEV_MSG);
} }
const descrs = Object.getOwnPropertyDescriptors(config.env || {}); const descrs = Object.getOwnPropertyDescriptors(config.env || {});