Skip to content

Commit

Permalink
Merge pull request #563 from sveltejs/gh-561
Browse files Browse the repository at this point in the history
Fix yield block placement
  • Loading branch information
Rich-Harris authored May 4, 2017
2 parents cedd318 + dd2e5e8 commit 90d2e7f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/generators/dom/visitors/YieldTag.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export default function visitYieldTag ( generator, block, state ) {
block.builders.mount.addLine(
`${block.component}._yield && ${block.component}._yield.mount( ${state.parentNode || block.target}, null );`
const parentNode = state.parentNode || block.target;

( state.parentNode ? block.builders.create : block.builders.mount ).addLine(
`if ( ${block.component}._yield ) ${block.component}._yield.mount( ${parentNode}, null );`
);

block.builders.destroy.addLine(
`${block.component}._yield && ${block.component}._yield.destroy( detach );`
`if ( ${block.component}._yield ) ${block.component}._yield.destroy( detach );`
);
}
6 changes: 6 additions & 0 deletions test/runtime/samples/component-yield-placement/Modal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class='modal-background' on:click='destroy()'></div>

<div class='modal'>
{{yield}}
<button on:click='destroy()'>close modal</button>
</div>
25 changes: 25 additions & 0 deletions test/runtime/samples/component-yield-placement/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export default {
data: {
showModal: true
},

html: `
<div class='modal-background'></div>
<div class='modal'>
<h2>Hello!</h2>
<button>close modal</button>
</div>
`,

test ( assert, component, target, window ) {
const button = target.querySelector( 'button' );
const click = new window.MouseEvent( 'click' );

button.dispatchEvent( click );

assert.htmlEqual( target.innerHTML, `
<button>show modal</button>
`);
}
};
15 changes: 15 additions & 0 deletions test/runtime/samples/component-yield-placement/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{#if showModal}}
<Modal on:destroy='set({ showModal: false })'>
<h2>Hello!</h2>
</Modal>
{{else}}
<button on:click='set({ showModal: true })'>show modal</button>
{{/if}}

<script>
import Modal from './Modal.html';

export default {
components: { Modal }
};
</script>

0 comments on commit 90d2e7f

Please sign in to comment.