mirror of https://github.com/sveltejs/svelte
parent
60eaa2862e
commit
c57e673c84
@ -0,0 +1,58 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
skip: true, // TODO this one is tricky
|
||||||
|
|
||||||
|
async test({ assert, target }) {
|
||||||
|
const [increment, a, b] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
a.click();
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>increment</button>
|
||||||
|
<button>shift a</button>
|
||||||
|
<button>shift b</button>
|
||||||
|
<p>a: 0</p>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
a.click();
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>increment</button>
|
||||||
|
<button>shift a</button>
|
||||||
|
<button>shift b</button>
|
||||||
|
<p>a: 0</p>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
b.click();
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>increment</button>
|
||||||
|
<button>shift a</button>
|
||||||
|
<button>shift b</button>
|
||||||
|
<p>b: 0</p
|
||||||
|
`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,34 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
let count = $state(0);
|
||||||
|
|
||||||
|
let a = [];
|
||||||
|
let b = [];
|
||||||
|
|
||||||
|
function push(deferreds, value) {
|
||||||
|
const deferred = Promise.withResolvers();
|
||||||
|
deferreds.push({ deferred, value });
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => count += 1}>increment</button>
|
||||||
|
<button onclick={() => {
|
||||||
|
const d = a.shift();
|
||||||
|
d?.deferred.resolve(d.value);
|
||||||
|
}}>shift a</button>
|
||||||
|
<button onclick={() => {
|
||||||
|
const d = b.shift();
|
||||||
|
d?.deferred.resolve(d.value);
|
||||||
|
}}>shift b</button>
|
||||||
|
|
||||||
|
<svelte:boundary>
|
||||||
|
{#if count % 2 === 0}
|
||||||
|
<p>a: {await push(a, count)}</p>
|
||||||
|
{:else}
|
||||||
|
<p>b: {await push(b, count)}</p>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#snippet pending()}
|
||||||
|
<p>loading...</p>
|
||||||
|
{/snippet}
|
||||||
|
</svelte:boundary>
|
Loading…
Reference in new issue