pull/12315/head
Dominic Gannaway 2 years ago
parent 4ce5f37c24
commit b985eea817

@ -0,0 +1,28 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
async test({ assert, target, logs }) {
const [b1, b2, b3] = target.querySelectorAll('button');
flushSync(() => {
b1.click();
b2.click();
});
assert.deepEqual(logs, [0, 1]);
flushSync(() => {
b3.click();
});
assert.deepEqual(logs, [0, 1, 'cleanup 1', 'cleanup 2']);
flushSync(() => {
b1.click();
b2.click();
});
assert.deepEqual(logs, [0, 1, 'cleanup 1', 'cleanup 2']);
}
});

@ -0,0 +1,11 @@
<script>
import { with_root } from './root.svelte.js';
let x = $state(0);
let y = $state(0);
const cleanup = with_root(() => x)
</script>
<button onclick={() => x++}>{x}</button>
<button onclick={() => y++}>{y}</button>
<button onclick={cleanup}>cleanup</button>

@ -0,0 +1,20 @@
export function with_root(get_x) {
const cleanup = $effect.root(() => {
$effect(() => {
console.log(get_x());
});
const nested_cleanup = $effect.root(() => {
return () => {
console.log('cleanup 2');
};
});
return () => {
console.log('cleanup 1');
nested_cleanup();
};
});
return cleanup;
}
Loading…
Cancel
Save