mirror of https://github.com/sveltejs/svelte
[fix] binding member expression should only invalidate the object, not the member property (#7008)
parent
fb419d2fda
commit
9f2b5afdf7
@ -0,0 +1,18 @@
|
|||||||
|
// binding member expression shouldn't invalidate the property name
|
||||||
|
export default {
|
||||||
|
async test({ assert, component, target, window }) {
|
||||||
|
const input = target.querySelector('input');
|
||||||
|
assert.deepEqual(component.logs.length, 1);
|
||||||
|
assert.equal(input.value, 'abc');
|
||||||
|
|
||||||
|
input.value = 'hij';
|
||||||
|
await input.dispatchEvent(new window.Event('input'));
|
||||||
|
|
||||||
|
assert.deepEqual(component.values.a, 'hij');
|
||||||
|
assert.deepEqual(component.logs.length, 1);
|
||||||
|
|
||||||
|
component.paths = ['b'];
|
||||||
|
assert.deepEqual(component.logs.length, 2);
|
||||||
|
assert.equal(input.value, 'def');
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,9 @@
|
|||||||
|
<script>
|
||||||
|
export let values = { a: 'abc', b: 'def' };
|
||||||
|
export let paths = ['a'];
|
||||||
|
export let logs = [];
|
||||||
|
|
||||||
|
$: paths && logs.push('paths updated');
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<input bind:value={values[paths[0]]} />
|
@ -0,0 +1,10 @@
|
|||||||
|
export default {
|
||||||
|
html: '<div>content</div><div>content</div><div>content</div>',
|
||||||
|
|
||||||
|
test({ assert, target, component }) {
|
||||||
|
const divs = target.querySelectorAll('div');
|
||||||
|
assert.equal(component.refs[0], divs[0]);
|
||||||
|
assert.equal(component.refs[1], divs[1]);
|
||||||
|
assert.equal(component.refs[2], divs[2]);
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,15 @@
|
|||||||
|
<script>
|
||||||
|
export let data = [ { id: '1' }, { id: '2' }, { id: '3' } ];
|
||||||
|
|
||||||
|
export let refs = [];
|
||||||
|
|
||||||
|
// note that this is NOT data.slice().reverse()
|
||||||
|
// as that wouldn't have triggered an infinite loop
|
||||||
|
$: list = data.reverse();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#each list as { id }, index (id)}
|
||||||
|
<div bind:this={refs[index]}>
|
||||||
|
content
|
||||||
|
</div>
|
||||||
|
{/each}
|
@ -0,0 +1,8 @@
|
|||||||
|
// binding member expression shouldn't invalidate the property name
|
||||||
|
export default {
|
||||||
|
test({ assert, component, target }) {
|
||||||
|
const div = target.querySelector('div');
|
||||||
|
assert.equal(div, component.container.a);
|
||||||
|
assert.deepEqual(component.logs.length, 1);
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,9 @@
|
|||||||
|
<script>
|
||||||
|
export let container = {};
|
||||||
|
export let paths = ['a'];
|
||||||
|
export let logs = [];
|
||||||
|
|
||||||
|
$: paths && logs.push('paths updated');
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div bind:this={container[paths[0]]} />
|
Loading…
Reference in new issue