-
-
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.
do not initialise slot fallback fragment unless necessary (#4514)
- Loading branch information
Showing
8 changed files
with
167 additions
and
45 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
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,7 @@ | ||
<script> | ||
import { model } from "./store.svelte"; | ||
export let value = ''; | ||
</script> | ||
|
||
<input bind:value={$model} /> | ||
{value} |
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,7 @@ | ||
<script> | ||
import Inner from "./Inner.svelte"; | ||
export let defaultValue = ''; | ||
export let slotProps = ''; | ||
</script> | ||
|
||
<slot {slotProps}><Inner value={defaultValue} /></slot> |
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,39 @@ | ||
export default { | ||
html: `<input> <input> <input>`, | ||
ssrHtml: `<input value="Blub"> <input value="Blub"> <input value="Blub">`, | ||
|
||
async test({ assert, target, component, window }) { | ||
const [input1, input2, inputFallback] = target.querySelectorAll("input"); | ||
|
||
assert.equal(component.getSubscriberCount(), 3); | ||
|
||
input1.value = "a"; | ||
await input1.dispatchEvent(new window.Event("input")); | ||
input1.value = "ab"; | ||
await input1.dispatchEvent(new window.Event("input")); | ||
assert.equal(input1.value, "ab"); | ||
assert.equal(input2.value, "ab"); | ||
assert.equal(inputFallback.value, "ab"); | ||
|
||
component.props = "hello"; | ||
|
||
assert.htmlEqual( | ||
target.innerHTML, | ||
` | ||
<input> hello | ||
<input> hello | ||
<input> | ||
` | ||
); | ||
|
||
component.fallback = "world"; | ||
assert.htmlEqual( | ||
target.innerHTML, | ||
` | ||
<input> hello | ||
<input> hello | ||
<input> world | ||
` | ||
); | ||
} | ||
}; |
23 changes: 23 additions & 0 deletions
23
test/runtime/samples/component-slot-fallback-2/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,23 @@ | ||
<script> | ||
import Outer from "./Outer.svelte"; | ||
import Inner from "./Inner.svelte"; | ||
import {model} from "./store.svelte"; | ||
export let props = ''; | ||
export let fallback = ''; | ||
export function getSubscriberCount() { | ||
return model.getCount(); | ||
} | ||
</script> | ||
|
||
<Outer slotProps={props} defaultValue={fallback} let:slotProps> | ||
<Inner value={slotProps} /> | ||
</Outer> | ||
|
||
<Outer slotProps={props} defaultValue={fallback} let:slotProps> | ||
<Inner value={slotProps} /> | ||
</Outer> | ||
|
||
<Outer slotProps={props} defaultValue={fallback}> | ||
</Outer> |
23 changes: 23 additions & 0 deletions
23
test/runtime/samples/component-slot-fallback-2/store.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,23 @@ | ||
<script context="module"> | ||
let value = 'Blub'; | ||
let count = 0; | ||
const subscribers = new Set(); | ||
export const model = { | ||
subscribe(fn) { | ||
subscribers.add(fn); | ||
count ++; | ||
fn(value); | ||
return () => { | ||
count--; | ||
subscribers.delete(fn); | ||
}; | ||
}, | ||
set(v) { | ||
value = v; | ||
subscribers.forEach(fn => fn(v)); | ||
}, | ||
getCount() { | ||
return count; | ||
} | ||
}; | ||
</script> |