Skip to content

Commit cec6387

Browse files
committed
refactor: adjusting demo code to test edge cases
1 parent 4fcf4c6 commit cec6387

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

KNOWN-ISSUES.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@
22

33
For now it breaks Svelte preview REPL as it can't compile ts on the fly
44

5-
[ ] Problem with positioning
6-
[ ] Problem with visible index range events
7-
[ ] Problem with offset scrolling
8-
[ ] Problem with focus positioning
5+
[ ] Problem with focus positioning on the edge size

src/routes/examples/positioningNew/code.svelte

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
import { ALIGNMENT, SCROLL_BEHAVIOR, type VLSlotSignature } from '$lib';
33
import VirtualList from 'svelte-virtuallists/new/VirtualListNew.svelte';
44
5-
const myModel = new Array(10000).fill(1).map((v, i) => {
6-
return { text: 'Item ' + i + ' item ' + i, lineHeight: 20 + (i % 30) + 'px' };
7-
});
8-
9-
let virtualList;
5+
const myModel = $state(new Array(10000));
106
117
// on the UI
128
let theScrollToIndex: number | undefined = $state();
@@ -46,15 +42,32 @@
4642
4743
let szCalculator: ((index: number, item: unknown) => number) | undefined = $state();
4844
49-
function randomize() {
50-
szCalculator = (_index: number, _item: any) => Math.round(Math.random() * (155 - 30) + 30);
45+
let randSizes: Array<number>;
46+
function randomizeSize() {
47+
randSizes = new Array(myModel.length);
48+
for (let i = 0; i < randSizes.length; i++) {
49+
randSizes[i] = Math.round(Math.random() * 65 + 30);
50+
}
51+
52+
szCalculator = (_index: number, _item: any) => randSizes[_index];
5153
}
5254
5355
function sameSize() {
54-
szCalculator = (_index: number, _item: any) => 25;
56+
szCalculator = () => 25;
57+
}
58+
59+
function randomizeContent() {
60+
for (let i = 0; i < myModel.length; i++) {
61+
myModel[i] = { text: Math.floor(Math.random() * myModel.length) }; // Random number between 0 and 9999
62+
}
63+
}
64+
65+
function stripItemsBy10() {
66+
for (let i = 0; i < 10; i++) myModel.pop();
5567
}
5668
57-
randomize();
69+
randomizeContent();
70+
randomizeSize();
5871
</script>
5972

6073
<div class="actions">
@@ -120,18 +133,21 @@
120133
{scrollToBehaviour}
121134
sizingCalculator={szCalculator}
122135
onVisibleRangeUpdate={handleMessage}>
123-
{#snippet vl_slot({ item, index, size })}
136+
{#snippet vl_slot({ index, item, size }: VLSlotSignature)}
124137
<div
125138
style="border: 1px solid rgb(204, 204, 204); line-height: {size}px;"
126139
class:highlighted={index === scrollToIndex}>
140+
#{index}
127141
{item.text}
128142
</div>
129143
{/snippet}
130144
</VirtualList>
131145

132146
<div class="actions">
133-
<button onclick={randomize} class="button">Randomize row heights</button>
147+
<button onclick={randomizeSize} class="button">Randomize row heights</button>
134148
<button onclick={sameSize} class="button">Same row heights</button>
149+
<button onclick={randomizeContent} class="button">Randomize content</button>
150+
<button onclick={stripItemsBy10} class="button">array size -10</button>
135151
</div>
136152

137153
<style>

0 commit comments

Comments
 (0)