[FIX] component: call mounted hooks in subcomponent properly

order was not correct in some cases.  Also, this commit is a pretty
significant optimization.
This commit is contained in:
Géry Debongnie
2019-04-26 17:32:02 +02:00
parent 005b727328
commit b08e876136
2 changed files with 63 additions and 37 deletions
+48
View File
@@ -216,6 +216,54 @@ describe("lifecycle hooks", () => {
expect(steps).toEqual(["child:mounted", "parent:mounted"]);
});
test("mounted hook is called on subsubwidgets, in proper order", async () => {
const steps: any[] = [];
class ParentWidget extends Widget {
inlineTemplate = `<div><t t-if="state.flag"><t t-widget="child"/></t></div>`;
widgets = { child: ChildWidget };
state = { flag: false };
mounted() {
steps.push("parent:mounted");
}
willUnmount() {
steps.push("parent:willUnmount");
}
}
class ChildWidget extends Widget {
inlineTemplate = `<div><t t-widget="childchild"/></div>`;
widgets = { childchild: ChildChildWidget };
mounted() {
steps.push("child:mounted");
}
willUnmount() {
steps.push("child:willUnmount");
}
}
class ChildChildWidget extends Widget {
mounted() {
steps.push("childchild:mounted");
}
willUnmount() {
steps.push("childchild:willUnmount");
}
}
const widget = new ParentWidget(env);
await widget.mount(fixture);
expect(steps).toEqual(["parent:mounted"]);
widget.state.flag = true;
await nextTick();
widget.destroy();
expect(steps).toEqual([
"parent:mounted",
"childchild:mounted",
"child:mounted",
"parent:willUnmount",
"child:willUnmount",
"childchild:willUnmount"
]);
});
test("willStart, mounted on subwidget rendered after main is mounted in some other position", async () => {
const steps: string[] = [];