mirror of https://github.com/sveltejs/svelte
Merge pull request #809 from sveltejs/gh-804
prevent mutation bug from incorrectly calling observerpull/810/head
commit
7510f9c929
@ -0,0 +1 @@
|
||||
<input type="number" bind:value="field1">
|
@ -0,0 +1,28 @@
|
||||
export default {
|
||||
html: `
|
||||
<input type='number'>
|
||||
<p>field1: 1</p>
|
||||
<p>field2: 2</p>
|
||||
`,
|
||||
|
||||
test(assert, component, target, window) {
|
||||
let triggered = false;
|
||||
component.refs.nested.observe('field2', () => {
|
||||
triggered = true;
|
||||
}, { init: false });
|
||||
|
||||
const input = target.querySelector('input');
|
||||
const event = new window.Event('input');
|
||||
|
||||
input.value = 3;
|
||||
input.dispatchEvent(event); // will throw error if observer fires incorrectly
|
||||
|
||||
assert.ok(!triggered);
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<input type='number'>
|
||||
<p>field1: 3</p>
|
||||
<p>field2: 2</p>
|
||||
`);
|
||||
}
|
||||
};
|
@ -0,0 +1,21 @@
|
||||
<Nested ref:nested bind:field1="myObject.field1" bind:field2="myObject.field2" />
|
||||
<p>field1: {{myObject.field1}}</p>
|
||||
<p>field2: {{myObject.field2}}</p>
|
||||
|
||||
<script>
|
||||
import Nested from './Nested.html';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
Nested
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
myObject: {
|
||||
field1: 1,
|
||||
field2: 2
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
</script>
|
Loading…
Reference in new issue