From f960149ba2182e6c6aacf27fc9bb7a75097e28ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Wed, 10 Apr 2019 09:35:20 +0200 Subject: [PATCH] rem: remove destroyed hook --- doc/component.md | 1 - src/component.ts | 9 --------- tests/component.test.ts | 42 ++--------------------------------------- tests/store.test.ts | 9 +-------- 4 files changed, 3 insertions(+), 58 deletions(-) diff --git a/doc/component.md b/doc/component.md index 0ed7e733..38b115dc 100644 --- a/doc/component.md +++ b/doc/component.md @@ -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. diff --git a/src/component.ts b/src/component.ts index 41e2c5a9..e068892d 100644 --- a/src/component.ts +++ b/src/component.ts @@ -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(); } } diff --git a/tests/component.test.ts b/tests/component.test.ts index f0142a1a..74c694b2 100644 --- a/tests/component.test.ts +++ b/tests/component.test.ts @@ -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); diff --git a/tests/store.test.ts b/tests/store.test.ts index 0ab8dea6..2dd653db 100644 --- a/tests/store.test.ts +++ b/tests/store.test.ts @@ -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 () => {