From 620077227f7d42310cbaee028c30e7f2e5e7404f Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 22 Aug 2018 23:01:57 -0400 Subject: [PATCH 1/2] allow non-existent dynamic components to be destroyed (#1660) --- src/compile/nodes/Component.ts | 2 +- .../dynamic-component-destroy-null/_config.js | 13 +++++++++++++ .../dynamic-component-destroy-null/main.html | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/dynamic-component-destroy-null/_config.js create mode 100644 test/runtime/samples/dynamic-component-destroy-null/main.html diff --git a/src/compile/nodes/Component.ts b/src/compile/nodes/Component.ts index fb244e5fba..526af029c8 100644 --- a/src/compile/nodes/Component.ts +++ b/src/compile/nodes/Component.ts @@ -505,7 +505,7 @@ export default class Component extends Node { if (this.compiler.options.nestedTransitions) { block.builders.outro.addLine( - `${name}._fragment.o(#outrocallback);` + `if (${name}) ${name}._fragment.o(#outrocallback);` ); } } diff --git a/test/runtime/samples/dynamic-component-destroy-null/_config.js b/test/runtime/samples/dynamic-component-destroy-null/_config.js new file mode 100644 index 0000000000..b85e35e259 --- /dev/null +++ b/test/runtime/samples/dynamic-component-destroy-null/_config.js @@ -0,0 +1,13 @@ +export default { + data: { + x: true + }, + + nestedTransitions: true, + + test(assert, component) { + component.set({ + x: false + }); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-destroy-null/main.html b/test/runtime/samples/dynamic-component-destroy-null/main.html new file mode 100644 index 0000000000..401b86d1f6 --- /dev/null +++ b/test/runtime/samples/dynamic-component-destroy-null/main.html @@ -0,0 +1,3 @@ +{#if x} + +{/if} \ No newline at end of file From 3785a6d2ad10b9a216d935f45f653390b045c105 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 22 Aug 2018 23:02:22 -0400 Subject: [PATCH 2/2] update unrelated test --- test/cli/samples/amd/expected/Main.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/test/cli/samples/amd/expected/Main.js b/test/cli/samples/amd/expected/Main.js index 5a902064b6..35f4b57186 100644 --- a/test/cli/samples/amd/expected/Main.js +++ b/test/cli/samples/amd/expected/Main.js @@ -65,11 +65,18 @@ define("test", function() { "use strict"; function init(component, options) { component._handlers = blankObject(); + component._slots = blankObject(); component._bind = options._bind; component.options = options; component.root = options.root || component; component.store = options.store || component.root.store; + + if (!options.root) { + component._beforecreate = []; + component._oncreate = []; + component._aftercreate = []; + } } function assign(tar, src) { @@ -125,11 +132,7 @@ define("test", function() { "use strict"; function set(newState) { this._set(assign({}, newState)); if (this.root._lock) return; - this.root._lock = true; - callAll(this.root._beforecreate); - callAll(this.root._oncreate); - callAll(this.root._aftercreate); - this.root._lock = false; + flush(this.root); } function _set(newState) { @@ -165,8 +168,16 @@ define("test", function() { "use strict"; 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) { while (fns && fns.length) fns.shift()(); } return Main; -}); +}); \ No newline at end of file