-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prevent stale state in component event handlers - fixes #1353
- Loading branch information
1 parent
a6262ce
commit 35a5d8f
Showing
4 changed files
with
57 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<button on:click><slot/></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,30 @@ | ||
export default { | ||
data: { | ||
value: 1, | ||
}, | ||
|
||
test(assert, component, target, window) { | ||
const buttons = target.querySelectorAll('button'); | ||
const click = new window.MouseEvent('click'); | ||
|
||
const events = []; | ||
component.on('value', event => { | ||
events.push(event); | ||
}); | ||
|
||
buttons[0].dispatchEvent(click); | ||
buttons[1].dispatchEvent(click); | ||
|
||
component.set({ value: 2 }); | ||
|
||
buttons[0].dispatchEvent(click); | ||
buttons[1].dispatchEvent(click); | ||
|
||
assert.deepEqual(events, [ | ||
{ value: 1 }, | ||
{ value: 1 }, | ||
{ value: 2 }, | ||
{ value: 2 } | ||
]); | ||
}, | ||
}; |
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,20 @@ | ||
<Button on:click="handleClick()">one</Button> | ||
<Button on:click="fire('value', {value})">two</Button> | ||
|
||
<script> | ||
import Button from './Button.html'; | ||
|
||
export default { | ||
components: { | ||
Button | ||
}, | ||
|
||
methods: { | ||
handleClick() { | ||
const { value } = this.get(); | ||
this.fire('value', { value }); | ||
} | ||
} | ||
|
||
} | ||
</script> |