mirror of https://github.com/sveltejs/svelte
parent
d2c85f61ed
commit
b4cacabb42
@ -0,0 +1,8 @@
|
|||||||
|
<script>
|
||||||
|
$effect.pre(() => {
|
||||||
|
console.log('create A');
|
||||||
|
return () => console.log('destroy A');
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<h1>A</h1>
|
@ -0,0 +1,8 @@
|
|||||||
|
<script>
|
||||||
|
$effect.pre(() => {
|
||||||
|
console.log('create B');
|
||||||
|
return () => console.log('destroy B');
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<h1>B</h1>
|
@ -0,0 +1,13 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
import { flushSync } from 'svelte';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
mode: ['client', 'hydrate'],
|
||||||
|
|
||||||
|
async test({ assert, target, logs }) {
|
||||||
|
const [button] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
flushSync(() => button.click());
|
||||||
|
assert.deepEqual(logs, ['create A', 'destroy A', 'create B']);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,13 @@
|
|||||||
|
<script>
|
||||||
|
import A from './A.svelte';
|
||||||
|
import B from './B.svelte';
|
||||||
|
|
||||||
|
let condition = $state(true);
|
||||||
|
let Component = $derived(condition ? A : B);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => condition = !condition}>
|
||||||
|
toggle ({condition})
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<Component />
|
Loading…
Reference in new issue