use throttle instead of debounce
This commit is contained in:
parent
e6e84e9079
commit
725a47a799
|
@ -17,29 +17,32 @@
|
||||||
<script>
|
<script>
|
||||||
import VirtualListItem from './VirtualListItem'
|
import VirtualListItem from './VirtualListItem'
|
||||||
import { virtualListStore } from '../_utils/virtualListStore'
|
import { virtualListStore } from '../_utils/virtualListStore'
|
||||||
import debounce from 'lodash/debounce'
|
import throttle from 'lodash/throttle'
|
||||||
|
|
||||||
const DEBOUNCE_TIME = 500
|
const THROTTLE_TIME = 500
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
oncreate () {
|
oncreate () {
|
||||||
this.observe('innerHeight', debounce(innerHeight => {
|
this.observe('innerHeight', throttle(innerHeight => {
|
||||||
//console.log('setting innerHeight', innerHeight)
|
//console.log('setting innerHeight', innerHeight)
|
||||||
this.store.set({
|
this.store.set({
|
||||||
innerHeight: innerHeight
|
innerHeight: innerHeight
|
||||||
})
|
})
|
||||||
}, DEBOUNCE_TIME))
|
}, THROTTLE_TIME))
|
||||||
this.observe('items', (items) => {
|
this.observe('items', (items) => {
|
||||||
//console.log('setting items')
|
//console.log('setting items')
|
||||||
this.store.set({
|
this.store.set({
|
||||||
'items': items
|
'items': items
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
document.body.querySelector('.container').addEventListener('scroll', debounce((e) => {
|
document.body.querySelector('.container').addEventListener('scroll', throttle((e) => {
|
||||||
this.store.set({
|
this.store.set({
|
||||||
scrollTop: e.target.scrollTop
|
scrollTop: e.target.scrollTop
|
||||||
|
}, {
|
||||||
|
leading: false,
|
||||||
|
trailing: true
|
||||||
})
|
})
|
||||||
}, DEBOUNCE_TIME))
|
}, THROTTLE_TIME))
|
||||||
},
|
},
|
||||||
ondestroy () {
|
ondestroy () {
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue