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

only set ref to null when tearing down if it is still current – closes #24

This commit is contained in:
Rich-Harris 2016-11-25 22:35:41 -05:00
parent 4d842ab8a2
commit c1d230d625
4 changed files with 30 additions and 2 deletions

View File

@ -116,7 +116,7 @@ export default function addComponentAttributes ( generator, node, local ) {
` );
local.teardown.push( deindent`
component.refs.${attribute.name} = null;
if ( component.refs.${attribute.name} === ${local.name} ) component.refs.${attribute.name} = null;
` );
}

View File

@ -166,7 +166,7 @@ export default function addElementAttributes ( generator, node, local ) {
` );
local.teardown.push( deindent`
component.refs.${attribute.name} = null;
if ( component.refs.${attribute.name} === ${local.name} ) component.refs.${attribute.name} = null;
` );
}

View File

@ -0,0 +1,23 @@
export default {
data: {
x: true
},
html: '<canvas data-x="true"></canvas>',
test ( assert, component, target ) {
let canvas = target.querySelector( 'canvas' );
assert.equal( canvas, component.refs.foo );
assert.equal( canvas.getAttribute( 'data-x' ), 'true' );
component.set({ x: false });
canvas = target.querySelector( 'canvas' );
assert.equal( canvas, component.refs.foo );
assert.equal( canvas.getAttribute( 'data-x' ), 'false' );
component.set({ x: true });
canvas = target.querySelector( 'canvas' );
assert.equal( canvas, component.refs.foo );
assert.equal( canvas.getAttribute( 'data-x' ), 'true' );
}
};

View File

@ -0,0 +1,5 @@
{{#if x}}
<canvas ref:foo data-x='true'></canvas>
{{else}}
<canvas ref:foo data-x='false'></canvas>
{{/if}}