mirror of https://github.com/sveltejs/svelte
Merge pull request #1145 from jacobmischka/fix-destructured-hoisting
Add destructured context container to usedContextspull/1149/head
commit
ca779a452d
@ -0,0 +1,32 @@
|
||||
export default {
|
||||
html: `
|
||||
<button>0: foo</button>
|
||||
<button>1: bar</button>
|
||||
<button>2: baz</button>
|
||||
|
||||
<p>first: </p>
|
||||
<p>second: </p>
|
||||
`,
|
||||
|
||||
test ( assert, component, target, window ) {
|
||||
const event = new window.MouseEvent( 'click' );
|
||||
|
||||
const buttons = target.querySelectorAll( 'button' );
|
||||
|
||||
buttons[1].dispatchEvent( event );
|
||||
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
<button>0: foo</button>
|
||||
<button>1: bar</button>
|
||||
<button>2: baz</button>
|
||||
|
||||
<p>first: 1</p>
|
||||
<p>second: bar</p>
|
||||
` );
|
||||
|
||||
assert.equal( component.get( 'first' ), '1' );
|
||||
assert.equal( component.get( 'second' ), 'bar' );
|
||||
|
||||
component.destroy();
|
||||
}
|
||||
};
|
@ -0,0 +1,36 @@
|
||||
{{#each items as [item0, item1]}}
|
||||
<button on:tap='set({ first: item0, second: item1 })'>
|
||||
{{item0}}: {{item1}}
|
||||
</button>
|
||||
{{/each}}
|
||||
|
||||
<p>first: {{first}}</p>
|
||||
<p>second: {{second}}</p>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data: () => ({
|
||||
x: 0,
|
||||
y: 0,
|
||||
first: '',
|
||||
second: '',
|
||||
items: [ [0, 'foo'], [1, 'bar'], [2, 'baz'] ]
|
||||
}),
|
||||
|
||||
events: {
|
||||
tap ( node, callback ) {
|
||||
function clickHandler ( event ) {
|
||||
callback();
|
||||
}
|
||||
|
||||
node.addEventListener( 'click', clickHandler, false );
|
||||
|
||||
return {
|
||||
teardown () {
|
||||
node.addEventListener( 'click', clickHandler, false );
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
Loading…
Reference in new issue