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:
parent
4d842ab8a2
commit
c1d230d625
@ -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;
|
||||
` );
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
` );
|
||||
}
|
||||
|
||||
|
23
test/compiler/refs-unset/_config.js
Normal file
23
test/compiler/refs-unset/_config.js
Normal 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' );
|
||||
}
|
||||
};
|
5
test/compiler/refs-unset/main.html
Normal file
5
test/compiler/refs-unset/main.html
Normal file
@ -0,0 +1,5 @@
|
||||
{{#if x}}
|
||||
<canvas ref:foo data-x='true'></canvas>
|
||||
{{else}}
|
||||
<canvas ref:foo data-x='false'></canvas>
|
||||
{{/if}}
|
Loading…
Reference in New Issue
Block a user