mirror of https://github.com/sveltejs/svelte
parent
0cdc431562
commit
e846ebb578
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
feat: allow `$derived($state())` for deep reactive deriveds
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
export class Test {
|
||||||
|
local_arr;
|
||||||
|
constructor(arr) {
|
||||||
|
this.local_arr = $derived($state(arr()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
<script>
|
||||||
|
import { Test } from "./Class.svelte.js";
|
||||||
|
let { arr } = $props();
|
||||||
|
|
||||||
|
let test = new Test(() => arr);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={()=>{
|
||||||
|
test.local_arr.push(test.local_arr.length + 1);
|
||||||
|
}}>push</button>
|
||||||
|
{#each test.local_arr as item}
|
||||||
|
<p>{item}</p>
|
||||||
|
{/each}
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ target, assert }) {
|
||||||
|
const [update_parent, push] = target.querySelectorAll('button');
|
||||||
|
let p_tags = target.querySelectorAll('p');
|
||||||
|
|
||||||
|
assert.equal(p_tags.length, 3);
|
||||||
|
assert.equal(p_tags[0].textContent, '1');
|
||||||
|
assert.equal(p_tags[1].textContent, '2');
|
||||||
|
assert.equal(p_tags[2].textContent, '3');
|
||||||
|
|
||||||
|
flushSync(() => {
|
||||||
|
push.click();
|
||||||
|
});
|
||||||
|
|
||||||
|
p_tags = target.querySelectorAll('p');
|
||||||
|
|
||||||
|
assert.equal(p_tags.length, 4);
|
||||||
|
assert.equal(p_tags[0].textContent, '1');
|
||||||
|
assert.equal(p_tags[1].textContent, '2');
|
||||||
|
assert.equal(p_tags[2].textContent, '3');
|
||||||
|
assert.equal(p_tags[3].textContent, '4');
|
||||||
|
|
||||||
|
flushSync(() => {
|
||||||
|
update_parent.click();
|
||||||
|
});
|
||||||
|
|
||||||
|
p_tags = target.querySelectorAll('p');
|
||||||
|
|
||||||
|
assert.equal(p_tags.length, 3);
|
||||||
|
assert.equal(p_tags[0].textContent, '4');
|
||||||
|
assert.equal(p_tags[1].textContent, '5');
|
||||||
|
assert.equal(p_tags[2].textContent, '6');
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
<script>
|
||||||
|
import Component from './Component.svelte';
|
||||||
|
let arr = $state.raw([1, 2, 3]);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={()=>{
|
||||||
|
arr = [4,5,6];
|
||||||
|
}}>update</button>
|
||||||
|
|
||||||
|
<Component {arr}/>
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
<script>
|
||||||
|
let { arr } = $props();
|
||||||
|
|
||||||
|
let local_arr = $derived($state(arr));
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={()=>{
|
||||||
|
local_arr.push(local_arr.length + 1);
|
||||||
|
}}>push</button>
|
||||||
|
{#each local_arr as item}
|
||||||
|
<p>{item}</p>
|
||||||
|
{/each}
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ target, assert }) {
|
||||||
|
const [update_parent, push] = target.querySelectorAll('button');
|
||||||
|
let p_tags = target.querySelectorAll('p');
|
||||||
|
|
||||||
|
assert.equal(p_tags.length, 3);
|
||||||
|
assert.equal(p_tags[0].textContent, '1');
|
||||||
|
assert.equal(p_tags[1].textContent, '2');
|
||||||
|
assert.equal(p_tags[2].textContent, '3');
|
||||||
|
|
||||||
|
flushSync(() => {
|
||||||
|
push.click();
|
||||||
|
});
|
||||||
|
|
||||||
|
p_tags = target.querySelectorAll('p');
|
||||||
|
|
||||||
|
assert.equal(p_tags.length, 4);
|
||||||
|
assert.equal(p_tags[0].textContent, '1');
|
||||||
|
assert.equal(p_tags[1].textContent, '2');
|
||||||
|
assert.equal(p_tags[2].textContent, '3');
|
||||||
|
assert.equal(p_tags[3].textContent, '4');
|
||||||
|
|
||||||
|
flushSync(() => {
|
||||||
|
update_parent.click();
|
||||||
|
});
|
||||||
|
|
||||||
|
p_tags = target.querySelectorAll('p');
|
||||||
|
|
||||||
|
assert.equal(p_tags.length, 3);
|
||||||
|
assert.equal(p_tags[0].textContent, '4');
|
||||||
|
assert.equal(p_tags[1].textContent, '5');
|
||||||
|
assert.equal(p_tags[2].textContent, '6');
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
<script>
|
||||||
|
import Component from './Component.svelte';
|
||||||
|
let arr = $state.raw([1, 2, 3]);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={()=>{
|
||||||
|
arr = [4,5,6];
|
||||||
|
}}>update</button>
|
||||||
|
|
||||||
|
<Component {arr}/>
|
||||||
Loading…
Reference in new issue