Merge pull request #3171 from sveltejs/gh-3140

Pass context used in bindings down to slots
pull/3192/head
Rich Harris 6 years ago committed by GitHub
commit 8203c22f63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -138,7 +138,8 @@ export default class Expression {
}
if (template_scope.is_let(name)) {
if (!function_expression) {
if (!function_expression) { // TODO should this be `!lazy` ?
contextual_dependencies.add(name);
dependencies.add(name);
}
} else if (template_scope.names.has(name)) {

@ -0,0 +1,9 @@
<script>
export let items;
</script>
<div>
{#each items as item, index}
<slot {index}/>
{/each}
</div>

@ -0,0 +1,26 @@
export default {
html: `
<div>
<label>1: <input></label>
<label>2: <input></label>
<label>3: <input></label>
</div>
`,
ssrHtml: `
<div>
<label>1: <input value="a"></label>
<label>2: <input value="b"></label>
<label>3: <input value="c"></label>
</div>
`,
async test({ assert, component, target, window }) {
const inputs = target.querySelectorAll('input');
inputs[2].value = 'd';
await inputs[2].dispatchEvent(new window.Event('input'));
assert.deepEqual(component.letters, ['a', 'b', 'd']);
}
};

@ -0,0 +1,11 @@
<script>
import Nested from './Nested.svelte';
export let letters = ['a', 'b', 'c'];
</script>
<Nested items={letters} let:index>
<label>
{index + 1}: <input bind:value={letters[index]}>
</label>
</Nested>
Loading…
Cancel
Save