mirror of https://github.com/sveltejs/svelte
feat: derive destructured derived objects values (#10488)
* feat: derive destructured derived objects values * address feedback * address feedbackpull/10500/head
parent
302c379e01
commit
4b274dd00d
@ -0,0 +1,5 @@
|
||||
---
|
||||
"svelte": patch
|
||||
---
|
||||
|
||||
feat: derive destructured derived objects values
|
@ -0,0 +1,28 @@
|
||||
import { test } from '../../test';
|
||||
import { flushSync } from 'svelte';
|
||||
import { log } from './log.js';
|
||||
|
||||
export default test({
|
||||
before_test() {
|
||||
log.length = 0;
|
||||
},
|
||||
|
||||
async test({ assert, target }) {
|
||||
const [b1, b2, b3] = target.querySelectorAll('button');
|
||||
log.length = 0;
|
||||
flushSync(() => {
|
||||
b1.click();
|
||||
});
|
||||
assert.deepEqual(log, ['a', 1]);
|
||||
log.length = 0;
|
||||
flushSync(() => {
|
||||
b2.click();
|
||||
});
|
||||
assert.deepEqual(log, ['b', 1]);
|
||||
log.length = 0;
|
||||
flushSync(() => {
|
||||
b3.click();
|
||||
});
|
||||
assert.deepEqual(log, ['c', 1]);
|
||||
}
|
||||
});
|
@ -0,0 +1,2 @@
|
||||
/** @type {any[]} */
|
||||
export const log = [];
|
@ -0,0 +1,24 @@
|
||||
<script>
|
||||
import { log } from './log.js';
|
||||
|
||||
let a = $state(0);
|
||||
let b = $state(0);
|
||||
let c = $state(0);
|
||||
const {a: a1, b: b1, c: c1} = $derived({a, b, c});
|
||||
|
||||
$effect(() => {
|
||||
log.push('a', a1)
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
log.push('b', b1)
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
log.push('c', c1)
|
||||
});
|
||||
</script>
|
||||
|
||||
<button onclick={() => a++}>{a1}</button>
|
||||
<button onclick={() => b++}>{b1}</button>
|
||||
<button onclick={() => c++}>{c1}</button>
|
Loading…
Reference in new issue