Merge pull request #1677 from sveltejs/gh-1660

Allow non-existent dynamic components to be destroyed
pull/1654/head
Rich Harris 7 years ago committed by GitHub
commit ba7a6c9bc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -505,7 +505,7 @@ export default class Component extends Node {
if (this.compiler.options.nestedTransitions) { if (this.compiler.options.nestedTransitions) {
block.builders.outro.addLine( block.builders.outro.addLine(
`${name}._fragment.o(#outrocallback);` `if (${name}) ${name}._fragment.o(#outrocallback);`
); );
} }
} }

@ -65,11 +65,18 @@ define("test", function() { "use strict";
function init(component, options) { function init(component, options) {
component._handlers = blankObject(); component._handlers = blankObject();
component._slots = blankObject();
component._bind = options._bind; component._bind = options._bind;
component.options = options; component.options = options;
component.root = options.root || component; component.root = options.root || component;
component.store = options.store || component.root.store; component.store = options.store || component.root.store;
if (!options.root) {
component._beforecreate = [];
component._oncreate = [];
component._aftercreate = [];
}
} }
function assign(tar, src) { function assign(tar, src) {
@ -125,11 +132,7 @@ define("test", function() { "use strict";
function set(newState) { function set(newState) {
this._set(assign({}, newState)); this._set(assign({}, newState));
if (this.root._lock) return; if (this.root._lock) return;
this.root._lock = true; flush(this.root);
callAll(this.root._beforecreate);
callAll(this.root._oncreate);
callAll(this.root._aftercreate);
this.root._lock = false;
} }
function _set(newState) { function _set(newState) {
@ -165,8 +168,16 @@ define("test", function() { "use strict";
return Object.create(null); return Object.create(null);
} }
function flush(component) {
component._lock = true;
callAll(component._beforecreate);
callAll(component._oncreate);
callAll(component._aftercreate);
component._lock = false;
}
function callAll(fns) { function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
return Main; return Main;
}); });

@ -0,0 +1,13 @@
export default {
data: {
x: true
},
nestedTransitions: true,
test(assert, component) {
component.set({
x: false
});
}
};

@ -0,0 +1,3 @@
{#if x}
<svelte:component this={null}/>
{/if}
Loading…
Cancel
Save