0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 17:30:59 +01:00

remove elements at end of teardown sequence

This commit is contained in:
Rich-Harris 2016-11-20 12:40:37 -05:00
parent 44a2fd31f6
commit c2daa66b3c
3 changed files with 39 additions and 3 deletions

View File

@ -112,9 +112,7 @@ export default function generate ( parsed, template ) {
const updateStatements = [];
const teardownStatements = [
`${name}.parentNode.removeChild( ${name} );`
];
const teardownStatements = [];
const allUsedContexts = new Set();
@ -264,6 +262,10 @@ export default function generate ( parsed, template ) {
initStatements.push( deindent`
component.refs.${attribute.name} = ${name};
` );
teardownStatements.push( deindent`
component.refs.${attribute.name} = null;
` );
}
else {
@ -288,6 +290,8 @@ export default function generate ( parsed, template ) {
updateStatements.push( declarations );
}
teardownStatements.push( `${name}.parentNode.removeChild( ${name} );` );
current.initStatements.push( initStatements.join( '\n' ) );
if ( updateStatements.length ) current.updateStatements.push( updateStatements.join( '\n' ) );
current.teardownStatements.push( teardownStatements.join( '\n' ) );

View File

@ -0,0 +1,21 @@
import * as assert from 'assert';
// TODO gah, JSDOM appears to behave differently to real browsers here... probably need to raise an issue
export default {
html: '<input><!--#if visible-->',
test ( component ) {
component.refs.input.focus();
// this should NOT trigger blur event
component.set({ visible: false });
assert.ok( !component.get( 'blurred' ) );
component.set({ visible: true });
component.refs.input.focus();
// this SHOULD trigger blur event
component.refs.input.blur();
assert.ok( component.get( 'blurred' ) );
}
};

View File

@ -0,0 +1,11 @@
{{#if visible}}
<input ref:input on:blur='set({ blurred: true })'>
{{/if}}
<script>
export default {
data: () => ({
visible: true
})
};
</script>