mirror of https://github.com/sveltejs/svelte
Merge pull request #3886 from AlbertLucianto/fix/bind-out-of-sync
fix binding out of sync on reactive updatepull/3890/head
commit
9500282c7a
@ -0,0 +1,11 @@
|
||||
<script>
|
||||
export let count
|
||||
|
||||
function handleClick() {
|
||||
count += 1;
|
||||
}
|
||||
</script>
|
||||
|
||||
<button on:click={handleClick}>
|
||||
button {count}
|
||||
</button>
|
@ -0,0 +1,38 @@
|
||||
export default {
|
||||
html: `
|
||||
<button>main 0</button>
|
||||
<button>button 0</button>
|
||||
`,
|
||||
|
||||
async test({ assert, component, target, window }) {
|
||||
const event = new window.MouseEvent('click');
|
||||
|
||||
const buttons = target.querySelectorAll('button');
|
||||
|
||||
await buttons[0].dispatchEvent(event);
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<button>main 1</button>
|
||||
<button>button 1</button>
|
||||
`);
|
||||
|
||||
await buttons[1].dispatchEvent(event);
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<button>main 2</button>
|
||||
<button>button 2</button>
|
||||
`);
|
||||
|
||||
// reactive update, reset to 2
|
||||
await buttons[0].dispatchEvent(event);
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<button>main 2</button>
|
||||
<button>button 2</button>
|
||||
`);
|
||||
|
||||
// bound to main, reset to 2
|
||||
await buttons[1].dispatchEvent(event);
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<button>main 2</button>
|
||||
<button>button 2</button>
|
||||
`);
|
||||
}
|
||||
};
|
@ -0,0 +1,19 @@
|
||||
<script>
|
||||
import Button from './Button.svelte';
|
||||
|
||||
let count = 0;
|
||||
|
||||
$: if (count > 2) {
|
||||
count = 2;
|
||||
}
|
||||
|
||||
function handleClick() {
|
||||
count += 1;
|
||||
}
|
||||
</script>
|
||||
|
||||
<button on:click={handleClick}>
|
||||
main {count}
|
||||
</button>
|
||||
|
||||
<Button bind:count />
|
Loading…
Reference in new issue