-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix function slot props based on context (#5607)
- Loading branch information
Showing
13 changed files
with
202 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
test/runtime/samples/component-slot-context-props-each-nested/Nested.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<script> | ||
let keys = ['a', 'b']; | ||
let items = ['c', 'd']; | ||
export let log; | ||
function setKey(key, value, item) { | ||
log.push(`setKey(${key}, ${value}, ${item})`); | ||
} | ||
</script> | ||
|
||
{#each items as item (item)} | ||
{#each keys as key (key)} | ||
<slot {key} {item} set={(value) => setKey(key, value, item)} /> | ||
{/each} | ||
{/each} |
36 changes: 36 additions & 0 deletions
36
test/runtime/samples/component-slot-context-props-each-nested/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export default { | ||
html: ` | ||
<button type="button">Set a-c</button> | ||
<button type="button">Set b-c</button> | ||
<button type="button">Set a-d</button> | ||
<button type="button">Set b-d</button> | ||
`, | ||
async test({ assert, target, window, component }) { | ||
const [btn1, btn2, btn3, btn4] = target.querySelectorAll('button'); | ||
const click = new window.MouseEvent('click'); | ||
|
||
await btn1.dispatchEvent(click); | ||
assert.deepEqual(component.log, ['setKey(a, value-a-c, c)']); | ||
|
||
await btn2.dispatchEvent(click); | ||
assert.deepEqual(component.log, [ | ||
'setKey(a, value-a-c, c)', | ||
'setKey(b, value-b-c, c)' | ||
]); | ||
|
||
await btn3.dispatchEvent(click); | ||
assert.deepEqual(component.log, [ | ||
'setKey(a, value-a-c, c)', | ||
'setKey(b, value-b-c, c)', | ||
'setKey(a, value-a-d, d)' | ||
]); | ||
|
||
await btn4.dispatchEvent(click); | ||
assert.deepEqual(component.log, [ | ||
'setKey(a, value-a-c, c)', | ||
'setKey(b, value-b-c, c)', | ||
'setKey(a, value-a-d, d)', | ||
'setKey(b, value-b-d, d)' | ||
]); | ||
} | ||
}; |
8 changes: 8 additions & 0 deletions
8
test/runtime/samples/component-slot-context-props-each-nested/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<script> | ||
import Nested from './Nested.svelte'; | ||
export let log = []; | ||
</script> | ||
|
||
<Nested {log} let:set let:key let:item> | ||
<button type="button" on:click={() => set(`value-${key}-${item}`)}>Set {key}-{item}</button> | ||
</Nested> |
11 changes: 11 additions & 0 deletions
11
test/runtime/samples/component-slot-context-props-each/Nested.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script> | ||
let keys = ['a', 'b']; | ||
export let log; | ||
function setKey(key, value) { | ||
log.push(`setKey(${key}, ${value})`); | ||
} | ||
</script> | ||
|
||
{#each keys as key (key)} | ||
<slot {key} set={(value) => setKey(key, value)} /> | ||
{/each} |
19 changes: 19 additions & 0 deletions
19
test/runtime/samples/component-slot-context-props-each/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export default { | ||
html: ` | ||
<button type="button">Set a</button> | ||
<button type="button">Set b</button> | ||
`, | ||
async test({ assert, target, window, component }) { | ||
const [btn1, btn2] = target.querySelectorAll('button'); | ||
const click = new window.MouseEvent('click'); | ||
|
||
await btn1.dispatchEvent(click); | ||
assert.deepEqual(component.log, ['setKey(a, value-a)']); | ||
|
||
await btn2.dispatchEvent(click); | ||
assert.deepEqual(component.log, [ | ||
'setKey(a, value-a)', | ||
'setKey(b, value-b)' | ||
]); | ||
} | ||
}; |
8 changes: 8 additions & 0 deletions
8
test/runtime/samples/component-slot-context-props-each/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<script> | ||
import Nested from './Nested.svelte'; | ||
export let log = []; | ||
</script> | ||
|
||
<Nested {log} let:set let:key> | ||
<button type="button" on:click={() => set(`value-${key}`)}>Set {key}</button> | ||
</Nested> |
9 changes: 9 additions & 0 deletions
9
test/runtime/samples/component-slot-context-props-let/Inner.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<script> | ||
export let log; | ||
function setKey(key, value) { | ||
log.push(`setKey(${key}, ${value})`); | ||
} | ||
</script> | ||
|
||
<slot key="a" set={setKey} /> | ||
<slot key="b" set={setKey} /> |
8 changes: 8 additions & 0 deletions
8
test/runtime/samples/component-slot-context-props-let/Nested.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<script> | ||
import Inner from './Inner.svelte'; | ||
export let log; | ||
</script> | ||
|
||
<Inner {log} let:key let:set> | ||
<slot {key} set={(value) => set(key, value)} /> | ||
</Inner> |
19 changes: 19 additions & 0 deletions
19
test/runtime/samples/component-slot-context-props-let/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export default { | ||
html: ` | ||
<button type="button">Set a</button> | ||
<button type="button">Set b</button> | ||
`, | ||
async test({ assert, target, window, component }) { | ||
const [btn1, btn2] = target.querySelectorAll('button'); | ||
const click = new window.MouseEvent('click'); | ||
|
||
await btn1.dispatchEvent(click); | ||
assert.deepEqual(component.log, ['setKey(a, value-a)']); | ||
|
||
await btn2.dispatchEvent(click); | ||
assert.deepEqual(component.log, [ | ||
'setKey(a, value-a)', | ||
'setKey(b, value-b)' | ||
]); | ||
} | ||
}; |
8 changes: 8 additions & 0 deletions
8
test/runtime/samples/component-slot-context-props-let/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<script> | ||
import Nested from './Nested.svelte'; | ||
export let log = []; | ||
</script> | ||
|
||
<Nested {log} let:set let:key> | ||
<button type="button" on:click={() => set(`value-${key}`)}>Set {key}</button> | ||
</Nested> |