mirror of https://github.com/sveltejs/svelte
Merge d7d7c314cf into 5895c637b0
commit
deed13b9b5
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: make SvelteSet work with async mode
|
||||
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: defer batch resolution until earlier intersecting batches have committed
|
||||
@ -0,0 +1,145 @@
|
||||
import { tick } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
async test({ assert, target }) {
|
||||
await tick();
|
||||
|
||||
const [add, shift, pop] = target.querySelectorAll('button');
|
||||
|
||||
add.click();
|
||||
await tick();
|
||||
add.click();
|
||||
await tick();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>add</button>
|
||||
<button>shift</button>
|
||||
<button>pop</button>
|
||||
<p>pending=2 values.size=1 values=[1]</p>
|
||||
<hr>
|
||||
<p>1: true</p>
|
||||
<p>2: false</p>
|
||||
<p>3: false</p>
|
||||
<p>4: false</p>
|
||||
<p>5: false</p>
|
||||
<hr>
|
||||
<p>1</p>
|
||||
`
|
||||
);
|
||||
|
||||
shift.click();
|
||||
await tick();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>add</button>
|
||||
<button>shift</button>
|
||||
<button>pop</button>
|
||||
<p>pending=1 values.size=2 values=[1,2]</p>
|
||||
<hr>
|
||||
<p>1: true</p>
|
||||
<p>2: true</p>
|
||||
<p>3: false</p>
|
||||
<p>4: false</p>
|
||||
<p>5: false</p>
|
||||
<hr>
|
||||
<p>1</p>
|
||||
<p>2</p>
|
||||
`
|
||||
);
|
||||
|
||||
shift.click();
|
||||
await tick();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>add</button>
|
||||
<button>shift</button>
|
||||
<button>pop</button>
|
||||
<p>pending=0 values.size=3 values=[1,2,3]</p>
|
||||
<hr>
|
||||
<p>1: true</p>
|
||||
<p>2: true</p>
|
||||
<p>3: true</p>
|
||||
<p>4: false</p>
|
||||
<p>5: false</p>
|
||||
<hr>
|
||||
<p>1</p>
|
||||
<p>2</p>
|
||||
<p>3</p>
|
||||
`
|
||||
);
|
||||
|
||||
add.click();
|
||||
await tick();
|
||||
add.click();
|
||||
await tick();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>add</button>
|
||||
<button>shift</button>
|
||||
<button>pop</button>
|
||||
<p>pending=2 values.size=3 values=[1,2,3]</p>
|
||||
<hr>
|
||||
<p>1: true</p>
|
||||
<p>2: true</p>
|
||||
<p>3: true</p>
|
||||
<p>4: false</p>
|
||||
<p>5: false</p>
|
||||
<hr>
|
||||
<p>1</p>
|
||||
<p>2</p>
|
||||
<p>3</p>
|
||||
`
|
||||
);
|
||||
|
||||
pop.click();
|
||||
await tick();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>add</button>
|
||||
<button>shift</button>
|
||||
<button>pop</button>
|
||||
<p>pending=1 values.size=3 values=[1,2,3]</p>
|
||||
<hr>
|
||||
<p>1: true</p>
|
||||
<p>2: true</p>
|
||||
<p>3: true</p>
|
||||
<p>4: false</p>
|
||||
<p>5: false</p>
|
||||
<hr>
|
||||
<p>1</p>
|
||||
<p>2</p>
|
||||
<p>3</p>
|
||||
`
|
||||
);
|
||||
|
||||
pop.click();
|
||||
await tick();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<button>add</button>
|
||||
<button>shift</button>
|
||||
<button>pop</button>
|
||||
<p>pending=0 values.size=5 values=[1,2,3,4,5]</p>
|
||||
<hr>
|
||||
<p>1: true</p>
|
||||
<p>2: true</p>
|
||||
<p>3: true</p>
|
||||
<p>4: true</p>
|
||||
<p>5: true</p>
|
||||
<hr>
|
||||
<p>1</p>
|
||||
<p>2</p>
|
||||
<p>3</p>
|
||||
<p>4</p>
|
||||
<p>5</p>
|
||||
`
|
||||
);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,43 @@
|
||||
<script>
|
||||
import { SvelteSet } from 'svelte/reactivity';
|
||||
|
||||
let values = new SvelteSet([1]);
|
||||
|
||||
const queue = [];
|
||||
|
||||
function push(v) {
|
||||
if (v === 1) return v;
|
||||
|
||||
const p = Promise.withResolvers();
|
||||
queue.push(() => p.resolve(v));
|
||||
return p.promise;
|
||||
}
|
||||
|
||||
function addValue() {
|
||||
values.add(values.size + 1);
|
||||
}
|
||||
</script>
|
||||
|
||||
<button onclick={addValue}>add</button>
|
||||
<button onclick={() => queue.shift()?.()}>shift</button>
|
||||
<button onclick={() => queue.pop()?.()}>pop</button>
|
||||
|
||||
<p>
|
||||
pending={$effect.pending()}
|
||||
values.size={values.size}
|
||||
values=[{Array.from(values)}]
|
||||
</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>1: {values.has(1)}</p>
|
||||
<p>2: {values.has(2)}</p>
|
||||
<p>3: {values.has(3)}</p>
|
||||
<p>4: {values.has(4)}</p>
|
||||
<p>5: {values.has(5)}</p>
|
||||
|
||||
<hr>
|
||||
|
||||
{#each values as v(v)}
|
||||
<p>{await push(v)}</p>
|
||||
{/each}
|
||||
Loading…
Reference in new issue