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.
Mechanism for bubbling all events. Closes sveltejs#2837
- Loading branch information
Timothy Johnson
committed
Jun 2, 2020
1 parent
e606a0c
commit 3d6b990
Showing
12 changed files
with
127 additions
and
39 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
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
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
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
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
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
7 changes: 7 additions & 0 deletions
7
test/runtime/samples/event-handler-bubble-all-component/Widget.svelte
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,7 @@ | ||
<script> | ||
import { createEventDispatcher } from 'svelte'; | ||
const dispatch = createEventDispatcher(); | ||
</script> | ||
|
||
<button on:click='{() => dispatch("foo", { answer: 42 })}'>click me</button> |
18 changes: 18 additions & 0 deletions
18
test/runtime/samples/event-handler-bubble-all-component/_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,18 @@ | ||
export default { | ||
html: ` | ||
<button>click me</button> | ||
`, | ||
|
||
test({ assert, component, target, window }) { | ||
const button = target.querySelector('button'); | ||
const event = new window.MouseEvent('click'); | ||
|
||
let answer; | ||
component.$on('foo', event => { | ||
answer = event.detail.answer; | ||
}); | ||
|
||
button.dispatchEvent(event); | ||
assert.equal(answer, 42); | ||
} | ||
}; |
5 changes: 5 additions & 0 deletions
5
test/runtime/samples/event-handler-bubble-all-component/main.svelte
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,5 @@ | ||
<script> | ||
import Widget from './Widget.svelte'; | ||
</script> | ||
|
||
<Widget on:*/> |
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 @@ | ||
<button on:*>toggle</button> |
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,21 @@ | ||
export default { | ||
html: ` | ||
<button>toggle</button> | ||
`, | ||
|
||
async test({ assert, component, target, window }) { | ||
const button = target.querySelector('button'); | ||
const event = new window.MouseEvent('click'); | ||
|
||
await button.dispatchEvent(event); | ||
assert.htmlEqual(target.innerHTML, ` | ||
<button>toggle</button> | ||
<p>hello!</p> | ||
`); | ||
|
||
await button.dispatchEvent(event); | ||
assert.htmlEqual(target.innerHTML, ` | ||
<button>toggle</button> | ||
`); | ||
} | ||
}; |
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,11 @@ | ||
<script> | ||
import Button from './Button.svelte' | ||
export let visible; | ||
</script> | ||
|
||
<Button on:click='{() => visible = !visible}'>toggle</Button> | ||
|
||
{#if visible} | ||
<p>hello!</p> | ||
{/if} |