mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[REF] component: yet another simplification for t-widget
This commit is contained in:
+1
-2
@@ -459,8 +459,7 @@ export class Component<
|
||||
_mount(vnode: VNode, elm: HTMLElement): VNode {
|
||||
this.__owl__.vnode = patch(elm, vnode);
|
||||
if (
|
||||
this.__owl__.parent &&
|
||||
this.__owl__.parent.__owl__.isMounted &&
|
||||
this.__owl__.parent!.__owl__.isMounted &&
|
||||
!this.__owl__.isMounted
|
||||
) {
|
||||
this._callMounted();
|
||||
|
||||
+15
-16
@@ -257,25 +257,25 @@ QWeb.addDirective({
|
||||
createHook = `vnode.data.hook = {create(_, vn){${classCode}${styleCode}}};`;
|
||||
}
|
||||
|
||||
|
||||
ctx.addLine(
|
||||
`let w${widgetID} = ${templateID} in context.__owl__.cmap ? context.__owl__.children[context.__owl__.cmap[${templateID}]] : false;`
|
||||
);
|
||||
ctx.addLine(`let props${widgetID} = ${props || "{}"};`);
|
||||
ctx.addLine(`let sameProps${widgetID} = w${widgetID} && props${widgetID} === w${widgetID}.__owl__.renderProps`);
|
||||
ctx.addIf(`w${widgetID} && w${widgetID}.__owl__.renderPromise && !w${widgetID}.__owl__.isStarted && !sameProps${widgetID}`);
|
||||
ctx.addIf(
|
||||
`w${widgetID} && w${widgetID}.__owl__.renderPromise && !w${widgetID}.__owl__.isStarted && props${widgetID} !== w${widgetID}.__owl__.renderProps`
|
||||
);
|
||||
ctx.addLine(`w${widgetID}.destroy();`);
|
||||
ctx.addLine(`w${widgetID} = false`);
|
||||
ctx.closeIf();
|
||||
|
||||
|
||||
ctx.addLine(`let isNew${widgetID} = !w${widgetID};`);
|
||||
ctx.addIf(`isNew${widgetID}`);
|
||||
ctx.addIf(`!w${widgetID}`);
|
||||
// new widget
|
||||
ctx.addLine(`let W${widgetID} = context.widgets['${value}'];`);
|
||||
|
||||
// maybe only do this in dev mode...
|
||||
ctx.addLine(`if (!W${widgetID}) {throw new Error(\`Cannot find the definition of widget "${value}"\`)}`);
|
||||
ctx.addLine(
|
||||
`if (!W${widgetID}) {throw new Error(\`Cannot find the definition of widget "${value}"\`)}`
|
||||
);
|
||||
ctx.addLine(`w${widgetID} = new W${widgetID}(owner, props${widgetID});`);
|
||||
ctx.addLine(
|
||||
`context.__owl__.cmap[${templateID}] = w${widgetID}.__owl__.id;`
|
||||
@@ -285,29 +285,28 @@ QWeb.addDirective({
|
||||
}
|
||||
ctx.addLine(`def${defID} = w${widgetID}._prepare();`);
|
||||
ctx.addLine(
|
||||
`def${defID} = def${defID}.then(vnode=>{${createHook}let pvnode=h(vnode.sel, {key: ${templateID}});c${
|
||||
`def${defID} = def${defID}.then(vnode=>{${createHook}let pvnode=h(vnode.sel, {key: ${templateID}, hook: {insert(vn){let nvn=w${widgetID}._mount(vnode, vn.elm);pvnode.elm=nvn.elm;${refExpr}},remove(){${finalizeWidgetCode}},destroy(){${finalizeWidgetCode}}}});c${
|
||||
ctx.parentNode
|
||||
}[_${dummyID}_index]=pvnode;pvnode.data.hook = {insert(vn){let nvn=w${widgetID}._mount(vnode, vn.elm);pvnode.elm=nvn.elm;${refExpr}},remove(){${finalizeWidgetCode}},destroy(){${finalizeWidgetCode}}}; w${widgetID}.__owl__.pvnode = pvnode;});`
|
||||
}[_${dummyID}_index]=pvnode;w${widgetID}.__owl__.pvnode = pvnode;});`
|
||||
);
|
||||
|
||||
ctx.addElse();
|
||||
// need to update widget
|
||||
ctx.addIf(`w${widgetID}.__owl__.renderPromise && sameProps${widgetID}`);
|
||||
ctx.addLine(`def${defID} = w${widgetID}.__owl__.renderPromise;`);
|
||||
ctx.addElse();
|
||||
ctx.addLine(
|
||||
`def${defID} = w${widgetID}._updateProps(props${widgetID}, extra.forceUpdate, extra.patchQueue);`
|
||||
);
|
||||
ctx.closeIf()
|
||||
let keepAliveCode = "";
|
||||
if (keepAlive) {
|
||||
keepAliveCode = `pvnode.data.hook.insert = vn => {vn.elm.parentNode.replaceChild(w${widgetID}.el,vn.elm);vn.elm=w${widgetID}.el;w${widgetID}.__mount();};`;
|
||||
}
|
||||
ctx.addLine(
|
||||
`def${defID} = def${defID}.then(()=>{if (w${widgetID}.__owl__.isDestroyed) {return};${
|
||||
tattStyle ? `w${widgetID}.el.style=${tattStyle};` : ""
|
||||
}${updateClassCode}let pvnode=h(w${widgetID}.__owl__.pvnode.sel, {key: ${templateID}});pvnode.elm=w${widgetID}.el;pvnode.data.hook = {insert(a){a.elm.parentNode.replaceChild(w${widgetID}.el,a.elm);a.elm=w${widgetID}.el;w${widgetID}.__mount();},remove(){${finalizeWidgetCode}}, destroy() {${finalizeWidgetCode}}};c${
|
||||
}${updateClassCode}let pvnode=w${widgetID}.__owl__.pvnode;${keepAliveCode}c${
|
||||
ctx.parentNode
|
||||
}[_${dummyID}_index]=pvnode;});`
|
||||
);
|
||||
|
||||
ctx.closeIf()
|
||||
ctx.closeIf();
|
||||
|
||||
ctx.addLine(`extra.promises.push(def${defID});`);
|
||||
|
||||
|
||||
@@ -14,26 +14,20 @@ exports[`class and style attributes with t-widget dynamic t-att-style is properl
|
||||
const _5 = context['state'].style;
|
||||
let w4 = 4 in context.__owl__.cmap ? context.__owl__.children[context.__owl__.cmap[4]] : false;
|
||||
let props4 = {};
|
||||
let sameProps4 = w4 && props4 === w4.__owl__.renderProps
|
||||
if (w4 && w4.__owl__.renderPromise && !w4.__owl__.isStarted && !sameProps4) {
|
||||
if (w4 && w4.__owl__.renderPromise && !w4.__owl__.isStarted && props4 !== w4.__owl__.renderProps) {
|
||||
w4.destroy();
|
||||
w4 = false
|
||||
}
|
||||
let isNew4 = !w4;
|
||||
if (isNew4) {
|
||||
if (!w4) {
|
||||
let W4 = context.widgets['child'];
|
||||
if (!W4) {throw new Error(\`Cannot find the definition of widget \\"child\\"\`)}
|
||||
w4 = new W4(owner, props4);
|
||||
context.__owl__.cmap[4] = w4.__owl__.id;
|
||||
def3 = w4._prepare();
|
||||
def3 = def3.then(vnode=>{vnode.data.hook = {create(_, vn){vn.elm.style = _5}};let pvnode=h(vnode.sel, {key: 4});c1[_2_index]=pvnode;pvnode.data.hook = {insert(vn){let nvn=w4._mount(vnode, vn.elm);pvnode.elm=nvn.elm;},remove(){w4.destroy()},destroy(){w4.destroy()}}; w4.__owl__.pvnode = pvnode;});
|
||||
def3 = def3.then(vnode=>{vnode.data.hook = {create(_, vn){vn.elm.style = _5}};let pvnode=h(vnode.sel, {key: 4, hook: {insert(vn){let nvn=w4._mount(vnode, vn.elm);pvnode.elm=nvn.elm;},remove(){w4.destroy()},destroy(){w4.destroy()}}});c1[_2_index]=pvnode;w4.__owl__.pvnode = pvnode;});
|
||||
} else {
|
||||
if (w4.__owl__.renderPromise && sameProps4) {
|
||||
def3 = w4.__owl__.renderPromise;
|
||||
} else {
|
||||
def3 = w4._updateProps(props4, extra.forceUpdate, extra.patchQueue);
|
||||
}
|
||||
def3 = def3.then(()=>{if (w4.__owl__.isDestroyed) {return};w4.el.style=_5;let pvnode=h(w4.__owl__.pvnode.sel, {key: 4});pvnode.elm=w4.el;pvnode.data.hook = {insert(a){a.elm.parentNode.replaceChild(w4.el,a.elm);a.elm=w4.el;w4.__mount();},remove(){w4.destroy()}, destroy() {w4.destroy()}};c1[_2_index]=pvnode;});
|
||||
def3 = w4._updateProps(props4, extra.forceUpdate, extra.patchQueue);
|
||||
def3 = def3.then(()=>{if (w4.__owl__.isDestroyed) {return};w4.el.style=_5;let pvnode=w4.__owl__.pvnode;c1[_2_index]=pvnode;});
|
||||
}
|
||||
extra.promises.push(def3);
|
||||
return vn1;
|
||||
@@ -54,13 +48,11 @@ exports[`class and style attributes with t-widget t-att-class is properly added/
|
||||
const _5 = {a: context['state'].a,b: context['state'].b};
|
||||
let w4 = 4 in context.__owl__.cmap ? context.__owl__.children[context.__owl__.cmap[4]] : false;
|
||||
let props4 = {};
|
||||
let sameProps4 = w4 && props4 === w4.__owl__.renderProps
|
||||
if (w4 && w4.__owl__.renderPromise && !w4.__owl__.isStarted && !sameProps4) {
|
||||
if (w4 && w4.__owl__.renderPromise && !w4.__owl__.isStarted && props4 !== w4.__owl__.renderProps) {
|
||||
w4.destroy();
|
||||
w4 = false
|
||||
}
|
||||
let isNew4 = !w4;
|
||||
if (isNew4) {
|
||||
if (!w4) {
|
||||
let W4 = context.widgets['child'];
|
||||
if (!W4) {throw new Error(\`Cannot find the definition of widget \\"child\\"\`)}
|
||||
w4 = new W4(owner, props4);
|
||||
@@ -70,14 +62,10 @@ exports[`class and style attributes with t-widget t-att-class is properly added/
|
||||
if (_5[k]) {
|
||||
vn.elm.classList.add(k);
|
||||
}
|
||||
}}};let pvnode=h(vnode.sel, {key: 4});c1[_2_index]=pvnode;pvnode.data.hook = {insert(vn){let nvn=w4._mount(vnode, vn.elm);pvnode.elm=nvn.elm;},remove(){w4.destroy()},destroy(){w4.destroy()}}; w4.__owl__.pvnode = pvnode;});
|
||||
}}};let pvnode=h(vnode.sel, {key: 4, hook: {insert(vn){let nvn=w4._mount(vnode, vn.elm);pvnode.elm=nvn.elm;},remove(){w4.destroy()},destroy(){w4.destroy()}}});c1[_2_index]=pvnode;w4.__owl__.pvnode = pvnode;});
|
||||
} else {
|
||||
if (w4.__owl__.renderPromise && sameProps4) {
|
||||
def3 = w4.__owl__.renderPromise;
|
||||
} else {
|
||||
def3 = w4._updateProps(props4, extra.forceUpdate, extra.patchQueue);
|
||||
}
|
||||
def3 = def3.then(()=>{if (w4.__owl__.isDestroyed) {return};let cl=w4.el.classList;for (let k in _5) {if (_5[k]) {cl.add(k)} else {cl.remove(k)}}let pvnode=h(w4.__owl__.pvnode.sel, {key: 4});pvnode.elm=w4.el;pvnode.data.hook = {insert(a){a.elm.parentNode.replaceChild(w4.el,a.elm);a.elm=w4.el;w4.__mount();},remove(){w4.destroy()}, destroy() {w4.destroy()}};c1[_2_index]=pvnode;});
|
||||
def3 = w4._updateProps(props4, extra.forceUpdate, extra.patchQueue);
|
||||
def3 = def3.then(()=>{if (w4.__owl__.isDestroyed) {return};let cl=w4.el.classList;for (let k in _5) {if (_5[k]) {cl.add(k)} else {cl.remove(k)}}let pvnode=w4.__owl__.pvnode;c1[_2_index]=pvnode;});
|
||||
}
|
||||
extra.promises.push(def3);
|
||||
return vn1;
|
||||
@@ -111,26 +99,20 @@ exports[`composition sub widgets with some state rendered in a loop 1`] = `
|
||||
let def6;
|
||||
let w7 = key8 in context.__owl__.cmap ? context.__owl__.children[context.__owl__.cmap[key8]] : false;
|
||||
let props7 = {};
|
||||
let sameProps7 = w7 && props7 === w7.__owl__.renderProps
|
||||
if (w7 && w7.__owl__.renderPromise && !w7.__owl__.isStarted && !sameProps7) {
|
||||
if (w7 && w7.__owl__.renderPromise && !w7.__owl__.isStarted && props7 !== w7.__owl__.renderProps) {
|
||||
w7.destroy();
|
||||
w7 = false
|
||||
}
|
||||
let isNew7 = !w7;
|
||||
if (isNew7) {
|
||||
if (!w7) {
|
||||
let W7 = context.widgets['ChildWidget'];
|
||||
if (!W7) {throw new Error(\`Cannot find the definition of widget \\"ChildWidget\\"\`)}
|
||||
w7 = new W7(owner, props7);
|
||||
context.__owl__.cmap[key8] = w7.__owl__.id;
|
||||
def6 = w7._prepare();
|
||||
def6 = def6.then(vnode=>{let pvnode=h(vnode.sel, {key: key8});c1[_5_index]=pvnode;pvnode.data.hook = {insert(vn){let nvn=w7._mount(vnode, vn.elm);pvnode.elm=nvn.elm;},remove(){w7.destroy()},destroy(){w7.destroy()}}; w7.__owl__.pvnode = pvnode;});
|
||||
def6 = def6.then(vnode=>{let pvnode=h(vnode.sel, {key: key8, hook: {insert(vn){let nvn=w7._mount(vnode, vn.elm);pvnode.elm=nvn.elm;},remove(){w7.destroy()},destroy(){w7.destroy()}}});c1[_5_index]=pvnode;w7.__owl__.pvnode = pvnode;});
|
||||
} else {
|
||||
if (w7.__owl__.renderPromise && sameProps7) {
|
||||
def6 = w7.__owl__.renderPromise;
|
||||
} else {
|
||||
def6 = w7._updateProps(props7, extra.forceUpdate, extra.patchQueue);
|
||||
}
|
||||
def6 = def6.then(()=>{if (w7.__owl__.isDestroyed) {return};let pvnode=h(w7.__owl__.pvnode.sel, {key: key8});pvnode.elm=w7.el;pvnode.data.hook = {insert(a){a.elm.parentNode.replaceChild(w7.el,a.elm);a.elm=w7.el;w7.__mount();},remove(){w7.destroy()}, destroy() {w7.destroy()}};c1[_5_index]=pvnode;});
|
||||
def6 = w7._updateProps(props7, extra.forceUpdate, extra.patchQueue);
|
||||
def6 = def6.then(()=>{if (w7.__owl__.isDestroyed) {return};let pvnode=w7.__owl__.pvnode;c1[_5_index]=pvnode;});
|
||||
}
|
||||
extra.promises.push(def6);
|
||||
}
|
||||
@@ -152,26 +134,20 @@ exports[`random stuff/miscellaneous snapshotting compiled code 1`] = `
|
||||
let def3;
|
||||
let w4 = key5 in context.__owl__.cmap ? context.__owl__.children[context.__owl__.cmap[key5]] : false;
|
||||
let props4 = {flag: context['state'].flag};
|
||||
let sameProps4 = w4 && props4 === w4.__owl__.renderProps
|
||||
if (w4 && w4.__owl__.renderPromise && !w4.__owl__.isStarted && !sameProps4) {
|
||||
if (w4 && w4.__owl__.renderPromise && !w4.__owl__.isStarted && props4 !== w4.__owl__.renderProps) {
|
||||
w4.destroy();
|
||||
w4 = false
|
||||
}
|
||||
let isNew4 = !w4;
|
||||
if (isNew4) {
|
||||
if (!w4) {
|
||||
let W4 = context.widgets['child'];
|
||||
if (!W4) {throw new Error(\`Cannot find the definition of widget \\"child\\"\`)}
|
||||
w4 = new W4(owner, props4);
|
||||
context.__owl__.cmap[key5] = w4.__owl__.id;
|
||||
def3 = w4._prepare();
|
||||
def3 = def3.then(vnode=>{let pvnode=h(vnode.sel, {key: key5});c1[_2_index]=pvnode;pvnode.data.hook = {insert(vn){let nvn=w4._mount(vnode, vn.elm);pvnode.elm=nvn.elm;},remove(){w4.destroy()},destroy(){w4.destroy()}}; w4.__owl__.pvnode = pvnode;});
|
||||
def3 = def3.then(vnode=>{let pvnode=h(vnode.sel, {key: key5, hook: {insert(vn){let nvn=w4._mount(vnode, vn.elm);pvnode.elm=nvn.elm;},remove(){w4.destroy()},destroy(){w4.destroy()}}});c1[_2_index]=pvnode;w4.__owl__.pvnode = pvnode;});
|
||||
} else {
|
||||
if (w4.__owl__.renderPromise && sameProps4) {
|
||||
def3 = w4.__owl__.renderPromise;
|
||||
} else {
|
||||
def3 = w4._updateProps(props4, extra.forceUpdate, extra.patchQueue);
|
||||
}
|
||||
def3 = def3.then(()=>{if (w4.__owl__.isDestroyed) {return};let pvnode=h(w4.__owl__.pvnode.sel, {key: key5});pvnode.elm=w4.el;pvnode.data.hook = {insert(a){a.elm.parentNode.replaceChild(w4.el,a.elm);a.elm=w4.el;w4.__mount();},remove(){w4.destroy()}, destroy() {w4.destroy()}};c1[_2_index]=pvnode;});
|
||||
def3 = w4._updateProps(props4, extra.forceUpdate, extra.patchQueue);
|
||||
def3 = def3.then(()=>{if (w4.__owl__.isDestroyed) {return};let pvnode=w4.__owl__.pvnode;c1[_2_index]=pvnode;});
|
||||
}
|
||||
extra.promises.push(def3);
|
||||
return vn1;
|
||||
@@ -191,26 +167,20 @@ exports[`random stuff/miscellaneous t-props should not be undefined (snapshottin
|
||||
let def3;
|
||||
let w4 = 4 in context.__owl__.cmap ? context.__owl__.children[context.__owl__.cmap[4]] : false;
|
||||
let props4 = {};
|
||||
let sameProps4 = w4 && props4 === w4.__owl__.renderProps
|
||||
if (w4 && w4.__owl__.renderPromise && !w4.__owl__.isStarted && !sameProps4) {
|
||||
if (w4 && w4.__owl__.renderPromise && !w4.__owl__.isStarted && props4 !== w4.__owl__.renderProps) {
|
||||
w4.destroy();
|
||||
w4 = false
|
||||
}
|
||||
let isNew4 = !w4;
|
||||
if (isNew4) {
|
||||
if (!w4) {
|
||||
let W4 = context.widgets['child'];
|
||||
if (!W4) {throw new Error(\`Cannot find the definition of widget \\"child\\"\`)}
|
||||
w4 = new W4(owner, props4);
|
||||
context.__owl__.cmap[4] = w4.__owl__.id;
|
||||
def3 = w4._prepare();
|
||||
def3 = def3.then(vnode=>{let pvnode=h(vnode.sel, {key: 4});c1[_2_index]=pvnode;pvnode.data.hook = {insert(vn){let nvn=w4._mount(vnode, vn.elm);pvnode.elm=nvn.elm;},remove(){w4.destroy()},destroy(){w4.destroy()}}; w4.__owl__.pvnode = pvnode;});
|
||||
def3 = def3.then(vnode=>{let pvnode=h(vnode.sel, {key: 4, hook: {insert(vn){let nvn=w4._mount(vnode, vn.elm);pvnode.elm=nvn.elm;},remove(){w4.destroy()},destroy(){w4.destroy()}}});c1[_2_index]=pvnode;w4.__owl__.pvnode = pvnode;});
|
||||
} else {
|
||||
if (w4.__owl__.renderPromise && sameProps4) {
|
||||
def3 = w4.__owl__.renderPromise;
|
||||
} else {
|
||||
def3 = w4._updateProps(props4, extra.forceUpdate, extra.patchQueue);
|
||||
}
|
||||
def3 = def3.then(()=>{if (w4.__owl__.isDestroyed) {return};let pvnode=h(w4.__owl__.pvnode.sel, {key: 4});pvnode.elm=w4.el;pvnode.data.hook = {insert(a){a.elm.parentNode.replaceChild(w4.el,a.elm);a.elm=w4.el;w4.__mount();},remove(){w4.destroy()}, destroy() {w4.destroy()}};c1[_2_index]=pvnode;});
|
||||
def3 = w4._updateProps(props4, extra.forceUpdate, extra.patchQueue);
|
||||
def3 = def3.then(()=>{if (w4.__owl__.isDestroyed) {return};let pvnode=w4.__owl__.pvnode;c1[_2_index]=pvnode;});
|
||||
}
|
||||
extra.promises.push(def3);
|
||||
return vn1;
|
||||
|
||||
Reference in New Issue
Block a user