From 8061799f661f88076d2ff1a16c2ddad115d59dfd Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 23 Nov 2017 18:43:18 -0500 Subject: [PATCH] add component.destroyed property (fixes #935) --- src/shared/index.js | 3 +++ .../collapses-text-around-comments/expected-bundle.js | 2 ++ test/js/samples/component-static/expected-bundle.js | 2 ++ test/js/samples/computed-collapsed-if/expected-bundle.js | 2 ++ test/js/samples/css-media-query/expected-bundle.js | 2 ++ .../js/samples/css-shadow-dom-keyframes/expected-bundle.js | 2 ++ test/js/samples/do-use-dataset/expected-bundle.js | 2 ++ .../samples/dont-use-dataset-in-legacy/expected-bundle.js | 2 ++ .../js/samples/each-block-changed-check/expected-bundle.js | 2 ++ test/js/samples/event-handlers-custom/expected-bundle.js | 2 ++ test/js/samples/if-block-no-update/expected-bundle.js | 2 ++ test/js/samples/if-block-simple/expected-bundle.js | 2 ++ .../inline-style-optimized-multiple/expected-bundle.js | 2 ++ .../samples/inline-style-optimized-url/expected-bundle.js | 2 ++ test/js/samples/inline-style-optimized/expected-bundle.js | 2 ++ .../js/samples/inline-style-unoptimized/expected-bundle.js | 2 ++ .../input-without-blowback-guard/expected-bundle.js | 2 ++ test/js/samples/legacy-input-type/expected-bundle.js | 2 ++ test/js/samples/legacy-quote-class/expected-bundle.js | 2 ++ test/js/samples/media-bindings/expected-bundle.js | 2 ++ test/js/samples/non-imported-component/expected-bundle.js | 2 ++ .../onrender-onteardown-rewritten/expected-bundle.js | 2 ++ test/js/samples/setup-method/expected-bundle.js | 2 ++ test/js/samples/use-elements-as-anchors/expected-bundle.js | 2 ++ test/js/samples/window-binding-scroll/expected-bundle.js | 2 ++ test/runtime/samples/destroyed/_config.js | 7 +++++++ test/runtime/samples/destroyed/main.html | 1 + 27 files changed, 59 insertions(+) create mode 100644 test/runtime/samples/destroyed/_config.js create mode 100644 test/runtime/samples/destroyed/main.html diff --git a/src/shared/index.js b/src/shared/index.js index f9d0f91998..ef084f4c76 100644 --- a/src/shared/index.js +++ b/src/shared/index.js @@ -16,6 +16,7 @@ export function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } export function destroyDev(detach) { @@ -188,6 +189,7 @@ export function _unmount() { } export var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, @@ -202,6 +204,7 @@ export var proto = { }; export var protoDev = { + destroyed: false, destroy: destroyDev, get: get, fire: fire, diff --git a/test/js/samples/collapses-text-around-comments/expected-bundle.js b/test/js/samples/collapses-text-around-comments/expected-bundle.js index a5776bc195..c10fdf0464 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -49,6 +49,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -178,6 +179,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/js/samples/component-static/expected-bundle.js b/test/js/samples/component-static/expected-bundle.js index 94f69ca2ca..c8597c398f 100644 --- a/test/js/samples/component-static/expected-bundle.js +++ b/test/js/samples/component-static/expected-bundle.js @@ -25,6 +25,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -154,6 +155,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/js/samples/computed-collapsed-if/expected-bundle.js b/test/js/samples/computed-collapsed-if/expected-bundle.js index c378d78026..18742926fa 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -25,6 +25,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -154,6 +155,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index 11ffa87f21..610aee617c 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -45,6 +45,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -174,6 +175,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js b/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js index 86edac7465..7aefd1633e 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js @@ -37,6 +37,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -166,6 +167,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/js/samples/do-use-dataset/expected-bundle.js b/test/js/samples/do-use-dataset/expected-bundle.js index 42de89fd93..3bfdafcaa9 100644 --- a/test/js/samples/do-use-dataset/expected-bundle.js +++ b/test/js/samples/do-use-dataset/expected-bundle.js @@ -41,6 +41,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -170,6 +171,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/js/samples/dont-use-dataset-in-legacy/expected-bundle.js b/test/js/samples/dont-use-dataset-in-legacy/expected-bundle.js index 2d25e23a10..1aaeb35f44 100644 --- a/test/js/samples/dont-use-dataset-in-legacy/expected-bundle.js +++ b/test/js/samples/dont-use-dataset-in-legacy/expected-bundle.js @@ -45,6 +45,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -174,6 +175,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/js/samples/each-block-changed-check/expected-bundle.js b/test/js/samples/each-block-changed-check/expected-bundle.js index c9723db616..ffee6754bb 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -57,6 +57,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -186,6 +187,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index 46c109100a..501af3326f 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -37,6 +37,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -166,6 +167,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/js/samples/if-block-no-update/expected-bundle.js b/test/js/samples/if-block-no-update/expected-bundle.js index 0277095a83..57ef928904 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -41,6 +41,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -170,6 +171,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js index 40acbe3959..0c0e0920eb 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -41,6 +41,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -170,6 +171,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js index eff6f53cfa..41d5252f51 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js @@ -41,6 +41,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -170,6 +171,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/js/samples/inline-style-optimized-url/expected-bundle.js b/test/js/samples/inline-style-optimized-url/expected-bundle.js index 3a126946ad..9e7cc233db 100644 --- a/test/js/samples/inline-style-optimized-url/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-url/expected-bundle.js @@ -41,6 +41,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -170,6 +171,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/js/samples/inline-style-optimized/expected-bundle.js b/test/js/samples/inline-style-optimized/expected-bundle.js index 0c127a6391..d3aac0dd34 100644 --- a/test/js/samples/inline-style-optimized/expected-bundle.js +++ b/test/js/samples/inline-style-optimized/expected-bundle.js @@ -41,6 +41,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -170,6 +171,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/js/samples/inline-style-unoptimized/expected-bundle.js b/test/js/samples/inline-style-unoptimized/expected-bundle.js index d6f545111a..638b3896da 100644 --- a/test/js/samples/inline-style-unoptimized/expected-bundle.js +++ b/test/js/samples/inline-style-unoptimized/expected-bundle.js @@ -41,6 +41,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -170,6 +171,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/js/samples/input-without-blowback-guard/expected-bundle.js b/test/js/samples/input-without-blowback-guard/expected-bundle.js index 1918f9f6d1..0c6449d2ed 100644 --- a/test/js/samples/input-without-blowback-guard/expected-bundle.js +++ b/test/js/samples/input-without-blowback-guard/expected-bundle.js @@ -45,6 +45,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -174,6 +175,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/js/samples/legacy-input-type/expected-bundle.js b/test/js/samples/legacy-input-type/expected-bundle.js index 7211738f45..99e8a5f81d 100644 --- a/test/js/samples/legacy-input-type/expected-bundle.js +++ b/test/js/samples/legacy-input-type/expected-bundle.js @@ -43,6 +43,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -172,6 +173,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/js/samples/legacy-quote-class/expected-bundle.js b/test/js/samples/legacy-quote-class/expected-bundle.js index 1575bf4064..00fbf38e9f 100644 --- a/test/js/samples/legacy-quote-class/expected-bundle.js +++ b/test/js/samples/legacy-quote-class/expected-bundle.js @@ -60,6 +60,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -189,6 +190,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/js/samples/media-bindings/expected-bundle.js b/test/js/samples/media-bindings/expected-bundle.js index 80545b9402..ea19dfe3bf 100644 --- a/test/js/samples/media-bindings/expected-bundle.js +++ b/test/js/samples/media-bindings/expected-bundle.js @@ -53,6 +53,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -182,6 +183,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js index 575be613fa..dc81c1ab6c 100644 --- a/test/js/samples/non-imported-component/expected-bundle.js +++ b/test/js/samples/non-imported-component/expected-bundle.js @@ -39,6 +39,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -168,6 +169,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js index f1e701bd04..424b65a955 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js @@ -25,6 +25,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -154,6 +155,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/js/samples/setup-method/expected-bundle.js b/test/js/samples/setup-method/expected-bundle.js index 0c545ea70c..d0cdfe6529 100644 --- a/test/js/samples/setup-method/expected-bundle.js +++ b/test/js/samples/setup-method/expected-bundle.js @@ -25,6 +25,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -154,6 +155,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/js/samples/use-elements-as-anchors/expected-bundle.js b/test/js/samples/use-elements-as-anchors/expected-bundle.js index 8805cc3847..986d16ad81 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -49,6 +49,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -178,6 +179,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/js/samples/window-binding-scroll/expected-bundle.js b/test/js/samples/window-binding-scroll/expected-bundle.js index 6c357ef732..b6740d0e6d 100644 --- a/test/js/samples/window-binding-scroll/expected-bundle.js +++ b/test/js/samples/window-binding-scroll/expected-bundle.js @@ -45,6 +45,7 @@ function destroy(detach) { if (detach !== false) this._fragment.u(); this._fragment.d(); this._fragment = this._state = null; + this.destroyed = true; } function differs(a, b) { @@ -174,6 +175,7 @@ function _unmount() { } var proto = { + destroyed: false, destroy: destroy, get: get, fire: fire, diff --git a/test/runtime/samples/destroyed/_config.js b/test/runtime/samples/destroyed/_config.js new file mode 100644 index 0000000000..41c6b52f24 --- /dev/null +++ b/test/runtime/samples/destroyed/_config.js @@ -0,0 +1,7 @@ +export default { + test(assert, component) { + assert.ok(!component.destroyed); + component.destroy(); + assert.ok(component.destroyed); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/destroyed/main.html b/test/runtime/samples/destroyed/main.html new file mode 100644 index 0000000000..78e7012b82 --- /dev/null +++ b/test/runtime/samples/destroyed/main.html @@ -0,0 +1 @@ +
\ No newline at end of file