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)** - **[willPatch](#willPatch)**
- **[updated](#updated)** - **[updated](#updated)**
- **[willUnmount](#willUnmount)** - **[willUnmount](#willUnmount)**
- **[destroyed](#destroyed)**
Note: no hook method should ever be called manually. They are supposed to be Note: no hook method should ever be called manually. They are supposed to be
called by the owl framework whenever it is required. called by the owl framework whenever it is required.
-9
View File
@@ -197,14 +197,6 @@ export class Component<
*/ */
willUnmount() {} 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 // Public
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
@@ -296,7 +288,6 @@ export class Component<
} }
this.clear(); this.clear();
this.__widget__.isDestroyed = true; this.__widget__.isDestroyed = true;
this.destroyed();
} }
} }
+2 -40
View File
@@ -312,21 +312,12 @@ describe("lifecycle hooks", () => {
willUnmount() { willUnmount() {
steps.push("willunmount"); steps.push("willunmount");
} }
destroyed() {
steps.push("destroyed");
}
} }
const widget = new ParentWidget(env); const widget = new ParentWidget(env);
await widget.mount(fixture); await widget.mount(fixture);
expect(steps).toEqual(["init", "willstart", "mounted"]); expect(steps).toEqual(["init", "willstart", "mounted"]);
await widget.updateState({ ok: false }); await widget.updateState({ ok: false });
expect(steps).toEqual([ expect(steps).toEqual(["init", "willstart", "mounted", "willunmount"]);
"init",
"willstart",
"mounted",
"willunmount",
"destroyed"
]);
}); });
test("widgets are unmounted and destroyed if no longer in DOM, even after updateprops", async () => { test("widgets are unmounted and destroyed if no longer in DOM, even after updateprops", async () => {
@@ -388,9 +379,6 @@ describe("lifecycle hooks", () => {
willUnmount() { willUnmount() {
steps.push("p willunmount"); steps.push("p willunmount");
} }
destroyed() {
steps.push("p destroyed");
}
} }
class ChildWidget extends Widget { class ChildWidget extends Widget {
@@ -407,9 +395,6 @@ describe("lifecycle hooks", () => {
willUnmount() { willUnmount() {
steps.push("c willunmount"); steps.push("c willunmount");
} }
destroyed() {
steps.push("c destroyed");
}
} }
const widget = new ParentWidget(env); const widget = new ParentWidget(env);
await widget.mount(fixture); await widget.mount(fixture);
@@ -422,9 +407,7 @@ describe("lifecycle hooks", () => {
"p mounted", "p mounted",
"c mounted", "c mounted",
"c willunmount", "c willunmount",
"c destroyed", "p willunmount"
"p willunmount",
"p destroyed"
]); ]);
}); });
@@ -523,7 +506,6 @@ describe("lifecycle hooks", () => {
}); });
test("sub widget (inside sub node): hooks are correctly called", async () => { test("sub widget (inside sub node): hooks are correctly called", async () => {
let destroyed = false;
let created = false; let created = false;
let mounted = false; let mounted = false;
class ParentWidget extends Widget { class ParentWidget extends Widget {
@@ -545,9 +527,6 @@ describe("lifecycle hooks", () => {
mounted() { mounted() {
mounted = true; mounted = true;
} }
destroyed() {
destroyed = true;
}
} }
const widget = new ParentWidget(env); const widget = new ParentWidget(env);
await widget.mount(fixture); await widget.mount(fixture);
@@ -556,9 +535,7 @@ describe("lifecycle hooks", () => {
await widget.updateState({ flag: true }); await widget.updateState({ flag: true });
expect(mounted).toBe(true); expect(mounted).toBe(true);
expect(created).toBe(true); expect(created).toBe(true);
expect(destroyed).toBe(false);
await widget.updateState({ flag: false }); await widget.updateState({ flag: false });
expect(destroyed).toBe(true);
}); });
test("willPatch/patched hook", async () => { test("willPatch/patched hook", async () => {
@@ -612,21 +589,6 @@ describe("destroy method", () => {
expect(widget.__widget__.isDestroyed).toBe(true); 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 () => { test("destroying a parent also destroys its children", async () => {
const parent = new WidgetA(env); const parent = new WidgetA(env);
await parent.mount(fixture); await parent.mount(fixture);
+1 -8
View File
@@ -548,9 +548,6 @@ describe("connecting a component to store", () => {
willUnmount() { willUnmount() {
steps.push("child:willUnmount"); steps.push("child:willUnmount");
} }
destroyed() {
steps.push("child:destroyed");
}
} }
const ConnectedChild = connect(s => s)(Child); const ConnectedChild = connect(s => s)(Child);
@@ -576,11 +573,7 @@ describe("connecting a component to store", () => {
expect(steps).toEqual(["child:mounted"]); expect(steps).toEqual(["child:mounted"]);
await parent.updateState({ child: false }); await parent.updateState({ child: false });
expect(steps).toEqual([ expect(steps).toEqual(["child:mounted", "child:willUnmount"]);
"child:mounted",
"child:willUnmount",
"child:destroyed"
]);
}); });
test("connect receives ownprops as second argument", async () => { test("connect receives ownprops as second argument", async () => {