Compare commits

..

1 Commits

Author SHA1 Message Date
Géry Debongnie b90aa0e23a [REL] v2.0.0-beta-16
# v2.0.0-beta-16

Notes

- fix: components: fix cause left unset when thrown object is not Error
2022-07-22 09:43:43 +02:00
3 changed files with 11 additions and 39 deletions
-3
View File
@@ -55,9 +55,6 @@ The `config` object is an object with some of the following keys:
[`dev` mode](#dev-mode); [`dev` mode](#dev-mode);
- **`test (boolean, default=false)`**: `test` mode is the same as `dev` mode, except - **`test (boolean, default=false)`**: `test` mode is the same as `dev` mode, except
that Owl will not log a message to warn that Owl is in `dev` mode. that Owl will not log a message to warn that Owl is in `dev` mode.
- **`shareTemplates (boolean, default=false)`**: if `true`, each compiled template
will be shared between instances of `App`. Useful for speeding test suites, because
it prevent recompiling the same templates again and again.
- **`translatableAttributes (string[])`**: a list of additional attributes that should - **`translatableAttributes (string[])`**: a list of additional attributes that should
be translated (see [translations](translations.md)) be translated (see [translations](translations.md))
- **`translateFn (function)`**: a function that will be called by owl to translate - **`translateFn (function)`**: a function that will be called by owl to translate
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@odoo/owl", "name": "@odoo/owl",
"version": "2.0.0-beta-15", "version": "2.0.0-beta-16",
"description": "Odoo Web Library (OWL)", "description": "Odoo Web Library (OWL)",
"main": "dist/owl.cjs.js", "main": "dist/owl.cjs.js",
"module": "dist/owl.es.js", "module": "dist/owl.es.js",
+10 -35
View File
@@ -37,17 +37,11 @@ function parseXML(xml: string): Document {
return doc; return doc;
} }
const sharedTemplates: Map<
Function | undefined,
{ [key: string]: { [name: string]: TemplateFunction } }
> = new Map();
export interface TemplateSetConfig { export interface TemplateSetConfig {
dev?: boolean; dev?: boolean;
translatableAttributes?: string[]; translatableAttributes?: string[];
translateFn?: (s: string) => string; translateFn?: (s: string) => string;
templates?: string | Document; templates?: string | Document;
shareTemplates?: boolean;
} }
export class TemplateSet { export class TemplateSet {
@@ -57,27 +51,12 @@ export class TemplateSet {
dev: boolean; dev: boolean;
rawTemplates: typeof globalTemplates = Object.create(globalTemplates); rawTemplates: typeof globalTemplates = Object.create(globalTemplates);
templates: { [name: string]: Template } = {}; templates: { [name: string]: Template } = {};
templateFunctions: { [name: string]: TemplateFunction } = {};
translateFn?: (s: string) => string; translateFn?: (s: string) => string;
translatableAttributes?: string[]; translatableAttributes?: string[];
Portal = Portal; Portal = Portal;
constructor(config: TemplateSetConfig = {}) { constructor(config: TemplateSetConfig = {}) {
this.dev = config.dev || false; this.dev = config.dev || false;
if (config.shareTemplates) {
let cache = sharedTemplates.get(this.translateFn);
if (!cache) {
cache = {};
sharedTemplates.set(this.translateFn, cache);
}
let key = `${this.dev ? "d" : "p"}${(this.translatableAttributes || []).toString()}`;
let templates = cache[key];
if (!templates) {
cache[key] = {};
templates = cache[key];
}
this.templateFunctions = templates;
}
this.translateFn = config.translateFn; this.translateFn = config.translateFn;
this.translatableAttributes = config.translatableAttributes; this.translatableAttributes = config.translatableAttributes;
if (config.templates) { if (config.templates) {
@@ -117,21 +96,17 @@ export class TemplateSet {
getTemplate(name: string): Template { getTemplate(name: string): Template {
if (!(name in this.templates)) { if (!(name in this.templates)) {
let templateFn = this.templateFunctions[name]; const rawTemplate = this.rawTemplates[name];
if (!templateFn) { if (rawTemplate === undefined) {
const rawTemplate = this.rawTemplates[name]; let extraInfo = "";
if (rawTemplate === undefined) { try {
let extraInfo = ""; const componentName = getCurrent().component.constructor.name;
try { extraInfo = ` (for component "${componentName}")`;
const componentName = getCurrent().component.constructor.name; } catch {}
extraInfo = ` (for component "${componentName}")`; throw new OwlError(`Missing template: "${name}"${extraInfo}`);
} catch {}
throw new OwlError(`Missing template: "${name}"${extraInfo}`);
}
const isFn = typeof rawTemplate === "function" && !(rawTemplate instanceof Element);
templateFn = isFn ? rawTemplate : this._compileTemplate(name, rawTemplate);
this.templateFunctions[name] = templateFn;
} }
const isFn = typeof rawTemplate === "function" && !(rawTemplate instanceof Element);
const templateFn = isFn ? rawTemplate : this._compileTemplate(name, rawTemplate);
// first add a function to lazily get the template, in case there is a // first add a function to lazily get the template, in case there is a
// recursive call to the template name // recursive call to the template name
const templates = this.templates; const templates = this.templates;