mirror of https://github.com/sveltejs/svelte
parent
60a71cc593
commit
1534c1d0bb
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: invoke `$state.link` callback at the correct time
|
@ -0,0 +1,22 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: `<button>0</button><button>0</button>`,
|
||||
|
||||
test({ assert, target, logs }) {
|
||||
const [btn1, btn2] = target.querySelectorAll('button');
|
||||
|
||||
flushSync(() => btn1.click());
|
||||
assert.deepEqual(logs, ['in callback 1']);
|
||||
assert.htmlEqual(target.innerHTML, `<button>1</button><button>1</button>`);
|
||||
|
||||
flushSync(() => btn2.click());
|
||||
assert.deepEqual(logs, ['in callback 1']);
|
||||
assert.htmlEqual(target.innerHTML, `<button>1</button><button>2</button>`);
|
||||
|
||||
flushSync(() => btn1.click());
|
||||
assert.deepEqual(logs, ['in callback 1', 'in callback 2']);
|
||||
assert.htmlEqual(target.innerHTML, `<button>2</button><button>2</button>`);
|
||||
}
|
||||
});
|
@ -0,0 +1,10 @@
|
||||
<script>
|
||||
let a = $state(0);
|
||||
let b = $state.link(a, (value) => {
|
||||
console.log(`in callback ${value}`);
|
||||
b = value;
|
||||
});
|
||||
</script>
|
||||
|
||||
<button onclick={() => a++}>{a}</button>
|
||||
<button onclick={() => b++}>{b}</button>
|
Loading…
Reference in new issue