From 92766ee9e7fd16110617d9a88cd303212dd0fde9 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 5 Aug 2017 22:16:47 -0400 Subject: [PATCH 1/5] handle set after destroy, and move destroy into shared helpers --- src/generators/dom/index.ts | 18 ++--------- src/shared/index.js | 27 ++++++++++++++-- .../expected-bundle.js | 30 +++++++++-------- .../expected.js | 12 ------- .../computed-collapsed-if/expected-bundle.js | 30 +++++++++-------- .../samples/computed-collapsed-if/expected.js | 12 ------- .../css-media-query/expected-bundle.js | 30 +++++++++-------- test/js/samples/css-media-query/expected.js | 12 ------- .../expected-bundle.js | 30 +++++++++-------- .../each-block-changed-check/expected.js | 12 ------- .../event-handlers-custom/expected-bundle.js | 30 +++++++++-------- .../samples/event-handlers-custom/expected.js | 12 ------- .../if-block-no-update/expected-bundle.js | 30 +++++++++-------- .../js/samples/if-block-no-update/expected.js | 12 ------- .../if-block-simple/expected-bundle.js | 30 +++++++++-------- test/js/samples/if-block-simple/expected.js | 12 ------- .../non-imported-component/expected-bundle.js | 30 +++++++++-------- .../non-imported-component/expected.js | 12 ------- .../expected-bundle.js | 32 +++++++++++-------- .../onrender-onteardown-rewritten/expected.js | 14 +------- .../samples/setup-method/expected-bundle.js | 30 +++++++++-------- test/js/samples/setup-method/expected.js | 14 +------- .../expected-bundle.js | 30 +++++++++-------- .../use-elements-as-anchors/expected.js | 12 ------- .../samples/lifecycle-events/_config.js | 6 ++-- .../samples/lifecycle-events/main.html | 10 +++--- .../samples/set-after-destroy/_config.js | 10 ++++++ .../samples/set-after-destroy/main.html | 1 + 28 files changed, 237 insertions(+), 303 deletions(-) create mode 100644 test/runtime/samples/set-after-destroy/_config.js create mode 100644 test/runtime/samples/set-after-destroy/main.html diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 825b5e2a2e..ff8bcf8949 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -174,8 +174,8 @@ export default function dom( ? `@proto ` : deindent` { - ${['get', 'fire', 'observe', 'on', 'set'] - .map(n => `${n}: @${n}`) + ${['destroy', 'get', 'fire', 'observe', 'on', 'set', 'teardown'] + .map(n => `${n}: @${n === 'teardown' ? 'destroy' : n}`) .join(',\n')} }`; @@ -207,6 +207,7 @@ export default function dom( }; this._handlers = Object.create( null ); + ${templateProperties.ondestroy && `this._handlers.destroy = [@template.ondestroy.bind(this)]`} this._root = options._root || this; this._yield = options._yield; @@ -263,19 +264,6 @@ export default function dom( ${_set} }; - ${name}.prototype.teardown = ${name}.prototype.destroy = function destroy ( detach ) { - if ( this._destroyed ) return${options.dev && ` console.warn( 'Component was already destroyed' )`}; - this.fire( 'destroy' ); - ${templateProperties.ondestroy && `@template.ondestroy.call( this );`} - - if ( detach !== false ) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; - - this._state = {}; - this._destroyed = true; - }; - ${templateProperties.setup && `@template.setup( ${name} );`} `); diff --git a/src/shared/index.js b/src/shared/index.js index 119f50452b..87f4728f8f 100644 --- a/src/shared/index.js +++ b/src/shared/index.js @@ -3,6 +3,24 @@ export * from './dom.js'; export * from './transitions.js'; export * from './utils.js'; +export function destroy(detach) { + if (!this._destroyed) { + this.fire('destroy'); + + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; + + this._state = {}; + this._destroyed = true; + } +} + +export function destroyDev(detach) { + if (this._destroyed) console.warn('Component was already destroyed'); + destroy.call(this, detach); +} + export function differs(a, b) { return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } @@ -105,6 +123,7 @@ export function onDev(eventName, handler) { } export function set(newState) { + if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; @@ -119,17 +138,21 @@ export function callAll(fns) { } export var proto = { + destroy: destroy, get: get, fire: fire, observe: observe, on: on, - set: set + set: set, + teardown: destroy }; export var protoDev = { + destroy: destroyDev, get: get, fire: fire, observe: observeDev, on: onDev, - set: set + set: set, + teardown: destroyDev }; 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 c9fa1ef590..053e4c2c12 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -37,6 +37,19 @@ function setAttribute(node, attribute, value) { node.setAttribute(attribute, value); } +function destroy(detach) { + if (!this._destroyed) { + this.fire('destroy'); + + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; + + this._state = {}; + this._destroyed = true; + } +} + function differs(a, b) { return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } @@ -114,6 +127,7 @@ function on(eventName, handler) { } function set(newState) { + if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; @@ -128,11 +142,13 @@ function callAll(fns) { } var proto = { + destroy: destroy, get: get, fire: fire, observe: observe, on: on, - set: set + set: set, + teardown: destroy }; var template = (function () { @@ -222,16 +238,4 @@ SvelteComponent.prototype._set = function _set ( newState ) { dispatchObservers( this, this._observers.post, newState, oldState ); }; -SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { - if ( this._destroyed ) return; - this.fire( 'destroy' ); - - if ( detach !== false ) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; - - this._state = {}; - this._destroyed = true; -}; - export default SvelteComponent; diff --git a/test/js/samples/collapses-text-around-comments/expected.js b/test/js/samples/collapses-text-around-comments/expected.js index a5dc4d5d58..697716bdfe 100644 --- a/test/js/samples/collapses-text-around-comments/expected.js +++ b/test/js/samples/collapses-text-around-comments/expected.js @@ -87,16 +87,4 @@ SvelteComponent.prototype._set = function _set ( newState ) { dispatchObservers( this, this._observers.post, newState, oldState ); }; -SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { - if ( this._destroyed ) return; - this.fire( 'destroy' ); - - if ( detach !== false ) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; - - this._state = {}; - this._destroyed = true; -}; - export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/computed-collapsed-if/expected-bundle.js b/test/js/samples/computed-collapsed-if/expected-bundle.js index 35825f465d..a52a992476 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -13,6 +13,19 @@ function assign(target) { return target; } +function destroy(detach) { + if (!this._destroyed) { + this.fire('destroy'); + + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; + + this._state = {}; + this._destroyed = true; + } +} + function differs(a, b) { return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } @@ -90,6 +103,7 @@ function on(eventName, handler) { } function set(newState) { + if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; @@ -104,11 +118,13 @@ function callAll(fns) { } var proto = { + destroy: destroy, get: get, fire: fire, observe: observe, on: on, - set: set + set: set, + teardown: destroy }; function recompute ( state, newState, oldState, isInitial ) { @@ -175,16 +191,4 @@ SvelteComponent.prototype._set = function _set ( newState ) { dispatchObservers( this, this._observers.post, newState, oldState ); }; -SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { - if ( this._destroyed ) return; - this.fire( 'destroy' ); - - if ( detach !== false ) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; - - this._state = {}; - this._destroyed = true; -}; - export default SvelteComponent; diff --git a/test/js/samples/computed-collapsed-if/expected.js b/test/js/samples/computed-collapsed-if/expected.js index bb2b420c84..25058a55f6 100644 --- a/test/js/samples/computed-collapsed-if/expected.js +++ b/test/js/samples/computed-collapsed-if/expected.js @@ -64,16 +64,4 @@ SvelteComponent.prototype._set = function _set ( newState ) { dispatchObservers( this, this._observers.post, newState, oldState ); }; -SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { - if ( this._destroyed ) return; - this.fire( 'destroy' ); - - if ( detach !== false ) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; - - this._state = {}; - this._destroyed = true; -}; - export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index ebbfffd1ec..8ecdac50c1 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -33,6 +33,19 @@ function setAttribute(node, attribute, value) { node.setAttribute(attribute, value); } +function destroy(detach) { + if (!this._destroyed) { + this.fire('destroy'); + + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; + + this._state = {}; + this._destroyed = true; + } +} + function differs(a, b) { return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } @@ -110,6 +123,7 @@ function on(eventName, handler) { } function set(newState) { + if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; @@ -124,11 +138,13 @@ function callAll(fns) { } var proto = { + destroy: destroy, get: get, fire: fire, observe: observe, on: on, - set: set + set: set, + teardown: destroy }; function encapsulateStyles ( node ) { @@ -201,16 +217,4 @@ SvelteComponent.prototype._set = function _set ( newState ) { dispatchObservers( this, this._observers.post, newState, oldState ); }; -SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { - if ( this._destroyed ) return; - this.fire( 'destroy' ); - - if ( detach !== false ) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; - - this._state = {}; - this._destroyed = true; -}; - export default SvelteComponent; diff --git a/test/js/samples/css-media-query/expected.js b/test/js/samples/css-media-query/expected.js index d9af1bfe54..15a7e61159 100644 --- a/test/js/samples/css-media-query/expected.js +++ b/test/js/samples/css-media-query/expected.js @@ -70,16 +70,4 @@ SvelteComponent.prototype._set = function _set ( newState ) { dispatchObservers( this, this._observers.post, newState, oldState ); }; -SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { - if ( this._destroyed ) return; - this.fire( 'destroy' ); - - if ( detach !== false ) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; - - this._state = {}; - this._destroyed = true; -}; - export default SvelteComponent; \ No newline at end of file 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 9afe02d871..f77ab22f89 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -46,6 +46,19 @@ function createText(data) { return document.createTextNode(data); } +function destroy(detach) { + if (!this._destroyed) { + this.fire('destroy'); + + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; + + this._state = {}; + this._destroyed = true; + } +} + function differs(a, b) { return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } @@ -123,6 +136,7 @@ function on(eventName, handler) { } function set(newState) { + if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; @@ -137,11 +151,13 @@ function callAll(fns) { } var proto = { + destroy: destroy, get: get, fire: fire, observe: observe, on: on, - set: set + set: set, + teardown: destroy }; function create_main_fragment ( state, component ) { @@ -321,16 +337,4 @@ SvelteComponent.prototype._set = function _set ( newState ) { dispatchObservers( this, this._observers.post, newState, oldState ); }; -SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { - if ( this._destroyed ) return; - this.fire( 'destroy' ); - - if ( detach !== false ) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; - - this._state = {}; - this._destroyed = true; -}; - export default SvelteComponent; diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index 6072df4896..c849754884 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -177,16 +177,4 @@ SvelteComponent.prototype._set = function _set ( newState ) { dispatchObservers( this, this._observers.post, newState, oldState ); }; -SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { - if ( this._destroyed ) return; - this.fire( 'destroy' ); - - if ( detach !== false ) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; - - this._state = {}; - this._destroyed = true; -}; - export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index fa20cbc9ef..12857effdd 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -31,6 +31,19 @@ function createText(data) { return document.createTextNode(data); } +function destroy(detach) { + if (!this._destroyed) { + this.fire('destroy'); + + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; + + this._state = {}; + this._destroyed = true; + } +} + function differs(a, b) { return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } @@ -108,6 +121,7 @@ function on(eventName, handler) { } function set(newState) { + if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; @@ -122,11 +136,13 @@ function callAll(fns) { } var proto = { + destroy: destroy, get: get, fire: fire, observe: observe, on: on, - set: set + set: set, + teardown: destroy }; var template = (function () { @@ -209,16 +225,4 @@ SvelteComponent.prototype._set = function _set ( newState ) { dispatchObservers( this, this._observers.post, newState, oldState ); }; -SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { - if ( this._destroyed ) return; - this.fire( 'destroy' ); - - if ( detach !== false ) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; - - this._state = {}; - this._destroyed = true; -}; - export default SvelteComponent; diff --git a/test/js/samples/event-handlers-custom/expected.js b/test/js/samples/event-handlers-custom/expected.js index abbfef0f91..b4bf41c8a5 100644 --- a/test/js/samples/event-handlers-custom/expected.js +++ b/test/js/samples/event-handlers-custom/expected.js @@ -80,16 +80,4 @@ SvelteComponent.prototype._set = function _set ( newState ) { dispatchObservers( this, this._observers.post, newState, oldState ); }; -SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { - if ( this._destroyed ) return; - this.fire( 'destroy' ); - - if ( detach !== false ) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; - - this._state = {}; - this._destroyed = true; -}; - export default SvelteComponent; \ No newline at end of file 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 73ac6bcf63..56ab031da3 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -37,6 +37,19 @@ function createComment() { return document.createComment(''); } +function destroy(detach) { + if (!this._destroyed) { + this.fire('destroy'); + + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; + + this._state = {}; + this._destroyed = true; + } +} + function differs(a, b) { return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } @@ -114,6 +127,7 @@ function on(eventName, handler) { } function set(newState) { + if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; @@ -128,11 +142,13 @@ function callAll(fns) { } var proto = { + destroy: destroy, get: get, fire: fire, observe: observe, on: on, - set: set + set: set, + teardown: destroy }; function create_main_fragment ( state, component ) { @@ -256,16 +272,4 @@ SvelteComponent.prototype._set = function _set ( newState ) { dispatchObservers( this, this._observers.post, newState, oldState ); }; -SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { - if ( this._destroyed ) return; - this.fire( 'destroy' ); - - if ( detach !== false ) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; - - this._state = {}; - this._destroyed = true; -}; - export default SvelteComponent; diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js index e346847b37..4fdddb4f0c 100644 --- a/test/js/samples/if-block-no-update/expected.js +++ b/test/js/samples/if-block-no-update/expected.js @@ -121,16 +121,4 @@ SvelteComponent.prototype._set = function _set ( newState ) { dispatchObservers( this, this._observers.post, newState, oldState ); }; -SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { - if ( this._destroyed ) return; - this.fire( 'destroy' ); - - if ( detach !== false ) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; - - this._state = {}; - this._destroyed = true; -}; - export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js index 2ce85c33e6..aca06df4f4 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -37,6 +37,19 @@ function createComment() { return document.createComment(''); } +function destroy(detach) { + if (!this._destroyed) { + this.fire('destroy'); + + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; + + this._state = {}; + this._destroyed = true; + } +} + function differs(a, b) { return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } @@ -114,6 +127,7 @@ function on(eventName, handler) { } function set(newState) { + if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; @@ -128,11 +142,13 @@ function callAll(fns) { } var proto = { + destroy: destroy, get: get, fire: fire, observe: observe, on: on, - set: set + set: set, + teardown: destroy }; function create_main_fragment ( state, component ) { @@ -232,16 +248,4 @@ SvelteComponent.prototype._set = function _set ( newState ) { dispatchObservers( this, this._observers.post, newState, oldState ); }; -SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { - if ( this._destroyed ) return; - this.fire( 'destroy' ); - - if ( detach !== false ) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; - - this._state = {}; - this._destroyed = true; -}; - export default SvelteComponent; diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js index efd23dc55d..03ab6d1598 100644 --- a/test/js/samples/if-block-simple/expected.js +++ b/test/js/samples/if-block-simple/expected.js @@ -97,16 +97,4 @@ SvelteComponent.prototype._set = function _set ( newState ) { dispatchObservers( this, this._observers.post, newState, oldState ); }; -SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { - if ( this._destroyed ) return; - this.fire( 'destroy' ); - - if ( detach !== false ) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; - - this._state = {}; - this._destroyed = true; -}; - export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js index c37d2f042a..e9a1ef969d 100644 --- a/test/js/samples/non-imported-component/expected-bundle.js +++ b/test/js/samples/non-imported-component/expected-bundle.js @@ -25,6 +25,19 @@ function createText(data) { return document.createTextNode(data); } +function destroy(detach) { + if (!this._destroyed) { + this.fire('destroy'); + + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; + + this._state = {}; + this._destroyed = true; + } +} + function differs(a, b) { return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } @@ -102,6 +115,7 @@ function on(eventName, handler) { } function set(newState) { + if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; @@ -116,11 +130,13 @@ function callAll(fns) { } var proto = { + destroy: destroy, get: get, fire: fire, observe: observe, on: on, - set: set + set: set, + teardown: destroy }; var template = (function () { @@ -215,16 +231,4 @@ SvelteComponent.prototype._set = function _set ( newState ) { dispatchObservers( this, this._observers.post, newState, oldState ); }; -SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { - if ( this._destroyed ) return; - this.fire( 'destroy' ); - - if ( detach !== false ) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; - - this._state = {}; - this._destroyed = true; -}; - export default SvelteComponent; diff --git a/test/js/samples/non-imported-component/expected.js b/test/js/samples/non-imported-component/expected.js index 195fb2b7b1..629390ca63 100644 --- a/test/js/samples/non-imported-component/expected.js +++ b/test/js/samples/non-imported-component/expected.js @@ -94,16 +94,4 @@ SvelteComponent.prototype._set = function _set ( newState ) { dispatchObservers( this, this._observers.post, newState, oldState ); }; -SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { - if ( this._destroyed ) return; - this.fire( 'destroy' ); - - if ( detach !== false ) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; - - this._state = {}; - this._destroyed = true; -}; - export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js index eb9a6cdd4f..041326fdf3 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js @@ -13,6 +13,19 @@ function assign(target) { return target; } +function destroy(detach) { + if (!this._destroyed) { + this.fire('destroy'); + + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; + + this._state = {}; + this._destroyed = true; + } +} + function differs(a, b) { return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } @@ -90,6 +103,7 @@ function on(eventName, handler) { } function set(newState) { + if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; @@ -104,11 +118,13 @@ function callAll(fns) { } var proto = { + destroy: destroy, get: get, fire: fire, observe: observe, on: on, - set: set + set: set, + teardown: destroy }; var template = (function () { @@ -142,6 +158,7 @@ function SvelteComponent ( options ) { }; this._handlers = Object.create( null ); + this._handlers.destroy = [template.ondestroy.bind(this)]; this._root = options._root || this; this._yield = options._yield; @@ -177,17 +194,4 @@ SvelteComponent.prototype._set = function _set ( newState ) { dispatchObservers( this, this._observers.post, newState, oldState ); }; -SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { - if ( this._destroyed ) return; - this.fire( 'destroy' ); - template.ondestroy.call( this ); - - if ( detach !== false ) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; - - this._state = {}; - this._destroyed = true; -}; - export default SvelteComponent; diff --git a/test/js/samples/onrender-onteardown-rewritten/expected.js b/test/js/samples/onrender-onteardown-rewritten/expected.js index e35b716595..f40d3e0a5c 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected.js @@ -31,6 +31,7 @@ function SvelteComponent ( options ) { }; this._handlers = Object.create( null ); + this._handlers.destroy = [template.ondestroy.bind(this)] this._root = options._root || this; this._yield = options._yield; @@ -66,17 +67,4 @@ SvelteComponent.prototype._set = function _set ( newState ) { dispatchObservers( this, this._observers.post, newState, oldState ); }; -SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { - if ( this._destroyed ) return; - this.fire( 'destroy' ); - template.ondestroy.call( this ); - - if ( detach !== false ) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; - - this._state = {}; - this._destroyed = true; -}; - export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/setup-method/expected-bundle.js b/test/js/samples/setup-method/expected-bundle.js index 6c4e62fa04..d27a1ef958 100644 --- a/test/js/samples/setup-method/expected-bundle.js +++ b/test/js/samples/setup-method/expected-bundle.js @@ -13,6 +13,19 @@ function assign(target) { return target; } +function destroy(detach) { + if (!this._destroyed) { + this.fire('destroy'); + + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; + + this._state = {}; + this._destroyed = true; + } +} + function differs(a, b) { return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } @@ -90,6 +103,7 @@ function on(eventName, handler) { } function set(newState) { + if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; @@ -104,11 +118,13 @@ function callAll(fns) { } var proto = { + destroy: destroy, get: get, fire: fire, observe: observe, on: on, - set: set + set: set, + teardown: destroy }; var template = (function () { @@ -176,18 +192,6 @@ SvelteComponent.prototype._set = function _set ( newState ) { dispatchObservers( this, this._observers.post, newState, oldState ); }; -SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { - if ( this._destroyed ) return; - this.fire( 'destroy' ); - - if ( detach !== false ) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; - - this._state = {}; - this._destroyed = true; -}; - template.setup( SvelteComponent ); export default SvelteComponent; diff --git a/test/js/samples/setup-method/expected.js b/test/js/samples/setup-method/expected.js index 3e72768ac8..d82ab92039 100644 --- a/test/js/samples/setup-method/expected.js +++ b/test/js/samples/setup-method/expected.js @@ -65,18 +65,6 @@ SvelteComponent.prototype._set = function _set ( newState ) { dispatchObservers( this, this._observers.post, newState, oldState ); }; -SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { - if ( this._destroyed ) return; - this.fire( 'destroy' ); - - if ( detach !== false ) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; - - this._state = {}; - this._destroyed = true; -}; - template.setup( SvelteComponent ); -export default SvelteComponent; +export default SvelteComponent; \ No newline at end of file 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 b969e80971..dd1ed072bb 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -37,6 +37,19 @@ function createComment() { return document.createComment(''); } +function destroy(detach) { + if (!this._destroyed) { + this.fire('destroy'); + + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = null; + + this._state = {}; + this._destroyed = true; + } +} + function differs(a, b) { return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } @@ -114,6 +127,7 @@ function on(eventName, handler) { } function set(newState) { + if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; @@ -128,11 +142,13 @@ function callAll(fns) { } var proto = { + destroy: destroy, get: get, fire: fire, observe: observe, on: on, - set: set + set: set, + teardown: destroy }; function create_main_fragment ( state, component ) { @@ -416,16 +432,4 @@ SvelteComponent.prototype._set = function _set ( newState ) { dispatchObservers( this, this._observers.post, newState, oldState ); }; -SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { - if ( this._destroyed ) return; - this.fire( 'destroy' ); - - if ( detach !== false ) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; - - this._state = {}; - this._destroyed = true; -}; - export default SvelteComponent; diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js index 046bf7fcbc..2a214d1ca0 100644 --- a/test/js/samples/use-elements-as-anchors/expected.js +++ b/test/js/samples/use-elements-as-anchors/expected.js @@ -281,16 +281,4 @@ SvelteComponent.prototype._set = function _set ( newState ) { dispatchObservers( this, this._observers.post, newState, oldState ); }; -SvelteComponent.prototype.teardown = SvelteComponent.prototype.destroy = function destroy ( detach ) { - if ( this._destroyed ) return; - this.fire( 'destroy' ); - - if ( detach !== false ) this._fragment.unmount(); - this._fragment.destroy(); - this._fragment = null; - - this._state = {}; - this._destroyed = true; -}; - export default SvelteComponent; \ No newline at end of file diff --git a/test/runtime/samples/lifecycle-events/_config.js b/test/runtime/samples/lifecycle-events/_config.js index 3dcb0d5192..2a9d25564a 100644 --- a/test/runtime/samples/lifecycle-events/_config.js +++ b/test/runtime/samples/lifecycle-events/_config.js @@ -1,7 +1,7 @@ export default { - test ( assert, component ) { - assert.deepEqual( component.events, [ 'render' ]); + test(assert, component) { + assert.deepEqual(component.events, ['create']); component.destroy(); - assert.deepEqual( component.events, [ 'render', 'teardown' ]); + assert.deepEqual(component.events, ['create', 'destroy']); } }; diff --git a/test/runtime/samples/lifecycle-events/main.html b/test/runtime/samples/lifecycle-events/main.html index 1989d158c0..b39ce292d6 100644 --- a/test/runtime/samples/lifecycle-events/main.html +++ b/test/runtime/samples/lifecycle-events/main.html @@ -2,12 +2,12 @@ + \ No newline at end of file diff --git a/test/runtime/samples/set-after-destroy/_config.js b/test/runtime/samples/set-after-destroy/_config.js new file mode 100644 index 0000000000..1f8fb08f73 --- /dev/null +++ b/test/runtime/samples/set-after-destroy/_config.js @@ -0,0 +1,10 @@ +export default { + data: { + x: 1 + }, + + test(assert, component) { + component.destroy(); + component.set({ x: 2 }); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/set-after-destroy/main.html b/test/runtime/samples/set-after-destroy/main.html new file mode 100644 index 0000000000..e60a1a28e2 --- /dev/null +++ b/test/runtime/samples/set-after-destroy/main.html @@ -0,0 +1 @@ +
{{x}}
\ No newline at end of file From c799c416c18ecd3ef8bdf4fc5b483c8610245762 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 5 Aug 2017 22:21:15 -0400 Subject: [PATCH 2/5] no need to bind destroy, event handlers are called with the component as context --- src/generators/dom/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index ff8bcf8949..091ec685df 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -207,7 +207,7 @@ export default function dom( }; this._handlers = Object.create( null ); - ${templateProperties.ondestroy && `this._handlers.destroy = [@template.ondestroy.bind(this)]`} + ${templateProperties.ondestroy && `this._handlers.destroy = [@template.ondestroy]`} this._root = options._root || this; this._yield = options._yield; From 73c83d887f5ded3d4e1f4e560a1d5d7f646c365e Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 5 Aug 2017 22:22:23 -0400 Subject: [PATCH 3/5] replace set with noop instead of checking _destroyed --- src/shared/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/index.js b/src/shared/index.js index 87f4728f8f..7e4afb7dfe 100644 --- a/src/shared/index.js +++ b/src/shared/index.js @@ -5,6 +5,7 @@ export * from './utils.js'; export function destroy(detach) { if (!this._destroyed) { + this.set = noop; this.fire('destroy'); if (detach !== false) this._fragment.unmount(); @@ -123,7 +124,6 @@ export function onDev(eventName, handler) { } export function set(newState) { - if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; From 6ae5e323717a16d50152266fc26bbb9c1a81a07c Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 5 Aug 2017 22:24:31 -0400 Subject: [PATCH 4/5] update tests --- src/shared/index.js | 1 + .../samples/collapses-text-around-comments/expected-bundle.js | 2 +- test/js/samples/computed-collapsed-if/expected-bundle.js | 2 +- test/js/samples/css-media-query/expected-bundle.js | 2 +- test/js/samples/each-block-changed-check/expected-bundle.js | 2 +- test/js/samples/event-handlers-custom/expected-bundle.js | 4 +++- test/js/samples/if-block-no-update/expected-bundle.js | 2 +- test/js/samples/if-block-simple/expected-bundle.js | 2 +- test/js/samples/non-imported-component/expected-bundle.js | 4 +++- .../samples/onrender-onteardown-rewritten/expected-bundle.js | 4 ++-- test/js/samples/onrender-onteardown-rewritten/expected.js | 2 +- test/js/samples/setup-method/expected-bundle.js | 2 +- test/js/samples/use-elements-as-anchors/expected-bundle.js | 2 +- 13 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/shared/index.js b/src/shared/index.js index 7e4afb7dfe..67aa972f6f 100644 --- a/src/shared/index.js +++ b/src/shared/index.js @@ -1,4 +1,5 @@ import { assign } from './utils.js'; +import { noop } from './utils.js'; export * from './dom.js'; export * from './transitions.js'; export * from './utils.js'; 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 053e4c2c12..93e2086a26 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -39,6 +39,7 @@ function setAttribute(node, attribute, value) { function destroy(detach) { if (!this._destroyed) { + this.set = noop; this.fire('destroy'); if (detach !== false) this._fragment.unmount(); @@ -127,7 +128,6 @@ function on(eventName, handler) { } function set(newState) { - if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; diff --git a/test/js/samples/computed-collapsed-if/expected-bundle.js b/test/js/samples/computed-collapsed-if/expected-bundle.js index a52a992476..b0d7198a01 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -15,6 +15,7 @@ function assign(target) { function destroy(detach) { if (!this._destroyed) { + this.set = noop; this.fire('destroy'); if (detach !== false) this._fragment.unmount(); @@ -103,7 +104,6 @@ function on(eventName, handler) { } function set(newState) { - if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index 8ecdac50c1..b2ddda972b 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -35,6 +35,7 @@ function setAttribute(node, attribute, value) { function destroy(detach) { if (!this._destroyed) { + this.set = noop; this.fire('destroy'); if (detach !== false) this._fragment.unmount(); @@ -123,7 +124,6 @@ function on(eventName, handler) { } function set(newState) { - if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; 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 f77ab22f89..823ff6e216 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -48,6 +48,7 @@ function createText(data) { function destroy(detach) { if (!this._destroyed) { + this.set = noop; this.fire('destroy'); if (detach !== false) this._fragment.unmount(); @@ -136,7 +137,6 @@ function on(eventName, handler) { } function set(newState) { - if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index 12857effdd..5f26fec2c6 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -1,3 +1,5 @@ +function noop() {} + function assign(target) { var k, source, @@ -33,6 +35,7 @@ function createText(data) { function destroy(detach) { if (!this._destroyed) { + this.set = noop; this.fire('destroy'); if (detach !== false) this._fragment.unmount(); @@ -121,7 +124,6 @@ function on(eventName, handler) { } function set(newState) { - if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; 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 56ab031da3..2cbbc1ac22 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -39,6 +39,7 @@ function createComment() { function destroy(detach) { if (!this._destroyed) { + this.set = noop; this.fire('destroy'); if (detach !== false) this._fragment.unmount(); @@ -127,7 +128,6 @@ function on(eventName, handler) { } function set(newState) { - if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js index aca06df4f4..a311445c9d 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -39,6 +39,7 @@ function createComment() { function destroy(detach) { if (!this._destroyed) { + this.set = noop; this.fire('destroy'); if (detach !== false) this._fragment.unmount(); @@ -127,7 +128,6 @@ function on(eventName, handler) { } function set(newState) { - if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js index e9a1ef969d..448fcbb3f6 100644 --- a/test/js/samples/non-imported-component/expected-bundle.js +++ b/test/js/samples/non-imported-component/expected-bundle.js @@ -1,5 +1,7 @@ import Imported from 'Imported.html'; +function noop() {} + function assign(target) { var k, source, @@ -27,6 +29,7 @@ function createText(data) { function destroy(detach) { if (!this._destroyed) { + this.set = noop; this.fire('destroy'); if (detach !== false) this._fragment.unmount(); @@ -115,7 +118,6 @@ function on(eventName, handler) { } function set(newState) { - if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; diff --git a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js index 041326fdf3..f79163ae3e 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js @@ -15,6 +15,7 @@ function assign(target) { function destroy(detach) { if (!this._destroyed) { + this.set = noop; this.fire('destroy'); if (detach !== false) this._fragment.unmount(); @@ -103,7 +104,6 @@ function on(eventName, handler) { } function set(newState) { - if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; @@ -158,7 +158,7 @@ function SvelteComponent ( options ) { }; this._handlers = Object.create( null ); - this._handlers.destroy = [template.ondestroy.bind(this)]; + this._handlers.destroy = [template.ondestroy]; this._root = options._root || this; this._yield = options._yield; diff --git a/test/js/samples/onrender-onteardown-rewritten/expected.js b/test/js/samples/onrender-onteardown-rewritten/expected.js index f40d3e0a5c..78c1a7e480 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected.js @@ -31,7 +31,7 @@ function SvelteComponent ( options ) { }; this._handlers = Object.create( null ); - this._handlers.destroy = [template.ondestroy.bind(this)] + this._handlers.destroy = [template.ondestroy] this._root = options._root || this; this._yield = options._yield; diff --git a/test/js/samples/setup-method/expected-bundle.js b/test/js/samples/setup-method/expected-bundle.js index d27a1ef958..c4a3c6178e 100644 --- a/test/js/samples/setup-method/expected-bundle.js +++ b/test/js/samples/setup-method/expected-bundle.js @@ -15,6 +15,7 @@ function assign(target) { function destroy(detach) { if (!this._destroyed) { + this.set = noop; this.fire('destroy'); if (detach !== false) this._fragment.unmount(); @@ -103,7 +104,6 @@ function on(eventName, handler) { } function set(newState) { - if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; 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 dd1ed072bb..04890dcc7e 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -39,6 +39,7 @@ function createComment() { function destroy(detach) { if (!this._destroyed) { + this.set = noop; this.fire('destroy'); if (detach !== false) this._fragment.unmount(); @@ -127,7 +128,6 @@ function on(eventName, handler) { } function set(newState) { - if (this._destroyed) return; this._set(assign({}, newState)); if (this._root._lock) return; this._root._lock = true; From a2e85aec1de5ff06f6197ecca10462fcb96ea986 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 6 Aug 2017 14:26:19 -0400 Subject: [PATCH 5/5] 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 ) {