forked from sveltejs/svelte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add destructured context container to usedContexts
Fixes sveltejs#1139
- Loading branch information
1 parent
56e9343
commit 31de60e
Showing
3 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
test/runtime/samples/event-handler-custom-each-destructured/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
}; |
36 changes: 36 additions & 0 deletions
36
test/runtime/samples/event-handler-custom-each-destructured/main.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |