[REF] component: use __owl__ as metadata key

This commit is contained in:
Géry Debongnie
2019-04-13 14:14:34 +02:00
parent caed076f2a
commit a0f0a24d1d
5 changed files with 131 additions and 131 deletions
+51 -51
View File
@@ -51,12 +51,12 @@ export class Component<
Props extends {}, Props extends {},
State extends {} State extends {}
> extends EventBus { > extends EventBus {
readonly __widget__: Meta<Env, Props>; readonly __owl__: Meta<Env, Props>;
template: string = "default"; template: string = "default";
inlineTemplate: string | null = null; inlineTemplate: string | null = null;
get el(): HTMLElement | null { get el(): HTMLElement | null {
return this.__widget__.vnode ? (<any>this).__widget__.vnode.elm : null; return this.__owl__.vnode ? (<any>this).__owl__.vnode.elm : null;
} }
env: T; env: T;
@@ -102,11 +102,11 @@ export class Component<
if (parent instanceof Component) { if (parent instanceof Component) {
p = parent; p = parent;
this.env = parent.env; this.env = parent.env;
parent.__widget__.children[id] = this; parent.__owl__.children[id] = this;
} else { } else {
this.env = parent; this.env = parent;
} }
this.__widget__ = { this.__owl__ = {
id: id, id: id,
vnode: null, vnode: null,
isStarted: false, isStarted: false,
@@ -221,7 +221,7 @@ export class Component<
async mount(target: HTMLElement): Promise<void> { async mount(target: HTMLElement): Promise<void> {
const vnode = await this._prepare(); const vnode = await this._prepare();
if (this.__widget__.isDestroyed) { if (this.__owl__.isDestroyed) {
// widget was destroyed before we get here... // widget was destroyed before we get here...
return; return;
} }
@@ -230,8 +230,8 @@ export class Component<
if (document.body.contains(target)) { if (document.body.contains(target)) {
this._visitSubTree(w => { this._visitSubTree(w => {
if (!w.__widget__.isMounted && this.el!.contains(w.el)) { if (!w.__owl__.isMounted && this.el!.contains(w.el)) {
w.__widget__.isMounted = true; w.__owl__.isMounted = true;
w.mounted(); w.mounted();
return true; return true;
} }
@@ -243,9 +243,9 @@ export class Component<
unmount() { unmount() {
if (this.el) { if (this.el) {
this._visitSubTree(w => { this._visitSubTree(w => {
if (w.__widget__.isMounted) { if (w.__owl__.isMounted) {
w.willUnmount(); w.willUnmount();
w.__widget__.isMounted = false; w.__owl__.isMounted = false;
return true; return true;
} }
return false; return false;
@@ -255,13 +255,13 @@ export class Component<
} }
async render(force: boolean = false): Promise<void> { async render(force: boolean = false): Promise<void> {
if (this.__widget__.isDestroyed) { if (this.__owl__.isDestroyed) {
return; return;
} }
const renderVDom = this._render(force); const renderVDom = this._render(force);
const renderId = this.__widget__.renderId; const renderId = this.__owl__.renderId;
const vnode = await renderVDom; const vnode = await renderVDom;
if (renderId === this.__widget__.renderId) { if (renderId === this.__owl__.renderId) {
// we only update the vnode and the actual DOM if no other rendering // we only update the vnode and the actual DOM if no other rendering
// occurred between now and when the render method was initially called. // occurred between now and when the render method was initially called.
this._patch(vnode); this._patch(vnode);
@@ -269,25 +269,25 @@ export class Component<
} }
destroy() { destroy() {
if (!this.__widget__.isDestroyed) { if (!this.__owl__.isDestroyed) {
for (let id in this.__widget__.children) { for (let id in this.__owl__.children) {
this.__widget__.children[id].destroy(); this.__owl__.children[id].destroy();
} }
if (this.__widget__.isMounted) { if (this.__owl__.isMounted) {
this.willUnmount(); this.willUnmount();
} }
if (this.el) { if (this.el) {
this.el.remove(); this.el.remove();
this.__widget__.isMounted = false; this.__owl__.isMounted = false;
delete this.__widget__.vnode; delete this.__owl__.vnode;
} }
if (this.__widget__.parent) { if (this.__owl__.parent) {
let id = this.__widget__.id; let id = this.__owl__.id;
delete this.__widget__.parent.__widget__.children[id]; delete this.__owl__.parent.__owl__.children[id];
this.__widget__.parent = null; this.__owl__.parent = null;
} }
this.clear(); this.clear();
this.__widget__.isDestroyed = true; this.__owl__.isDestroyed = true;
} }
} }
@@ -305,11 +305,11 @@ export class Component<
* mode or not. * mode or not.
*/ */
async updateEnv(nextEnv: Partial<T>): Promise<void> { async updateEnv(nextEnv: Partial<T>): Promise<void> {
if (this.__widget__.parent && this.__widget__.parent.env === this.env) { if (this.__owl__.parent && this.__owl__.parent.env === this.env) {
this.env = Object.create(this.env); this.env = Object.create(this.env);
} }
Object.assign(this.env, nextEnv); Object.assign(this.env, nextEnv);
if (this.__widget__.isMounted) { if (this.__owl__.isMounted) {
await this.render(true); await this.render(true);
} }
this.patched(); this.patched();
@@ -319,8 +319,8 @@ export class Component<
nextProps: Props, nextProps: Props,
forceUpdate: boolean = false forceUpdate: boolean = false
): Promise<void> { ): Promise<void> {
if (nextProps === this.__widget__.renderProps && !forceUpdate) { if (nextProps === this.__owl__.renderProps && !forceUpdate) {
await this.__widget__.renderPromise; await this.__owl__.renderPromise;
return; return;
} }
const shouldUpdate = forceUpdate || this.shouldUpdate(nextProps); const shouldUpdate = forceUpdate || this.shouldUpdate(nextProps);
@@ -341,7 +341,7 @@ export class Component<
return; return;
} }
Object.assign(this.state, nextState); Object.assign(this.state, nextState);
if (this.__widget__.isStarted) { if (this.__owl__.isStarted) {
await this.render(); await this.render();
} }
this.patched(); this.patched();
@@ -359,21 +359,21 @@ export class Component<
} }
_patch(vnode) { _patch(vnode) {
this.__widget__.renderPromise = null; this.__owl__.renderPromise = null;
if (this.__widget__.vnode) { if (this.__owl__.vnode) {
this.willPatch(); this.willPatch();
this.__widget__.vnode = patch(this.__widget__.vnode, vnode); this.__owl__.vnode = patch(this.__owl__.vnode, vnode);
} else { } else {
this.__widget__.vnode = patch(document.createElement(vnode.sel!), vnode); this.__owl__.vnode = patch(document.createElement(vnode.sel!), vnode);
} }
} }
async _prepare(): Promise<VNode> { async _prepare(): Promise<VNode> {
this.__widget__.renderProps = this.props; this.__owl__.renderProps = this.props;
this.__widget__.renderPromise = this.willStart().then(() => { this.__owl__.renderPromise = this.willStart().then(() => {
if (this.__widget__.isDestroyed) { if (this.__owl__.isDestroyed) {
return Promise.resolve(h("div")); return Promise.resolve(h("div"));
} }
this.__widget__.isStarted = true; this.__owl__.isStarted = true;
if (this.inlineTemplate) { if (this.inlineTemplate) {
this.env.qweb.addTemplate( this.env.qweb.addTemplate(
this.inlineTemplate, this.inlineTemplate,
@@ -383,16 +383,16 @@ export class Component<
} }
return this._render(); return this._render();
}); });
return this.__widget__.renderPromise; return this.__owl__.renderPromise;
} }
async _render(force: boolean = false): Promise<VNode> { async _render(force: boolean = false): Promise<VNode> {
this.__widget__.renderId++; this.__owl__.renderId++;
const promises: Promise<void>[] = []; const promises: Promise<void>[] = [];
const template = this.inlineTemplate || this.template; const template = this.inlineTemplate || this.template;
let vnode = this.env.qweb.render(template, this, { let vnode = this.env.qweb.render(template, this, {
promises, promises,
handlers: this.__widget__.boundHandlers, handlers: this.__owl__.boundHandlers,
forceUpdate: force forceUpdate: force
}); });
@@ -401,30 +401,30 @@ export class Component<
// will update its own vnode representation without the knowledge of the // will update its own vnode representation without the knowledge of the
// parent widget. With this, we make sure that the parent widget will be // parent widget. With this, we make sure that the parent widget will be
// able to patch itself properly after // able to patch itself properly after
vnode.key = this.__widget__.id; vnode.key = this.__owl__.id;
this.__widget__.renderProps = this.props; this.__owl__.renderProps = this.props;
this.__widget__.renderPromise = Promise.all(promises).then(() => vnode); this.__owl__.renderPromise = Promise.all(promises).then(() => vnode);
return this.__widget__.renderPromise; return this.__owl__.renderPromise;
} }
/** /**
* Only called by qweb t-widget directive * Only called by qweb t-widget directive
*/ */
_mount(vnode: VNode, elm: HTMLElement): VNode { _mount(vnode: VNode, elm: HTMLElement): VNode {
this.__widget__.vnode = patch(elm, vnode); this.__owl__.vnode = patch(elm, vnode);
this.__mount(); this.__mount();
return this.__widget__.vnode; return this.__owl__.vnode;
} }
__mount() { __mount() {
if (this.__widget__.isMounted) { if (this.__owl__.isMounted) {
return; return;
} }
if (this.__widget__.parent) { if (this.__owl__.parent) {
if (this.__widget__.parent!.__widget__.isMounted) { if (this.__owl__.parent!.__owl__.isMounted) {
this.__widget__.isMounted = true; this.__owl__.isMounted = true;
this.mounted(); this.mounted();
const children = this.__widget__.children; const children = this.__owl__.children;
for (let id in children) { for (let id in children) {
children[id].__mount(); children[id].__mount();
} }
@@ -435,7 +435,7 @@ export class Component<
_visitSubTree(callback: (w: Component<T, any, any>) => boolean) { _visitSubTree(callback: (w: Component<T, any, any>) => boolean) {
const shouldVisitChildren = callback(this); const shouldVisitChildren = callback(this);
if (shouldVisitChildren) { if (shouldVisitChildren) {
const children = this.__widget__.children; const children = this.__owl__.children;
for (let id in children) { for (let id in children) {
children[id]._visitSubTree(callback); children[id]._visitSubTree(callback);
} }
+8 -8
View File
@@ -960,21 +960,21 @@ const widgetDirective: Directive = {
? `String(-${widgetID} - i)` ? `String(-${widgetID} - i)`
: String(widgetID); : String(widgetID);
ctx.addLine( ctx.addLine(
`let w${widgetID} = ${templateID} in context.__widget__.cmap ? context.__widget__.children[context.__widget__.cmap[${templateID}]] : false;` `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 props${widgetID} = ${props || "{}"};`);
ctx.addLine(`let isNew${widgetID} = !w${widgetID};`); ctx.addLine(`let isNew${widgetID} = !w${widgetID};`);
// check if we can reuse current rendering promise // check if we can reuse current rendering promise
ctx.addIf(`w${widgetID} && w${widgetID}.__widget__.renderPromise`); ctx.addIf(`w${widgetID} && w${widgetID}.__owl__.renderPromise`);
ctx.addIf(`w${widgetID}.__widget__.isStarted`); ctx.addIf(`w${widgetID}.__owl__.isStarted`);
ctx.addLine( ctx.addLine(
`def${defID} = w${widgetID}.updateProps(props${widgetID}, extra.forceUpdate);` `def${defID} = w${widgetID}.updateProps(props${widgetID}, extra.forceUpdate);`
); );
ctx.addElse(); ctx.addElse();
ctx.addLine(`isNew${widgetID} = true`); ctx.addLine(`isNew${widgetID} = true`);
ctx.addIf(`props${widgetID} === w${widgetID}.__widget__.renderProps`); ctx.addIf(`props${widgetID} === w${widgetID}.__owl__.renderProps`);
ctx.addLine(`def${defID} = w${widgetID}.__widget__.renderPromise;`); ctx.addLine(`def${defID} = w${widgetID}.__owl__.renderPromise;`);
ctx.addElse(); ctx.addElse();
ctx.addLine(`w${widgetID}.destroy();`); ctx.addLine(`w${widgetID}.destroy();`);
ctx.addLine(`w${widgetID} = false`); ctx.addLine(`w${widgetID} = false`);
@@ -992,7 +992,7 @@ const widgetDirective: Directive = {
`w${widgetID} = new context.widgets['${value}'](owner, props${widgetID});` `w${widgetID} = new context.widgets['${value}'](owner, props${widgetID});`
); );
ctx.addLine( ctx.addLine(
`context.__widget__.cmap[${templateID}] = w${widgetID}.__widget__.id;` `context.__owl__.cmap[${templateID}] = w${widgetID}.__owl__.id;`
); );
for (let [event, method] of events) { for (let [event, method] of events) {
ctx.addLine(`w${widgetID}.on('${event}', owner, owner['${method}'])`); ctx.addLine(`w${widgetID}.on('${event}', owner, owner['${method}'])`);
@@ -1014,11 +1014,11 @@ const widgetDirective: Directive = {
keepAlive ? "unmount" : "destroy" keepAlive ? "unmount" : "destroy"
}()},destroy(){w${widgetID}.${ }()},destroy(){w${widgetID}.${
keepAlive ? "unmount" : "destroy" keepAlive ? "unmount" : "destroy"
}()}}; w${widgetID}.__widget__.pvnode = pvnode;});` }()}}; w${widgetID}.__owl__.pvnode = pvnode;});`
); );
ctx.addElse(); ctx.addElse();
ctx.addLine( ctx.addLine(
`def${defID} = def${defID}.then(()=>{if (w${widgetID}.__widget__.isDestroyed) {return};let vnode;if (!w${widgetID}.__widget__.vnode){vnode=w${widgetID}.__widget__.pvnode} else { vnode=h(w${widgetID}.__widget__.vnode.sel, {key: ${templateID}});vnode.elm=w${widgetID}.el;vnode.data.hook = {insert(a){a.elm.parentNode.replaceChild(w${widgetID}.el,a.elm);a.elm=w${widgetID}.el;w${widgetID}.__mount();},remove(){w${widgetID}.${ `def${defID} = def${defID}.then(()=>{if (w${widgetID}.__owl__.isDestroyed) {return};let vnode;if (!w${widgetID}.__owl__.vnode){vnode=w${widgetID}.__owl__.pvnode} else { vnode=h(w${widgetID}.__owl__.vnode.sel, {key: ${templateID}});vnode.elm=w${widgetID}.el;vnode.data.hook = {insert(a){a.elm.parentNode.replaceChild(w${widgetID}.el,a.elm);a.elm=w${widgetID}.el;w${widgetID}.__mount();},remove(){w${widgetID}.${
keepAlive ? "unmount" : "destroy" keepAlive ? "unmount" : "destroy"
}()}, destroy() {w${widgetID}.${keepAlive ? "unmount" : "destroy"}()}}}c${ }()}, destroy() {w${widgetID}.${keepAlive ? "unmount" : "destroy"}()}}}c${
ctx.parentNode ctx.parentNode
+16 -16
View File
@@ -227,12 +227,12 @@ export function makeObserver(): Observer {
// Connect function // Connect function
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
function setStoreProps(__widget__: any, storeProps: any) { function setStoreProps(__owl__: any, storeProps: any) {
__widget__.currentStoreProps = storeProps; __owl__.currentStoreProps = storeProps;
__widget__.currentStoreRevs = {}; __owl__.currentStoreRevs = {};
__widget__.currentStoreRev = storeProps.__rev__; __owl__.currentStoreRev = storeProps.__rev__;
for (let key in storeProps) { for (let key in storeProps) {
__widget__.currentStoreRevs[key] = storeProps[key].__rev__; __owl__.currentStoreRevs[key] = storeProps[key].__rev__;
} }
} }
@@ -245,25 +245,25 @@ export function connect(mapStateToProps) {
const storeProps = mapStateToProps(env.store.state, ownProps); const storeProps = mapStateToProps(env.store.state, ownProps);
const mergedProps = Object.assign({}, props || {}, storeProps); const mergedProps = Object.assign({}, props || {}, storeProps);
super(parent, mergedProps); super(parent, mergedProps);
setStoreProps(this.__widget__, storeProps); setStoreProps(this.__owl__, storeProps);
this.__widget__.ownProps = ownProps; this.__owl__.ownProps = ownProps;
} }
mounted() { mounted() {
this.env.store.on("update", this, () => { this.env.store.on("update", this, () => {
const ownProps = this.__widget__.ownProps; const ownProps = this.__owl__.ownProps;
const storeProps = mapStateToProps(this.env.store.state, ownProps); const storeProps = mapStateToProps(this.env.store.state, ownProps);
let didChange = false; let didChange = false;
if (this.__widget__.currentStoreRev !== storeProps.__rev__) { if (this.__owl__.currentStoreRev !== storeProps.__rev__) {
setStoreProps(this.__widget__, storeProps); setStoreProps(this.__owl__, storeProps);
didChange = true; didChange = true;
} else { } else {
const revs = this.__widget__.currentStoreRevs; const revs = this.__owl__.currentStoreRevs;
for (let key in storeProps) { for (let key in storeProps) {
const val = storeProps[key]; const val = storeProps[key];
if (val.__rev__ !== revs[key]) { if (val.__rev__ !== revs[key]) {
didChange = true; didChange = true;
revs[key] = val.__rev__; revs[key] = val.__rev__;
this.__widget__.currentStoreProps[key] = val; this.__owl__.currentStoreProps[key] = val;
} }
} }
} }
@@ -278,17 +278,17 @@ export function connect(mapStateToProps) {
super.willUnmount(); super.willUnmount();
} }
updateProps(nextProps, forceUpdate) { updateProps(nextProps, forceUpdate) {
if (this.__widget__.ownProps !== nextProps) { if (this.__owl__.ownProps !== nextProps) {
this.__widget__.currentStoreProps = mapStateToProps( this.__owl__.currentStoreProps = mapStateToProps(
this.env.store.state, this.env.store.state,
nextProps nextProps
); );
} }
this.__widget__.ownProps = nextProps; this.__owl__.ownProps = nextProps;
const mergedProps = Object.assign( const mergedProps = Object.assign(
{}, {},
nextProps, nextProps,
this.__widget__.currentStoreProps this.__owl__.currentStoreProps
); );
return super.updateProps(mergedProps, forceUpdate); return super.updateProps(mergedProps, forceUpdate);
} }
+24 -24
View File
@@ -25,16 +25,16 @@ exports[`composition sub widgets with some state rendered in a loop 1`] = `
let _5_index = c1.length; let _5_index = c1.length;
c1.push(null); c1.push(null);
let def6; let def6;
let w7 = key8 in context.__widget__.cmap ? context.__widget__.children[context.__widget__.cmap[key8]] : false; let w7 = key8 in context.__owl__.cmap ? context.__owl__.children[context.__owl__.cmap[key8]] : false;
let props7 = {}; let props7 = {};
let isNew7 = !w7; let isNew7 = !w7;
if (w7 && w7.__widget__.renderPromise) { if (w7 && w7.__owl__.renderPromise) {
if (w7.__widget__.isStarted) { if (w7.__owl__.isStarted) {
def6 = w7.updateProps(props7, extra.forceUpdate); def6 = w7.updateProps(props7, extra.forceUpdate);
} else { } else {
isNew7 = true isNew7 = true
if (props7 === w7.__widget__.renderProps) { if (props7 === w7.__owl__.renderProps) {
def6 = w7.__widget__.renderPromise; def6 = w7.__owl__.renderPromise;
} else { } else {
w7.destroy(); w7.destroy();
w7 = false w7 = false
@@ -46,14 +46,14 @@ exports[`composition sub widgets with some state rendered in a loop 1`] = `
def6 = w7.updateProps(props7, extra.forceUpdate); def6 = w7.updateProps(props7, extra.forceUpdate);
} else { } else {
w7 = new context.widgets['ChildWidget'](owner, props7); w7 = new context.widgets['ChildWidget'](owner, props7);
context.__widget__.cmap[key8] = w7.__widget__.id; context.__owl__.cmap[key8] = w7.__owl__.id;
def6 = w7._prepare(); def6 = w7._prepare();
} }
} }
if (isNew7) { if (isNew7) {
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.__widget__.pvnode = pvnode;}); 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;});
} else { } else {
def6 = def6.then(()=>{if (w7.__widget__.isDestroyed) {return};let vnode;if (!w7.__widget__.vnode){vnode=w7.__widget__.pvnode} else { vnode=h(w7.__widget__.vnode.sel, {key: key8});vnode.elm=w7.el;vnode.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]=vnode;}); def6 = def6.then(()=>{if (w7.__owl__.isDestroyed) {return};let vnode;if (!w7.__owl__.vnode){vnode=w7.__owl__.pvnode} else { vnode=h(w7.__owl__.vnode.sel, {key: key8});vnode.elm=w7.el;vnode.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]=vnode;});
} }
extra.promises.push(def6); extra.promises.push(def6);
} }
@@ -73,16 +73,16 @@ exports[`random stuff/miscellaneous snapshotting compiled code 1`] = `
let _2_index = c1.length; let _2_index = c1.length;
c1.push(null); c1.push(null);
let def3; let def3;
let w4 = key5 in context.__widget__.cmap ? context.__widget__.children[context.__widget__.cmap[key5]] : false; let w4 = key5 in context.__owl__.cmap ? context.__owl__.children[context.__owl__.cmap[key5]] : false;
let props4 = {flag: context['state'].flag}; let props4 = {flag: context['state'].flag};
let isNew4 = !w4; let isNew4 = !w4;
if (w4 && w4.__widget__.renderPromise) { if (w4 && w4.__owl__.renderPromise) {
if (w4.__widget__.isStarted) { if (w4.__owl__.isStarted) {
def3 = w4.updateProps(props4, extra.forceUpdate); def3 = w4.updateProps(props4, extra.forceUpdate);
} else { } else {
isNew4 = true isNew4 = true
if (props4 === w4.__widget__.renderProps) { if (props4 === w4.__owl__.renderProps) {
def3 = w4.__widget__.renderPromise; def3 = w4.__owl__.renderPromise;
} else { } else {
w4.destroy(); w4.destroy();
w4 = false w4 = false
@@ -94,14 +94,14 @@ exports[`random stuff/miscellaneous snapshotting compiled code 1`] = `
def3 = w4.updateProps(props4, extra.forceUpdate); def3 = w4.updateProps(props4, extra.forceUpdate);
} else { } else {
w4 = new context.widgets['child'](owner, props4); w4 = new context.widgets['child'](owner, props4);
context.__widget__.cmap[key5] = w4.__widget__.id; context.__owl__.cmap[key5] = w4.__owl__.id;
def3 = w4._prepare(); def3 = w4._prepare();
} }
} }
if (isNew4) { if (isNew4) {
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.__widget__.pvnode = pvnode;}); 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;});
} else { } else {
def3 = def3.then(()=>{if (w4.__widget__.isDestroyed) {return};let vnode;if (!w4.__widget__.vnode){vnode=w4.__widget__.pvnode} else { vnode=h(w4.__widget__.vnode.sel, {key: key5});vnode.elm=w4.el;vnode.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]=vnode;}); def3 = def3.then(()=>{if (w4.__owl__.isDestroyed) {return};let vnode;if (!w4.__owl__.vnode){vnode=w4.__owl__.pvnode} else { vnode=h(w4.__owl__.vnode.sel, {key: key5});vnode.elm=w4.el;vnode.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]=vnode;});
} }
extra.promises.push(def3); extra.promises.push(def3);
return vn1; return vn1;
@@ -119,16 +119,16 @@ exports[`random stuff/miscellaneous t-props should not be undefined (snapshottin
let _2_index = c1.length; let _2_index = c1.length;
c1.push(null); c1.push(null);
let def3; let def3;
let w4 = 4 in context.__widget__.cmap ? context.__widget__.children[context.__widget__.cmap[4]] : false; let w4 = 4 in context.__owl__.cmap ? context.__owl__.children[context.__owl__.cmap[4]] : false;
let props4 = {}; let props4 = {};
let isNew4 = !w4; let isNew4 = !w4;
if (w4 && w4.__widget__.renderPromise) { if (w4 && w4.__owl__.renderPromise) {
if (w4.__widget__.isStarted) { if (w4.__owl__.isStarted) {
def3 = w4.updateProps(props4, extra.forceUpdate); def3 = w4.updateProps(props4, extra.forceUpdate);
} else { } else {
isNew4 = true isNew4 = true
if (props4 === w4.__widget__.renderProps) { if (props4 === w4.__owl__.renderProps) {
def3 = w4.__widget__.renderPromise; def3 = w4.__owl__.renderPromise;
} else { } else {
w4.destroy(); w4.destroy();
w4 = false w4 = false
@@ -140,14 +140,14 @@ exports[`random stuff/miscellaneous t-props should not be undefined (snapshottin
def3 = w4.updateProps(props4, extra.forceUpdate); def3 = w4.updateProps(props4, extra.forceUpdate);
} else { } else {
w4 = new context.widgets['child'](owner, props4); w4 = new context.widgets['child'](owner, props4);
context.__widget__.cmap[4] = w4.__widget__.id; context.__owl__.cmap[4] = w4.__owl__.id;
def3 = w4._prepare(); def3 = w4._prepare();
} }
} }
if (isNew4) { if (isNew4) {
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.__widget__.pvnode = pvnode;}); 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;});
} else { } else {
def3 = def3.then(()=>{if (w4.__widget__.isDestroyed) {return};let vnode;if (!w4.__widget__.vnode){vnode=w4.__widget__.pvnode} else { vnode=h(w4.__widget__.vnode.sel, {key: 4});vnode.elm=w4.el;vnode.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]=vnode;}); def3 = def3.then(()=>{if (w4.__owl__.isDestroyed) {return};let vnode;if (!w4.__owl__.vnode){vnode=w4.__owl__.pvnode} else { vnode=h(w4.__owl__.vnode.sel, {key: 4});vnode.elm=w4.el;vnode.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]=vnode;});
} }
extra.promises.push(def3); extra.promises.push(def3);
return vn1; return vn1;
+32 -32
View File
@@ -39,7 +39,7 @@ afterEach(() => {
class Widget extends Component<any, any, any> {} class Widget extends Component<any, any, any> {}
function children(w: Widget): Widget[] { function children(w: Widget): Widget[] {
const childrenMap = w.__widget__.children; const childrenMap = w.__owl__.children;
return Object.keys(childrenMap).map(id => childrenMap[id]); return Object.keys(childrenMap).map(id => childrenMap[id]);
} }
@@ -585,8 +585,8 @@ describe("destroy method", () => {
expect(document.contains(widget.el)).toBe(true); expect(document.contains(widget.el)).toBe(true);
widget.destroy(); widget.destroy();
expect(document.contains(widget.el)).toBe(false); expect(document.contains(widget.el)).toBe(false);
expect(widget.__widget__.isMounted).toBe(false); expect(widget.__owl__.isMounted).toBe(false);
expect(widget.__widget__.isDestroyed).toBe(true); expect(widget.__owl__.isDestroyed).toBe(true);
}); });
test("destroying a parent also destroys its children", async () => { test("destroying a parent also destroys its children", async () => {
@@ -595,9 +595,9 @@ describe("destroy method", () => {
const child = children(parent)[0]; const child = children(parent)[0];
expect(child.__widget__.isDestroyed).toBe(false); expect(child.__owl__.isDestroyed).toBe(false);
parent.destroy(); parent.destroy();
expect(child.__widget__.isDestroyed).toBe(true); expect(child.__owl__.isDestroyed).toBe(true);
}); });
test("destroy remove the parent/children link", async () => { test("destroy remove the parent/children link", async () => {
@@ -605,10 +605,10 @@ describe("destroy method", () => {
await parent.mount(fixture); await parent.mount(fixture);
const child = children(parent)[0]; const child = children(parent)[0];
expect(child.__widget__.parent).toBe(parent); expect(child.__owl__.parent).toBe(parent);
expect(children(parent).length).toBe(1); expect(children(parent).length).toBe(1);
child.destroy(); child.destroy();
expect(child.__widget__.parent).toBe(null); expect(child.__owl__.parent).toBe(null);
expect(children(parent).length).toBe(0); expect(children(parent).length).toBe(0);
}); });
@@ -623,20 +623,20 @@ describe("destroy method", () => {
expect(fixture.innerHTML).toBe(""); expect(fixture.innerHTML).toBe("");
const widget = new DelayedWidget(env); const widget = new DelayedWidget(env);
widget.mount(fixture); widget.mount(fixture);
expect(widget.__widget__.isStarted).toBe(false); expect(widget.__owl__.isStarted).toBe(false);
expect(widget.__widget__.isMounted).toBe(false); expect(widget.__owl__.isMounted).toBe(false);
expect(widget.__widget__.isDestroyed).toBe(false); expect(widget.__owl__.isDestroyed).toBe(false);
widget.destroy(); widget.destroy();
expect(widget.__widget__.isMounted).toBe(false); expect(widget.__owl__.isMounted).toBe(false);
expect(widget.__widget__.isStarted).toBe(false); expect(widget.__owl__.isStarted).toBe(false);
expect(widget.__widget__.isDestroyed).toBe(true); expect(widget.__owl__.isDestroyed).toBe(true);
def.resolve(); def.resolve();
await nextTick(); await nextTick();
expect(widget.__widget__.isStarted).toBe(false); expect(widget.__owl__.isStarted).toBe(false);
expect(widget.__widget__.isMounted).toBe(false); expect(widget.__owl__.isMounted).toBe(false);
expect(widget.__widget__.isDestroyed).toBe(true); expect(widget.__owl__.isDestroyed).toBe(true);
expect(widget.__widget__.vnode).toBe(null); expect(widget.__owl__.vnode).toBe(null);
expect(fixture.innerHTML).toBe(""); expect(fixture.innerHTML).toBe("");
expect(isRendered).toBe(false); expect(isRendered).toBe(false);
}); });
@@ -647,7 +647,7 @@ describe("composition", () => {
const widget = new WidgetA(env); const widget = new WidgetA(env);
await widget.mount(fixture); await widget.mount(fixture);
expect(fixture.innerHTML).toBe("<div>Hello<div>world</div></div>"); expect(fixture.innerHTML).toBe("<div>Hello<div>world</div></div>");
expect(children(widget)[0].__widget__.parent).toBe(widget); expect(children(widget)[0].__owl__.parent).toBe(widget);
}); });
test("t-refs on widget are widgets", async () => { test("t-refs on widget are widgets", async () => {
@@ -682,12 +682,12 @@ describe("composition", () => {
const widget = new WidgetA(env); const widget = new WidgetA(env);
await widget.mount(fixture); await widget.mount(fixture);
expect((<any>widget.__widget__.vnode!.children![1]).elm).toBe( expect((<any>widget.__owl__.vnode!.children![1]).elm).toBe(
(<any>children(widget)[0].__widget__.vnode).elm (<any>children(widget)[0].__owl__.vnode).elm
); );
await children(widget)[0].render(); await children(widget)[0].render();
expect((<any>widget.__widget__.vnode!.children![1]).elm).toBe( expect((<any>widget.__owl__.vnode!.children![1]).elm).toBe(
(<any>children(widget)[0].__widget__.vnode).elm (<any>children(widget)[0].__owl__.vnode).elm
); );
}); });
@@ -754,12 +754,12 @@ describe("composition", () => {
"<div><div>1<button>Inc</button></div></div>" "<div><div>1<button>Inc</button></div></div>"
); );
const counter = children(widget)[0]; const counter = children(widget)[0];
expect(counter.__widget__.isMounted).toBe(true); expect(counter.__owl__.isMounted).toBe(true);
await widget.updateState({ ok: false }); await widget.updateState({ ok: false });
expect(fixture.innerHTML).toBe("<div></div>"); expect(fixture.innerHTML).toBe("<div></div>");
expect(counter.__widget__.isMounted).toBe(false); expect(counter.__owl__.isMounted).toBe(false);
await widget.updateState({ ok: true }); await widget.updateState({ ok: true });
expect(counter.__widget__.isMounted).toBe(true); expect(counter.__owl__.isMounted).toBe(true);
expect(fixture.innerHTML).toBe( expect(fixture.innerHTML).toBe(
"<div><div>1<button>Inc</button></div></div>" "<div><div>1<button>Inc</button></div></div>"
); );
@@ -878,7 +878,7 @@ describe("composition", () => {
const child = children(parent)[0]; const child = children(parent)[0];
await parent.updateState({ flag: true }); await parent.updateState({ flag: true });
expect(children(parent)[0]).toBe(child); expect(children(parent)[0]).toBe(child);
expect(child.__widget__.isDestroyed).toBe(false); expect(child.__owl__.isDestroyed).toBe(false);
expect(normalize(fixture.innerHTML)).toBe( expect(normalize(fixture.innerHTML)).toBe(
normalize(` normalize(`
<div> <div>
@@ -1125,15 +1125,15 @@ describe("async rendering", () => {
} }
const w = new W(env); const w = new W(env);
w.mount(fixture); w.mount(fixture);
expect(w.__widget__.isDestroyed).toBe(false); expect(w.__owl__.isDestroyed).toBe(false);
expect(w.__widget__.isMounted).toBe(false); expect(w.__owl__.isMounted).toBe(false);
expect(w.__widget__.isStarted).toBe(false); expect(w.__owl__.isStarted).toBe(false);
w.destroy(); w.destroy();
def.resolve(); def.resolve();
await nextTick(); await nextTick();
expect(w.__widget__.isDestroyed).toBe(true); expect(w.__owl__.isDestroyed).toBe(true);
expect(w.__widget__.isMounted).toBe(false); expect(w.__owl__.isMounted).toBe(false);
expect(w.__widget__.isStarted).toBe(false); expect(w.__owl__.isStarted).toBe(false);
}); });
test("destroying/recreating a subwidget with different props (if start is not over)", async () => { test("destroying/recreating a subwidget with different props (if start is not over)", async () => {