mirror of https://github.com/sveltejs/svelte
fix: correctly call exported state (#10114)
fixes #10104 also cleans up related code and adds support for destructuring `$state.frozen`pull/10121/head
parent
92408e1506
commit
b3d185da29
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: correctly call exported state
|
@ -1,13 +1,11 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: `<button>0</button>`,
|
||||
html: `<button>0 / 0</button>`,
|
||||
|
||||
async test({ assert, target, window }) {
|
||||
async test({ assert, target }) {
|
||||
const btn = target.querySelector('button');
|
||||
const clickEvent = new window.Event('click', { bubbles: true });
|
||||
await btn?.dispatchEvent(clickEvent);
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `<button>1</button>`);
|
||||
await btn?.click();
|
||||
assert.htmlEqual(target.innerHTML, `<button>1 / 1</button>`);
|
||||
}
|
||||
});
|
||||
|
@ -0,0 +1,12 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async test({ assert, target }) {
|
||||
assert.htmlEqual(target.innerHTML, `0 0 <button>0 / 0</button>`);
|
||||
const [btn] = target.querySelectorAll('button');
|
||||
|
||||
btn?.click();
|
||||
await Promise.resolve();
|
||||
assert.htmlEqual(target.innerHTML, '0 1 <button>0 / 1</button>');
|
||||
}
|
||||
});
|
@ -0,0 +1,7 @@
|
||||
<script>
|
||||
import Sub from './sub.svelte'
|
||||
let sub = $state();
|
||||
</script>
|
||||
|
||||
<Sub bind:this={sub} />
|
||||
<button on:click={() => sub.increment()}>{sub?.count1.value} / {sub?.count2.value}</button>
|
@ -0,0 +1,15 @@
|
||||
<script>
|
||||
export const count1 = $state.frozen({value: 0});
|
||||
export const count2 = $state({value: 0});
|
||||
|
||||
export function increment() {
|
||||
count2.value += 1;
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
{count1.value}
|
||||
{count2.value}
|
||||
|
||||
<!-- so that count1/2 become sources -->
|
||||
<svelte:options accessors />
|
Loading…
Reference in new issue