From a2e85aec1de5ff06f6197ecca10462fcb96ea986 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 6 Aug 2017 14:26:19 -0400 Subject: [PATCH] replace destroy with noop on destroy --- src/generators/dom/index.ts | 1 - src/shared/index.js | 19 +++++++++---------- .../expected-bundle.js | 16 ++++++---------- .../expected.js | 1 - .../computed-collapsed-if/expected-bundle.js | 17 ++++++----------- .../samples/computed-collapsed-if/expected.js | 2 -- .../css-media-query/expected-bundle.js | 16 ++++++---------- test/js/samples/css-media-query/expected.js | 1 - .../expected-bundle.js | 17 ++++++----------- .../each-block-changed-check/expected.js | 2 -- .../event-handlers-custom/expected-bundle.js | 17 ++++++----------- .../samples/event-handlers-custom/expected.js | 2 -- .../if-block-no-update/expected-bundle.js | 17 ++++++----------- .../js/samples/if-block-no-update/expected.js | 2 -- .../if-block-simple/expected-bundle.js | 17 ++++++----------- test/js/samples/if-block-simple/expected.js | 2 -- .../non-imported-component/expected-bundle.js | 17 ++++++----------- .../non-imported-component/expected.js | 2 -- .../expected-bundle.js | 17 ++++++----------- .../onrender-onteardown-rewritten/expected.js | 2 -- .../samples/setup-method/expected-bundle.js | 17 ++++++----------- test/js/samples/setup-method/expected.js | 2 -- .../expected-bundle.js | 17 ++++++----------- .../use-elements-as-anchors/expected.js | 2 -- 24 files changed, 75 insertions(+), 150 deletions(-) diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 091ec685df..2ffae2ee2f 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -212,7 +212,6 @@ export default function dom( this._root = options._root || this; this._yield = options._yield; - this._destroyed = false; ${generator.stylesheet.hasStyles && options.css !== false && `if ( !document.getElementById( '${generator.stylesheet.id}-style' ) ) @add_css();`} diff --git a/src/shared/index.js b/src/shared/index.js index 67aa972f6f..f198a4ef95 100644 --- a/src/shared/index.js +++ b/src/shared/index.js @@ -5,22 +5,21 @@ export * from './transitions.js'; export * from './utils.js'; export function destroy(detach) { - if (!this._destroyed) { - this.set = noop; - this.fire('destroy'); + this.destroy = this.set = noop; + this.fire('destroy'); - if (detach !== false) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; - this._state = {}; - this._destroyed = true; - } + this._state = {}; } export function destroyDev(detach) { - if (this._destroyed) console.warn('Component was already destroyed'); destroy.call(this, detach); + this.destroy = function() { + console.warn('Component was already destroyed'); + }; } export function differs(a, b) { 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 93e2086a26..e52f943862 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -38,17 +38,14 @@ function setAttribute(node, attribute, value) { } function destroy(detach) { - if (!this._destroyed) { - this.set = noop; - this.fire('destroy'); + this.destroy = this.set = noop; + this.fire('destroy'); - if (detach !== false) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; - this._state = {}; - this._destroyed = true; - } + this._state = {}; } function differs(a, b) { @@ -217,7 +214,6 @@ function SvelteComponent ( options ) { this._root = options._root || this; this._yield = options._yield; - this._destroyed = false; if ( !document.getElementById( 'svelte-3590263702-style' ) ) add_css(); this._fragment = create_main_fragment( this._state, this ); diff --git a/test/js/samples/collapses-text-around-comments/expected.js b/test/js/samples/collapses-text-around-comments/expected.js index 697716bdfe..5a3e3d52f6 100644 --- a/test/js/samples/collapses-text-around-comments/expected.js +++ b/test/js/samples/collapses-text-around-comments/expected.js @@ -66,7 +66,6 @@ function SvelteComponent ( options ) { this._root = options._root || this; this._yield = options._yield; - this._destroyed = false; if ( !document.getElementById( 'svelte-3590263702-style' ) ) add_css(); this._fragment = create_main_fragment( this._state, this ); diff --git a/test/js/samples/computed-collapsed-if/expected-bundle.js b/test/js/samples/computed-collapsed-if/expected-bundle.js index b0d7198a01..0da5cdf32c 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -14,17 +14,14 @@ function assign(target) { } function destroy(detach) { - if (!this._destroyed) { - this.set = noop; - this.fire('destroy'); + this.destroy = this.set = noop; + this.fire('destroy'); - if (detach !== false) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; - this._state = {}; - this._destroyed = true; - } + this._state = {}; } function differs(a, b) { @@ -171,8 +168,6 @@ function SvelteComponent ( options ) { this._root = options._root || this; this._yield = options._yield; - this._destroyed = false; - this._fragment = create_main_fragment( this._state, this ); if ( options.target ) { diff --git a/test/js/samples/computed-collapsed-if/expected.js b/test/js/samples/computed-collapsed-if/expected.js index 25058a55f6..a17e730122 100644 --- a/test/js/samples/computed-collapsed-if/expected.js +++ b/test/js/samples/computed-collapsed-if/expected.js @@ -44,8 +44,6 @@ function SvelteComponent ( options ) { this._root = options._root || this; this._yield = options._yield; - this._destroyed = false; - this._fragment = create_main_fragment( this._state, this ); if ( options.target ) { diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index b2ddda972b..3324ebf9be 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -34,17 +34,14 @@ function setAttribute(node, attribute, value) { } function destroy(detach) { - if (!this._destroyed) { - this.set = noop; - this.fire('destroy'); + this.destroy = this.set = noop; + this.fire('destroy'); - if (detach !== false) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; - this._state = {}; - this._destroyed = true; - } + this._state = {}; } function differs(a, b) { @@ -197,7 +194,6 @@ function SvelteComponent ( options ) { this._root = options._root || this; this._yield = options._yield; - this._destroyed = false; if ( !document.getElementById( 'svelte-2363328337-style' ) ) add_css(); this._fragment = create_main_fragment( this._state, this ); diff --git a/test/js/samples/css-media-query/expected.js b/test/js/samples/css-media-query/expected.js index 15a7e61159..72338bb55b 100644 --- a/test/js/samples/css-media-query/expected.js +++ b/test/js/samples/css-media-query/expected.js @@ -50,7 +50,6 @@ function SvelteComponent ( options ) { this._root = options._root || this; this._yield = options._yield; - this._destroyed = false; if ( !document.getElementById( 'svelte-2363328337-style' ) ) add_css(); this._fragment = create_main_fragment( this._state, this ); 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 823ff6e216..aac78b9adb 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -47,17 +47,14 @@ function createText(data) { } function destroy(detach) { - if (!this._destroyed) { - this.set = noop; - this.fire('destroy'); + this.destroy = this.set = noop; + this.fire('destroy'); - if (detach !== false) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; - this._state = {}; - this._destroyed = true; - } + this._state = {}; } function differs(a, b) { @@ -317,8 +314,6 @@ function SvelteComponent ( options ) { this._root = options._root || this; this._yield = options._yield; - this._destroyed = false; - this._fragment = create_main_fragment( this._state, this ); if ( options.target ) { diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index c849754884..e7683e0743 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -157,8 +157,6 @@ function SvelteComponent ( options ) { this._root = options._root || this; this._yield = options._yield; - this._destroyed = false; - this._fragment = create_main_fragment( this._state, this ); if ( options.target ) { diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index 5f26fec2c6..ed200a7b4c 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -34,17 +34,14 @@ function createText(data) { } function destroy(detach) { - if (!this._destroyed) { - this.set = noop; - this.fire('destroy'); + this.destroy = this.set = noop; + this.fire('destroy'); - if (detach !== false) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; - this._state = {}; - this._destroyed = true; - } + this._state = {}; } function differs(a, b) { @@ -208,8 +205,6 @@ function SvelteComponent ( options ) { this._root = options._root || this; this._yield = options._yield; - this._destroyed = false; - this._fragment = create_main_fragment( this._state, this ); if ( options.target ) { diff --git a/test/js/samples/event-handlers-custom/expected.js b/test/js/samples/event-handlers-custom/expected.js index b4bf41c8a5..9d5e771bdd 100644 --- a/test/js/samples/event-handlers-custom/expected.js +++ b/test/js/samples/event-handlers-custom/expected.js @@ -61,8 +61,6 @@ function SvelteComponent ( options ) { this._root = options._root || this; this._yield = options._yield; - this._destroyed = false; - this._fragment = create_main_fragment( this._state, this ); if ( options.target ) { 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 2cbbc1ac22..273ce81fc1 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -38,17 +38,14 @@ function createComment() { } function destroy(detach) { - if (!this._destroyed) { - this.set = noop; - this.fire('destroy'); + this.destroy = this.set = noop; + this.fire('destroy'); - if (detach !== false) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; - this._state = {}; - this._destroyed = true; - } + this._state = {}; } function differs(a, b) { @@ -252,8 +249,6 @@ function SvelteComponent ( options ) { this._root = options._root || this; this._yield = options._yield; - this._destroyed = false; - this._fragment = create_main_fragment( this._state, this ); if ( options.target ) { diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js index 4fdddb4f0c..8d30b66a03 100644 --- a/test/js/samples/if-block-no-update/expected.js +++ b/test/js/samples/if-block-no-update/expected.js @@ -101,8 +101,6 @@ function SvelteComponent ( options ) { this._root = options._root || this; this._yield = options._yield; - this._destroyed = false; - this._fragment = create_main_fragment( this._state, this ); if ( options.target ) { diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js index a311445c9d..3b57117283 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -38,17 +38,14 @@ function createComment() { } function destroy(detach) { - if (!this._destroyed) { - this.set = noop; - this.fire('destroy'); + this.destroy = this.set = noop; + this.fire('destroy'); - if (detach !== false) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; - this._state = {}; - this._destroyed = true; - } + this._state = {}; } function differs(a, b) { @@ -228,8 +225,6 @@ function SvelteComponent ( options ) { this._root = options._root || this; this._yield = options._yield; - this._destroyed = false; - this._fragment = create_main_fragment( this._state, this ); if ( options.target ) { diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js index 03ab6d1598..db04589093 100644 --- a/test/js/samples/if-block-simple/expected.js +++ b/test/js/samples/if-block-simple/expected.js @@ -77,8 +77,6 @@ function SvelteComponent ( options ) { this._root = options._root || this; this._yield = options._yield; - this._destroyed = false; - this._fragment = create_main_fragment( this._state, this ); if ( options.target ) { diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js index 448fcbb3f6..b40f56d109 100644 --- a/test/js/samples/non-imported-component/expected-bundle.js +++ b/test/js/samples/non-imported-component/expected-bundle.js @@ -28,17 +28,14 @@ function createText(data) { } function destroy(detach) { - if (!this._destroyed) { - this.set = noop; - this.fire('destroy'); + this.destroy = this.set = noop; + this.fire('destroy'); - if (detach !== false) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; - this._state = {}; - this._destroyed = true; - } + this._state = {}; } function differs(a, b) { @@ -200,8 +197,6 @@ function SvelteComponent ( options ) { this._root = options._root || this; this._yield = options._yield; - this._destroyed = false; - if ( !options._root ) { this._oncreate = []; this._beforecreate = []; diff --git a/test/js/samples/non-imported-component/expected.js b/test/js/samples/non-imported-component/expected.js index 629390ca63..2382e04ab3 100644 --- a/test/js/samples/non-imported-component/expected.js +++ b/test/js/samples/non-imported-component/expected.js @@ -61,8 +61,6 @@ function SvelteComponent ( options ) { this._root = options._root || this; this._yield = options._yield; - this._destroyed = false; - if ( !options._root ) { this._oncreate = []; this._beforecreate = []; diff --git a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js index f79163ae3e..a754118158 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js @@ -14,17 +14,14 @@ function assign(target) { } function destroy(detach) { - if (!this._destroyed) { - this.set = noop; - this.fire('destroy'); + this.destroy = this.set = noop; + this.fire('destroy'); - if (detach !== false) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; - this._state = {}; - this._destroyed = true; - } + this._state = {}; } function differs(a, b) { @@ -163,8 +160,6 @@ function SvelteComponent ( options ) { this._root = options._root || this; this._yield = options._yield; - this._destroyed = false; - var oncreate = template.oncreate.bind( this ); if ( !options._root ) { diff --git a/test/js/samples/onrender-onteardown-rewritten/expected.js b/test/js/samples/onrender-onteardown-rewritten/expected.js index 78c1a7e480..bd473fc2d7 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected.js @@ -36,8 +36,6 @@ function SvelteComponent ( options ) { this._root = options._root || this; this._yield = options._yield; - this._destroyed = false; - var oncreate = template.oncreate.bind( this ); if ( !options._root ) { diff --git a/test/js/samples/setup-method/expected-bundle.js b/test/js/samples/setup-method/expected-bundle.js index c4a3c6178e..006152cea5 100644 --- a/test/js/samples/setup-method/expected-bundle.js +++ b/test/js/samples/setup-method/expected-bundle.js @@ -14,17 +14,14 @@ function assign(target) { } function destroy(detach) { - if (!this._destroyed) { - this.set = noop; - this.fire('destroy'); + this.destroy = this.set = noop; + this.fire('destroy'); - if (detach !== false) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; - this._state = {}; - this._destroyed = true; - } + this._state = {}; } function differs(a, b) { @@ -173,8 +170,6 @@ function SvelteComponent ( options ) { this._root = options._root || this; this._yield = options._yield; - this._destroyed = false; - this._fragment = create_main_fragment( this._state, this ); if ( options.target ) { diff --git a/test/js/samples/setup-method/expected.js b/test/js/samples/setup-method/expected.js index d82ab92039..85f0d5c393 100644 --- a/test/js/samples/setup-method/expected.js +++ b/test/js/samples/setup-method/expected.js @@ -46,8 +46,6 @@ function SvelteComponent ( options ) { this._root = options._root || this; this._yield = options._yield; - this._destroyed = false; - this._fragment = create_main_fragment( this._state, this ); if ( options.target ) { 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 04890dcc7e..502e08b22e 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -38,17 +38,14 @@ function createComment() { } function destroy(detach) { - if (!this._destroyed) { - this.set = noop; - this.fire('destroy'); + this.destroy = this.set = noop; + this.fire('destroy'); - if (detach !== false) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; - this._state = {}; - this._destroyed = true; - } + this._state = {}; } function differs(a, b) { @@ -412,8 +409,6 @@ function SvelteComponent ( options ) { this._root = options._root || this; this._yield = options._yield; - this._destroyed = false; - this._fragment = create_main_fragment( this._state, this ); if ( options.target ) { diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js index 2a214d1ca0..3ed3f1e7db 100644 --- a/test/js/samples/use-elements-as-anchors/expected.js +++ b/test/js/samples/use-elements-as-anchors/expected.js @@ -261,8 +261,6 @@ function SvelteComponent ( options ) { this._root = options._root || this; this._yield = options._yield; - this._destroyed = false; - this._fragment = create_main_fragment( this._state, this ); if ( options.target ) {