Merge pull request #727 from sveltejs/gh-706

clear refs in destroy, not unmount, so that refs are populated in ondestroy
pull/733/head
Rich Harris 8 years ago committed by GitHub
commit dbf635b445

@ -17,7 +17,7 @@ export default function visitRef(
`#component.refs.${name} = ${state.parentNode};`
);
block.builders.unmount.addLine(deindent`
block.builders.destroy.addLine(deindent`
if ( #component.refs.${name} === ${state.parentNode} ) #component.refs.${name} = null;
`);

@ -0,0 +1,9 @@
<div ref:element></div>
<script>
export default {
ondestroy() {
this.refOnDestroy = this.refs.element;
}
};
</script>

@ -0,0 +1,9 @@
export default {
test(assert, component, target) {
const top = component.refs.top;
const div = target.querySelector('div');
component.set({ visible: false });
assert.equal(top.refOnDestroy, div);
}
};

@ -0,0 +1,18 @@
{{#if visible}}
<Top ref:top></Top>
{{/if}}
<script>
import Top from './Top.html';
export default {
data() {
return {
visible: true
};
},
components: {
Top
}
};
</script>
Loading…
Cancel
Save