Skip to content

Commit d5b72ba

Browse files
committed
-> v2.2.1
1 parent f8a2575 commit d5b72ba

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# svelte-virtual-list changelog
22

3+
## 2.2.1
4+
5+
* Rename `viewportHeight` to `_viewportHeight`
6+
* Initialise `_viewportHeight` to avoid missing data warning
7+
38
## 2.2.0
49

510
* Update when viewport changes size ([#3](https://github.com/sveltejs/svelte-virtual-list/issues/3))

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sveltejs/svelte-virtual-list",
3-
"version": "2.2.0",
3+
"version": "2.2.1",
44
"description": "A <VirtualList> component for Svelte apps",
55
"svelte": "src/VirtualList.html",
66
"module": "index.mjs",

src/VirtualList.html

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div ref:viewport on:scroll='refresh()' style='height: {height};' bind:offsetHeight="viewportHeight">
1+
<div ref:viewport on:scroll='refresh()' style='height: {height};' bind:offsetHeight="_viewportHeight">
22
<div ref:container style='padding-top: {_top}px; padding-bottom: {_bottom}px;'>
33
{#each visible as item (item.index)}
44
<div class='row'>
@@ -23,7 +23,16 @@
2323
<script>
2424
export default {
2525
data() {
26-
return { start: 0, end: 0, height: '100%', itemHeight: 0, _top: 0, _bottom: 0, _props: {} };
26+
return {
27+
start: 0,
28+
end: 0,
29+
height: '100%',
30+
itemHeight: 0,
31+
_viewportHeight: 0,
32+
_top: 0,
33+
_bottom: 0,
34+
_props: {}
35+
};
2736
},
2837

2938
computed: {
@@ -55,7 +64,7 @@
5564
}
5665

5766
this.on('state', ({ changed, previous, current }) => {
58-
if (changed.items || changed.height || changed.itemHeight || changed.viewportHeight) {
67+
if (changed.items || changed.height || changed.itemHeight || changed._viewportHeight) {
5968
if (current.itemHeight && (changed.itemHeight || current.items.length > this.heightMap.length)) {
6069
this.heightMap = current.items.map(() => current.itemHeight);
6170
}
@@ -87,19 +96,19 @@
8796

8897
methods: {
8998
initialise() {
90-
const { items, itemHeight, viewportHeight } = this.get();
99+
const { items, itemHeight, _viewportHeight } = this.get();
91100

92101
if (itemHeight) {
93102
this.heightMap = items.map(item => itemHeight);
94103
this.set({
95-
end: Math.min(items.length, Math.ceil(viewportHeight / itemHeight)),
104+
end: Math.min(items.length, Math.ceil(_viewportHeight / itemHeight)),
96105
_bottom: items.length * itemHeight
97106
});
98107
} else {
99108
let height = 0;
100109
let i = 0;
101110

102-
while (height < viewportHeight && i < items.length) {
111+
while (height < _viewportHeight && i < items.length) {
103112
this.set({ end: i + 1 });
104113

105114
const rowHeight = this.heightMap[i] = this.rows[i].offsetHeight;
@@ -120,7 +129,7 @@
120129
},
121130

122131
refresh() {
123-
const { items, start, end, itemHeight, viewportHeight } = this.get();
132+
const { items, start, end, itemHeight, _viewportHeight } = this.get();
124133
const { scrollTop } = this.refs.viewport;
125134

126135
let paddingTop = 0;
@@ -145,7 +154,7 @@
145154
const newStart = i++;
146155

147156
for (; i < items.length; i += 1) {
148-
if (offset >= scrollTop + viewportHeight) break;
157+
if (offset >= scrollTop + _viewportHeight) break;
149158
offset += this.heightMap[i];
150159
}
151160

0 commit comments

Comments
 (0)