Skip to content

Commit b00a84a

Browse files
author
Guillaume Chau
committed
feat: items limit
1 parent 6cf478a commit b00a84a

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

src/components/RecycleList.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
<script>
3636
import Scroller from '../mixins/scroller'
37+
import config from '../config'
3738
3839
let uid = 0
3940
@@ -249,6 +250,10 @@ export default {
249250
}
250251
}
251252
253+
if (endIndex - startIndex > config.itemsLimit) {
254+
this.itemsLimitError()
255+
}
256+
252257
this.totalHeight = totalHeight
253258
254259
let view

src/components/VirtualScroller.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959

6060
<script>
6161
import Scroller from '../mixins/scroller'
62+
import config from '../config'
6263
6364
export default {
6465
name: 'virtual-scroller',
@@ -235,6 +236,10 @@ export default {
235236
containerHeight = l * itemHeight
236237
}
237238
239+
if (endIndex - startIndex > config.itemsLimit) {
240+
this.itemsLimitError()
241+
}
242+
238243
if (
239244
force ||
240245
this.$_startIndex !== startIndex ||

src/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
itemsLimit: 1000,
3+
}

src/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import config from './config'
2+
13
import VirtualScroller from './components/VirtualScroller.vue'
24
import RecycleList from './components/RecycleList.vue'
35

@@ -20,6 +22,12 @@ const plugin = {
2022
componentsPrefix: '',
2123
}, options)
2224

25+
for (const key in finalOptions) {
26+
if (typeof finalOptions[key] !== 'undefined') {
27+
config[key] = finalOptions[key]
28+
}
29+
}
30+
2331
if (finalOptions.installComponents) {
2432
registerComponents(Vue, finalOptions.componentsPrefix)
2533
}

src/mixins/scroller.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,13 @@ export default {
149149
scrollToPosition (position) {
150150
this.$el.scrollTop = position
151151
},
152+
153+
itemsLimitError () {
154+
setTimeout(() => {
155+
console.log(`It seems the scroller element isn't scrolling, so it tries to render all the items at once.`, 'Scroller:', this.$el)
156+
console.log(`Make sure the scroller has a fixed height and 'overflow-y' set to 'auto' so it can scroll correctly and only render the items visible in the scroll viewport.`)
157+
})
158+
throw new Error('Rendered items limit reached')
159+
},
152160
},
153161
}

0 commit comments

Comments
 (0)