diff --git a/owl.js b/owl.js index 3267bb32..b4dc701f 100644 --- a/owl.js +++ b/owl.js @@ -1278,6 +1278,7 @@ } var _utils = /*#__PURE__*/Object.freeze({ + __proto__: null, whenReady: whenReady, loadJS: loadJS, loadFile: loadFile, @@ -2516,28 +2517,13 @@ set(mode) { QWeb.dev = mode === "dev"; if (QWeb.dev) { - const url = `https://github.com/odoo/owl/blob/master/doc/tooling.md#development-mode`; + const url = `https://github.com/odoo/owl/blob/master/doc/reference/config.md#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.`); } - }, - }); - let env; - Object.defineProperty(config, "env", { - get() { - if (!env) { - env = {}; - } - if (!env.qweb) { - env.qweb = new QWeb(); - } - return env; - }, - set(newEnv) { - env = newEnv; - }, + } }); //------------------------------------------------------------------------------ @@ -3343,17 +3329,19 @@ */ constructor(parent, props) { Component.current = this; + let constr = this.constructor; + const defaultProps = constr.defaultProps; + if (defaultProps) { + props = props || {}; + this.__applyDefaultProps(props, defaultProps); + } + this.props = props; + if (QWeb.dev) { + QWeb.utils.validateProps(constr, this.props); + } const id = nextId++; let depth; if (parent) { - const defaultProps = this.constructor.defaultProps; - if (defaultProps) { - props = this.__applyDefaultProps(props, defaultProps); - } - this.props = props; - if (QWeb.dev) { - QWeb.utils.validateProps(this.constructor, this.props); - } this.env = parent.env; const __powl__ = parent.__owl__; __powl__.children[id] = this; @@ -3361,8 +3349,10 @@ } else { // we are the root component - this.env = config.env; - this.props = undefined; + this.env = this.constructor.env; + if (!this.env.qweb) { + this.env.qweb = new QWeb(); + } this.env.qweb.on("update", this, () => { if (this.__owl__.isMounted) { this.render(true); @@ -3379,6 +3369,7 @@ depth = 0; } const qweb = this.env.qweb; + const template = constr.template || this.__getTemplate(qweb); this.__owl__ = { id: id, depth: depth, @@ -3398,7 +3389,7 @@ willStartCB: null, willUpdatePropsCB: null, observer: null, - renderFn: qweb.render.bind(qweb, this.__getTemplate(qweb)), + renderFn: qweb.render.bind(qweb, template), classObj: null, refs: null }; @@ -3694,7 +3685,7 @@ } const defaultProps = this.constructor.defaultProps; if (defaultProps) { - nextProps = this.__applyDefaultProps(nextProps, defaultProps); + this.__applyDefaultProps(nextProps, defaultProps); } if (QWeb.dev) { QWeb.utils.validateProps(this.constructor, nextProps); @@ -3739,23 +3730,18 @@ __getTemplate(qweb) { let p = this.constructor; if (!p.hasOwnProperty("_template")) { - if (p.template) { - p._template = p.template; + // here, the component and none of its superclasses defines a static `template` + // key. So we fall back on looking for a template matching its name (or + // one of its subclass). + let template; + while ((template = p.name) && !(template in qweb.templates) && p !== Component) { + p = p.__proto__; + } + if (p === Component) { + throw new Error(`Could not find template for component "${this.constructor.name}"`); } else { - // here, the component and none of its superclasses defines a static `template` - // key. So we fall back on looking for a template matching its name (or - // one of its subclass). - let template; - while ((template = p.name) && !(template in qweb.templates) && p !== Component) { - p = p.__proto__; - } - if (p === Component) { - throw new Error(`Could not find template for component "${this.constructor.name}"`); - } - else { - p._template = template; - } + p._template = template; } } return p._template; @@ -3837,23 +3823,21 @@ /** * Apply default props (only top level). * - * Note that this method does not modify in place the props, it returns a new - * prop object + * Note that this method does modify in place the props */ __applyDefaultProps(props, defaultProps) { - props = props ? Object.assign({}, props) : {}; for (let propName in defaultProps) { if (props[propName] === undefined) { props[propName] = defaultProps[propName]; } } - return props; } } Component.template = null; Component._template = null; Component.current = null; Component.components = {}; + Component.env = {}; /** * Owl Hook System @@ -3964,6 +3948,7 @@ } var _hooks = /*#__PURE__*/Object.freeze({ + __proto__: null, useState: useState, onMounted: onMounted, onWillUnmount: onWillUnmount, @@ -4215,6 +4200,7 @@ } var _tags = /*#__PURE__*/Object.freeze({ + __proto__: null, xml: xml }); @@ -4529,9 +4515,9 @@ exports.useState = useState$1; exports.utils = utils; - exports.__info__.version = '1.0.0-alpha'; - exports.__info__.date = '2019-10-30T15:41:04.324Z'; - exports.__info__.hash = '2fc71cf'; + exports.__info__.version = '1.0.0-alpha2'; + exports.__info__.date = '2019-11-01T08:12:51.280Z'; + exports.__info__.hash = 'bd3c126'; exports.__info__.url = 'https://github.com/odoo/owl'; }(this.owl = this.owl || {})); diff --git a/playground/app.js b/playground/app.js index 70267071..d07ca6ec 100644 --- a/playground/app.js +++ b/playground/app.js @@ -95,7 +95,7 @@ function makeCodeIframe(js, css, xml, errorHandler) { owl.__info__.mode = 'dev'; let templates = \`${sanitizedXML}\`; const qweb = new owl.QWeb({ templates }); - owl.config.env = { qweb }; + owl.Component.env = { qweb }; } ${js}`; script.innerHTML = content; @@ -443,7 +443,7 @@ async function start() { owl.utils.whenReady() ]); const qweb = new owl.QWeb({ templates }); - owl.config.env = { qweb }; + owl.Component.env = { qweb }; const app = new App(); app.mount(document.body); } diff --git a/playground/samples.js b/playground/samples.js index b47f8e35..ab1384f6 100644 --- a/playground/samples.js +++ b/playground/samples.js @@ -345,7 +345,7 @@ const themeContext = new Context({ foreground: '#fff', }); // Add the themeContext the environment to make it available to all components -owl.config.env.themeContext = themeContext; +App.env.themeContext = themeContext; const app = new App(); app.mount(document.body); `; @@ -544,7 +544,7 @@ function makeStore() { return store; } -owl.config.env.store = makeStore(); +TodoApp.env.store = makeStore(); const app = new TodoApp(); app.mount(document.body); `; @@ -1032,7 +1032,7 @@ function setupResponsivePlugin(env) { //------------------------------------------------------------------------------ // Application Startup //------------------------------------------------------------------------------ -setupResponsivePlugin(owl.config.env); +setupResponsivePlugin(App.env); const app = new App(); app.mount(document.body); @@ -1543,7 +1543,7 @@ const windows = [ } ]; -owl.config.env.windows = windows; +App.env.windows = windows; const app = new App(); app.mount(document.body); `;