Fix each blocks not unmounting components correctly (#3056)

* Prevent outro from invoking detach multiple times

* Add tests for unmounting entries in an each block

* Remove redundant function for removing from lookup
pull/3062/head
Bryan Terce 6 years ago committed by Rich Harris
parent f9054bc439
commit 7b5f176764

@ -7,7 +7,7 @@ export function destroy_block(block, lookup) {
export function outro_and_destroy_block(block, lookup) {
transition_out(block, 1, () => {
destroy_block(block, lookup);
lookup.delete(block.key);
});
}

@ -0,0 +1,5 @@
<script>
export let title;
</script>
<p>{title}</p>

@ -0,0 +1,27 @@
export default {
props: {
titles: [{ name: 'a', }, { name: 'b' }, { name: 'c' }]
},
html: `
<p>a</p>
<p>b</p>
<p>c</p>
`,
test({ assert, component, target }) {
component.titles = [{ name: 'b' }, { name: 'c' }];
assert.htmlEqual(target.innerHTML, `
<p>b</p>
<p>c</p>
`);
component.titles = [{ name: 'c' }];
assert.htmlEqual(target.innerHTML, `
<p>c</p>
`);
}
};

@ -0,0 +1,9 @@
<script>
import Nested from './Nested.svelte';
export let titles;
</script>
{#each titles as title (title.name)}
<Nested title="{title.name}"/>
{/each}
Loading…
Cancel
Save