mirror of https://github.com/sveltejs/svelte
fix: allow async destructured deriveds (#16444)
* fix: allow async destructured deriveds * add test * tweak * tweak --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/16445/head
parent
307ec228ff
commit
e1e7a75d71
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: allow async destructured deriveds
|
@ -0,0 +1,13 @@
|
|||||||
|
<script>
|
||||||
|
let count = $state(1);
|
||||||
|
|
||||||
|
let { squared, cubed } = $derived(await {
|
||||||
|
squared: count ** 2,
|
||||||
|
cubed: count ** 3
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => count++}>increment</button>
|
||||||
|
|
||||||
|
<p>{count} ** 2 = {squared}</p>
|
||||||
|
<p>{count} ** 3 = {cubed}</p>
|
@ -0,0 +1,31 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target }) {
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
const [increment] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>increment</button>
|
||||||
|
<p>1 ** 2 = 1</p>
|
||||||
|
<p>1 ** 3 = 1</p>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>increment</button>
|
||||||
|
<p>2 ** 2 = 4</p>
|
||||||
|
<p>2 ** 3 = 8</p>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,11 @@
|
|||||||
|
<script>
|
||||||
|
import Child from './Child.svelte';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:boundary>
|
||||||
|
<Child />
|
||||||
|
|
||||||
|
{#snippet pending()}
|
||||||
|
<p>pending</p>
|
||||||
|
{/snippet}
|
||||||
|
</svelte:boundary>
|
@ -0,0 +1,8 @@
|
|||||||
|
// we need this so the VS Code extension doesn't yell at us
|
||||||
|
export default {
|
||||||
|
compilerOptions: {
|
||||||
|
experimental: {
|
||||||
|
async: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in new issue