mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
rename _ into __widget__
This commit is contained in:
@@ -27,12 +27,12 @@ interface Meta<T extends WEnv> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Widget<T extends WEnv> {
|
export class Widget<T extends WEnv> {
|
||||||
_: Meta<WEnv>;
|
__widget__: Meta<WEnv>;
|
||||||
name: string = "widget";
|
name: string = "widget";
|
||||||
template: string = "<div></div>";
|
template: string = "<div></div>";
|
||||||
|
|
||||||
get el(): HTMLElement | null {
|
get el(): HTMLElement | null {
|
||||||
return this._.vnode ? (<any>this)._.vnode.elm : null;
|
return this.__widget__.vnode ? (<any>this).__widget__.vnode.elm : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
env: T;
|
env: T;
|
||||||
@@ -48,12 +48,12 @@ export class Widget<T extends WEnv> {
|
|||||||
let p: Widget<T> | null = null;
|
let p: Widget<T> | null = null;
|
||||||
if (parent instanceof Widget) {
|
if (parent instanceof Widget) {
|
||||||
p = parent;
|
p = parent;
|
||||||
parent._.children.push(this);
|
parent.__widget__.children.push(this);
|
||||||
this.env = Object.create(parent.env);
|
this.env = Object.create(parent.env);
|
||||||
} else {
|
} else {
|
||||||
this.env = parent;
|
this.env = parent;
|
||||||
}
|
}
|
||||||
this._ = {
|
this.__widget__ = {
|
||||||
id: this.env.getID(),
|
id: this.env.getID(),
|
||||||
vnode: null,
|
vnode: null,
|
||||||
isStarted: false,
|
isStarted: false,
|
||||||
@@ -82,23 +82,22 @@ export class Widget<T extends WEnv> {
|
|||||||
|
|
||||||
if (document.body.contains(target)) {
|
if (document.body.contains(target)) {
|
||||||
this.visitSubTree(w => {
|
this.visitSubTree(w => {
|
||||||
if (!w._.isMounted && this.el!.contains(w.el)) {
|
if (!w.__widget__.isMounted && this.el!.contains(w.el)) {
|
||||||
w._.isMounted = true;
|
w.__widget__.isMounted = true;
|
||||||
w.mounted();
|
w.mounted();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
return vnode;
|
return vnode;
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
if (!this._.isDestroyed) {
|
if (!this.__widget__.isDestroyed) {
|
||||||
if (this.el) {
|
if (this.el) {
|
||||||
this.el.remove();
|
this.el.remove();
|
||||||
delete this._.vnode;
|
delete this.__widget__.vnode;
|
||||||
}
|
}
|
||||||
this._.isDestroyed = true;
|
this.__widget__.isDestroyed = true;
|
||||||
this.destroyed();
|
this.destroyed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -109,7 +108,7 @@ export class Widget<T extends WEnv> {
|
|||||||
*/
|
*/
|
||||||
async updateState(newState: Object) {
|
async updateState(newState: Object) {
|
||||||
Object.assign(this.state, newState);
|
Object.assign(this.state, newState);
|
||||||
if (this._.isStarted) {
|
if (this.__widget__.isStarted) {
|
||||||
await this.render();
|
await this.render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -120,16 +119,16 @@ export class Widget<T extends WEnv> {
|
|||||||
|
|
||||||
async render(): Promise<VNode> {
|
async render(): Promise<VNode> {
|
||||||
const vnode = await this._render();
|
const vnode = await this._render();
|
||||||
this._.vnode = patch(
|
this.__widget__.vnode = patch(
|
||||||
this._.vnode || document.createElement(vnode.sel!),
|
this.__widget__.vnode || document.createElement(vnode.sel!),
|
||||||
vnode
|
vnode
|
||||||
);
|
);
|
||||||
return this._.vnode;
|
return this.__widget__.vnode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _start(): Promise<void> {
|
private async _start(): Promise<void> {
|
||||||
await this.willStart();
|
await this.willStart();
|
||||||
this._.isStarted = true;
|
this.__widget__.isStarted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _render(): Promise<VNode> {
|
private async _render(): Promise<VNode> {
|
||||||
@@ -145,7 +144,7 @@ export class Widget<T extends WEnv> {
|
|||||||
// 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._.id;
|
vnode.key = this.__widget__.id;
|
||||||
return Promise.all(promises).then(() => vnode);
|
return Promise.all(promises).then(() => vnode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,10 +152,10 @@ export class Widget<T extends WEnv> {
|
|||||||
* Only called by qweb t-widget directive
|
* Only called by qweb t-widget directive
|
||||||
*/
|
*/
|
||||||
_mount(vnode: VNode) {
|
_mount(vnode: VNode) {
|
||||||
this._.vnode = vnode;
|
this.__widget__.vnode = vnode;
|
||||||
if (this._.parent) {
|
if (this.__widget__.parent) {
|
||||||
if (this._.parent._.isMounted) {
|
if (this.__widget__.parent.__widget__.isMounted) {
|
||||||
this._.isMounted = true;
|
this.__widget__.isMounted = true;
|
||||||
this.mounted();
|
this.mounted();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,7 +163,7 @@ export class Widget<T extends WEnv> {
|
|||||||
|
|
||||||
private visitSubTree(callback: (w: Widget<T>) => void) {
|
private visitSubTree(callback: (w: Widget<T>) => void) {
|
||||||
callback(this);
|
callback(this);
|
||||||
for (let child of this._.children) {
|
for (let child of this.__widget__.children) {
|
||||||
child.visitSubTree(callback);
|
child.visitSubTree(callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -280,7 +280,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(widget._.children[0]._.parent).toBe(widget);
|
expect(widget.__widget__.children[0].__widget__.parent).toBe(widget);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("t-refs on widget are widgets", async () => {
|
test("t-refs on widget are widgets", async () => {
|
||||||
@@ -316,12 +316,12 @@ describe("composition", () => {
|
|||||||
const widget = new WidgetA(env);
|
const widget = new WidgetA(env);
|
||||||
await widget.mount(fixture);
|
await widget.mount(fixture);
|
||||||
|
|
||||||
expect((<any>widget._.vnode!.children![1]).elm).toBe(
|
expect((<any>widget.__widget__.vnode!.children![1]).elm).toBe(
|
||||||
(<any>widget._.children[0]._.vnode).elm
|
(<any>widget.__widget__.children[0].__widget__.vnode).elm
|
||||||
);
|
);
|
||||||
await widget._.children[0].render();
|
await widget.__widget__.children[0].render();
|
||||||
expect((<any>widget._.vnode!.children![1]).elm).toBe(
|
expect((<any>widget.__widget__.vnode!.children![1]).elm).toBe(
|
||||||
(<any>widget._.children[0]._.vnode).elm
|
(<any>widget.__widget__.children[0].__widget__.vnode).elm
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user