fix reactivity when binding to each context (#4878)

pull/4913/head
Tan Li Hau 4 years ago committed by GitHub
parent 3330c3fbab
commit 11967804af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,6 +10,7 @@
* Add `muted` binding for media elements ([#2998](https://github.com/sveltejs/svelte/issues/2998))
* Fix let-less `<slot>` with context overflow ([#4624](https://github.com/sveltejs/svelte/issues/4624))
* Fix `use:` actions being recreated when a keyed `{#each}` is reordered ([#4693](https://github.com/sveltejs/svelte/issues/4693))
* Fix reactivity when binding directly to `{#each}` context ([#4879](https://github.com/sveltejs/svelte/issues/4879))
## 3.22.3

@ -60,7 +60,7 @@ export default class Binding extends Node {
scope.dependencies_for_name.get(name).forEach(name => {
const variable = component.var_lookup.get(name);
if (variable) {
variable[this.expression.node.type === 'MemberExpression' ? 'mutated' : 'reassigned'] = true;
variable.mutated = true;
}
});
} else {

@ -0,0 +1,27 @@
let value;
let called = 0;
function callback(_value) {
called ++;
value = _value;
}
export default {
props: {
callback,
},
async test({ assert, component, target, window }) {
assert.equal(called, 1);
const input = target.querySelector('input');
const event = new window.Event('input');
input.value = 'h';
await input.dispatchEvent(event);
assert.equal(called, 2);
assert.equal(value.length, 3);
assert.equal(value[0], 'h');
assert.equal(value[1], '2');
assert.equal(value[2], '3');
}
};

@ -0,0 +1,10 @@
<script>
const refs = ['1','2','3']
export let callback = () => {};
$: callback(refs);
</script>
{#each refs as ref}
<input bind:value={ref} />
{/each}
Loading…
Cancel
Save