rem: remove destroyed hook

This commit is contained in:
Géry Debongnie
2019-04-10 09:35:20 +02:00
parent 74ce6a671e
commit f960149ba2
4 changed files with 3 additions and 58 deletions
-1
View File
@@ -41,7 +41,6 @@ component:
- **[willPatch](#willPatch)**
- **[updated](#updated)**
- **[willUnmount](#willUnmount)**
- **[destroyed](#destroyed)**
Note: no hook method should ever be called manually. They are supposed to be
called by the owl framework whenever it is required.
-9
View File
@@ -197,14 +197,6 @@ export class Component<
*/
willUnmount() {}
/**
* destroyed is a hook called exactly once, when a component is destroyed.
* When a component is destroyed, its children will be destroyed first.
*
* Note: this method should not be called manually.
*/
destroyed() {}
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
@@ -296,7 +288,6 @@ export class Component<
}
this.clear();
this.__widget__.isDestroyed = true;
this.destroyed();
}
}
+2 -40
View File
@@ -312,21 +312,12 @@ describe("lifecycle hooks", () => {
willUnmount() {
steps.push("willunmount");
}
destroyed() {
steps.push("destroyed");
}
}
const widget = new ParentWidget(env);
await widget.mount(fixture);
expect(steps).toEqual(["init", "willstart", "mounted"]);
await widget.updateState({ ok: false });
expect(steps).toEqual([
"init",
"willstart",
"mounted",
"willunmount",
"destroyed"
]);
expect(steps).toEqual(["init", "willstart", "mounted", "willunmount"]);
});
test("widgets are unmounted and destroyed if no longer in DOM, even after updateprops", async () => {
@@ -388,9 +379,6 @@ describe("lifecycle hooks", () => {
willUnmount() {
steps.push("p willunmount");
}
destroyed() {
steps.push("p destroyed");
}
}
class ChildWidget extends Widget {
@@ -407,9 +395,6 @@ describe("lifecycle hooks", () => {
willUnmount() {
steps.push("c willunmount");
}
destroyed() {
steps.push("c destroyed");
}
}
const widget = new ParentWidget(env);
await widget.mount(fixture);
@@ -422,9 +407,7 @@ describe("lifecycle hooks", () => {
"p mounted",
"c mounted",
"c willunmount",
"c destroyed",
"p willunmount",
"p destroyed"
"p willunmount"
]);
});
@@ -523,7 +506,6 @@ describe("lifecycle hooks", () => {
});
test("sub widget (inside sub node): hooks are correctly called", async () => {
let destroyed = false;
let created = false;
let mounted = false;
class ParentWidget extends Widget {
@@ -545,9 +527,6 @@ describe("lifecycle hooks", () => {
mounted() {
mounted = true;
}
destroyed() {
destroyed = true;
}
}
const widget = new ParentWidget(env);
await widget.mount(fixture);
@@ -556,9 +535,7 @@ describe("lifecycle hooks", () => {
await widget.updateState({ flag: true });
expect(mounted).toBe(true);
expect(created).toBe(true);
expect(destroyed).toBe(false);
await widget.updateState({ flag: false });
expect(destroyed).toBe(true);
});
test("willPatch/patched hook", async () => {
@@ -612,21 +589,6 @@ describe("destroy method", () => {
expect(widget.__widget__.isDestroyed).toBe(true);
});
test("destroying a widget twice only call destroyed once", async () => {
let count = 0;
class TestWidget extends Widget {
destroyed() {
count++;
}
}
const widget = new TestWidget(env);
await widget.mount(fixture);
widget.destroy();
expect(count).toBe(1);
widget.destroy();
expect(count).toBe(1);
});
test("destroying a parent also destroys its children", async () => {
const parent = new WidgetA(env);
await parent.mount(fixture);
+1 -8
View File
@@ -548,9 +548,6 @@ describe("connecting a component to store", () => {
willUnmount() {
steps.push("child:willUnmount");
}
destroyed() {
steps.push("child:destroyed");
}
}
const ConnectedChild = connect(s => s)(Child);
@@ -576,11 +573,7 @@ describe("connecting a component to store", () => {
expect(steps).toEqual(["child:mounted"]);
await parent.updateState({ child: false });
expect(steps).toEqual([
"child:mounted",
"child:willUnmount",
"child:destroyed"
]);
expect(steps).toEqual(["child:mounted", "child:willUnmount"]);
});
test("connect receives ownprops as second argument", async () => {