Skip to content

Commit

Permalink
only set ref to null when tearing down if it is still current – closes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Nov 26, 2016
1 parent 4d842ab commit c1d230d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
` );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
` );
}

Expand Down
23 changes: 23 additions & 0 deletions test/compiler/refs-unset/_config.js
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions test/compiler/refs-unset/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{#if x}}
<canvas ref:foo data-x='true'></canvas>
{{else}}
<canvas ref:foo data-x='false'></canvas>
{{/if}}

0 comments on commit c1d230d

Please sign in to comment.