[IMP] owl: update to v1.0.0-alpha2

This commit is contained in:
Géry Debongnie
2019-11-01 09:16:27 +01:00
parent 71a6091772
commit 573e379af4
3 changed files with 43 additions and 57 deletions
+37 -51
View File
@@ -1278,6 +1278,7 @@
} }
var _utils = /*#__PURE__*/Object.freeze({ var _utils = /*#__PURE__*/Object.freeze({
__proto__: null,
whenReady: whenReady, whenReady: whenReady,
loadJS: loadJS, loadJS: loadJS,
loadFile: loadFile, loadFile: loadFile,
@@ -2516,28 +2517,13 @@
set(mode) { set(mode) {
QWeb.dev = mode === "dev"; QWeb.dev = mode === "dev";
if (QWeb.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.`); console.warn(`Owl is running in 'dev' mode. This is not suitable for production use. See ${url} for more information.`);
} }
else { else {
console.log(`Owl is now running in 'prod' mode.`); 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) { constructor(parent, props) {
Component.current = this; 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++; const id = nextId++;
let depth; let depth;
if (parent) { 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; this.env = parent.env;
const __powl__ = parent.__owl__; const __powl__ = parent.__owl__;
__powl__.children[id] = this; __powl__.children[id] = this;
@@ -3361,8 +3349,10 @@
} }
else { else {
// we are the root component // we are the root component
this.env = config.env; this.env = this.constructor.env;
this.props = undefined; if (!this.env.qweb) {
this.env.qweb = new QWeb();
}
this.env.qweb.on("update", this, () => { this.env.qweb.on("update", this, () => {
if (this.__owl__.isMounted) { if (this.__owl__.isMounted) {
this.render(true); this.render(true);
@@ -3379,6 +3369,7 @@
depth = 0; depth = 0;
} }
const qweb = this.env.qweb; const qweb = this.env.qweb;
const template = constr.template || this.__getTemplate(qweb);
this.__owl__ = { this.__owl__ = {
id: id, id: id,
depth: depth, depth: depth,
@@ -3398,7 +3389,7 @@
willStartCB: null, willStartCB: null,
willUpdatePropsCB: null, willUpdatePropsCB: null,
observer: null, observer: null,
renderFn: qweb.render.bind(qweb, this.__getTemplate(qweb)), renderFn: qweb.render.bind(qweb, template),
classObj: null, classObj: null,
refs: null refs: null
}; };
@@ -3694,7 +3685,7 @@
} }
const defaultProps = this.constructor.defaultProps; const defaultProps = this.constructor.defaultProps;
if (defaultProps) { if (defaultProps) {
nextProps = this.__applyDefaultProps(nextProps, defaultProps); this.__applyDefaultProps(nextProps, defaultProps);
} }
if (QWeb.dev) { if (QWeb.dev) {
QWeb.utils.validateProps(this.constructor, nextProps); QWeb.utils.validateProps(this.constructor, nextProps);
@@ -3739,23 +3730,18 @@
__getTemplate(qweb) { __getTemplate(qweb) {
let p = this.constructor; let p = this.constructor;
if (!p.hasOwnProperty("_template")) { if (!p.hasOwnProperty("_template")) {
if (p.template) { // here, the component and none of its superclasses defines a static `template`
p._template = p.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 { else {
// here, the component and none of its superclasses defines a static `template` p._template = 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;
}
} }
} }
return p._template; return p._template;
@@ -3837,23 +3823,21 @@
/** /**
* Apply default props (only top level). * Apply default props (only top level).
* *
* Note that this method does not modify in place the props, it returns a new * Note that this method does modify in place the props
* prop object
*/ */
__applyDefaultProps(props, defaultProps) { __applyDefaultProps(props, defaultProps) {
props = props ? Object.assign({}, props) : {};
for (let propName in defaultProps) { for (let propName in defaultProps) {
if (props[propName] === undefined) { if (props[propName] === undefined) {
props[propName] = defaultProps[propName]; props[propName] = defaultProps[propName];
} }
} }
return props;
} }
} }
Component.template = null; Component.template = null;
Component._template = null; Component._template = null;
Component.current = null; Component.current = null;
Component.components = {}; Component.components = {};
Component.env = {};
/** /**
* Owl Hook System * Owl Hook System
@@ -3964,6 +3948,7 @@
} }
var _hooks = /*#__PURE__*/Object.freeze({ var _hooks = /*#__PURE__*/Object.freeze({
__proto__: null,
useState: useState, useState: useState,
onMounted: onMounted, onMounted: onMounted,
onWillUnmount: onWillUnmount, onWillUnmount: onWillUnmount,
@@ -4215,6 +4200,7 @@
} }
var _tags = /*#__PURE__*/Object.freeze({ var _tags = /*#__PURE__*/Object.freeze({
__proto__: null,
xml: xml xml: xml
}); });
@@ -4529,9 +4515,9 @@
exports.useState = useState$1; exports.useState = useState$1;
exports.utils = utils; exports.utils = utils;
exports.__info__.version = '1.0.0-alpha'; exports.__info__.version = '1.0.0-alpha2';
exports.__info__.date = '2019-10-30T15:41:04.324Z'; exports.__info__.date = '2019-11-01T08:12:51.280Z';
exports.__info__.hash = '2fc71cf'; exports.__info__.hash = 'bd3c126';
exports.__info__.url = 'https://github.com/odoo/owl'; exports.__info__.url = 'https://github.com/odoo/owl';
}(this.owl = this.owl || {})); }(this.owl = this.owl || {}));
+2 -2
View File
@@ -95,7 +95,7 @@ function makeCodeIframe(js, css, xml, errorHandler) {
owl.__info__.mode = 'dev'; owl.__info__.mode = 'dev';
let templates = \`${sanitizedXML}\`; let templates = \`${sanitizedXML}\`;
const qweb = new owl.QWeb({ templates }); const qweb = new owl.QWeb({ templates });
owl.config.env = { qweb }; owl.Component.env = { qweb };
} }
${js}`; ${js}`;
script.innerHTML = content; script.innerHTML = content;
@@ -443,7 +443,7 @@ async function start() {
owl.utils.whenReady() owl.utils.whenReady()
]); ]);
const qweb = new owl.QWeb({ templates }); const qweb = new owl.QWeb({ templates });
owl.config.env = { qweb }; owl.Component.env = { qweb };
const app = new App(); const app = new App();
app.mount(document.body); app.mount(document.body);
} }
+4 -4
View File
@@ -345,7 +345,7 @@ const themeContext = new Context({
foreground: '#fff', foreground: '#fff',
}); });
// Add the themeContext the environment to make it available to all components // 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(); const app = new App();
app.mount(document.body); app.mount(document.body);
`; `;
@@ -544,7 +544,7 @@ function makeStore() {
return store; return store;
} }
owl.config.env.store = makeStore(); TodoApp.env.store = makeStore();
const app = new TodoApp(); const app = new TodoApp();
app.mount(document.body); app.mount(document.body);
`; `;
@@ -1032,7 +1032,7 @@ function setupResponsivePlugin(env) {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Application Startup // Application Startup
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
setupResponsivePlugin(owl.config.env); setupResponsivePlugin(App.env);
const app = new App(); const app = new App();
app.mount(document.body); app.mount(document.body);
@@ -1543,7 +1543,7 @@ const windows = [
} }
]; ];
owl.config.env.windows = windows; App.env.windows = windows;
const app = new App(); const app = new App();
app.mount(document.body); app.mount(document.body);
`; `;