From b08cc1d0844dea7886e86aa2fb59bd6f5370106a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Tue, 20 Oct 2020 13:05:39 +0200 Subject: [PATCH] [IMP] config: add enableTransitions flag to config It is useful to be able to disable the t-transition directive for testing purposes. This commit introduces a global config flag to do just that. closes #768 --- doc/reference/config.md | 21 +++++++++++++++++++-- src/config.ts | 10 ++++++++++ src/qweb/extensions.ts | 3 +++ src/qweb/qweb.ts | 1 + 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/doc/reference/config.md b/doc/reference/config.md index 59872965..f17181d8 100644 --- a/doc/reference/config.md +++ b/doc/reference/config.md @@ -2,9 +2,10 @@ The Owl framework is designed to work in many situations. However, it is sometimes necessary to customize some behaviour. This is done by using the -global `config` object. It currently has one key: +global `config` object. It provides two settings: -- [`mode`](#mode). +- [`mode`](#mode) (default value: `prod`), +- [`enableTransitions`](#enabletransitions) (default value: `true`). ## Mode @@ -25,3 +26,19 @@ So, changing this setting is best done at startup. An important job done by the `dev` mode is to validate props for each component creation and update. Also, extra props will cause an error. + +## `enableTransitions` + +Transitions are usually nice, but they can cause issues in some specific cases, +such as automated tests. It is uncomfortable having to wait for a transition +to end before moving to the next step. + +To solve this issue, Owl can be configured to ignore the `t-transition` directive. +To do that, one only needs to set the `enableTransitions` flag to false: + +```js +owl.config.enableTransitions = false; +``` + +Note that it suffers from the same drawback as the "dev" mode: all compiled +templates, if any, will keep their current behaviours. diff --git a/src/config.ts b/src/config.ts index 69dc8402..eedd0e56 100644 --- a/src/config.ts +++ b/src/config.ts @@ -8,6 +8,7 @@ import { QWeb } from "./qweb/index"; interface Config { mode: string; + enableTransitions: boolean; } export const config = {} as Config; @@ -28,3 +29,12 @@ Object.defineProperty(config, "mode", { } }, }); + +Object.defineProperty(config, "enableTransitions", { + get() { + return QWeb.enableTransitions; + }, + set(value: boolean) { + QWeb.enableTransitions = value; + }, +}); diff --git a/src/qweb/extensions.ts b/src/qweb/extensions.ts index 6e5c2b14..9e61bb44 100644 --- a/src/qweb/extensions.ts +++ b/src/qweb/extensions.ts @@ -205,6 +205,9 @@ QWeb.addDirective({ name: "transition", priority: 96, atNodeCreation({ ctx, value, addNodeHook }) { + if (!QWeb.enableTransitions) { + return; + } ctx.rootContext.shouldDefineUtils = true; let name = value; const hooks = { diff --git a/src/qweb/qweb.ts b/src/qweb/qweb.ts index 5be6174d..f6b7c830 100644 --- a/src/qweb/qweb.ts +++ b/src/qweb/qweb.ts @@ -212,6 +212,7 @@ export class QWeb extends EventBus { h = h; // dev mode enables better error messages or more costly validations static dev: boolean = false; + static enableTransitions: boolean = true; // slots contains sub templates defined with t-set inside t-component nodes, and // are meant to be used by the t-slot directive.