-
-
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.
feat: derive destructured derived objects values (#10488)
* feat: derive destructured derived objects values * address feedback * address feedback
- Loading branch information
Showing
5 changed files
with
69 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"svelte": patch | ||
--- | ||
|
||
feat: derive destructured derived objects values |
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
28 changes: 28 additions & 0 deletions
28
packages/svelte/tests/runtime-runes/samples/derived-destructure/_config.js
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,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]); | ||
} | ||
}); |
2 changes: 2 additions & 0 deletions
2
packages/svelte/tests/runtime-runes/samples/derived-destructure/log.js
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,2 @@ | ||
/** @type {any[]} */ | ||
export const log = []; |
24 changes: 24 additions & 0 deletions
24
packages/svelte/tests/runtime-runes/samples/derived-destructure/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,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> |