use throttle instead of debounce

This commit is contained in:
Nolan Lawson 2018-01-16 17:33:47 -08:00
parent e6e84e9079
commit 725a47a799
1 changed files with 9 additions and 6 deletions

View File

@ -17,29 +17,32 @@
<script>
import VirtualListItem from './VirtualListItem'
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 {
oncreate () {
this.observe('innerHeight', debounce(innerHeight => {
this.observe('innerHeight', throttle(innerHeight => {
//console.log('setting innerHeight', innerHeight)
this.store.set({
innerHeight: innerHeight
})
}, DEBOUNCE_TIME))
}, THROTTLE_TIME))
this.observe('items', (items) => {
//console.log('setting items')
this.store.set({
'items': items
})
})
document.body.querySelector('.container').addEventListener('scroll', debounce((e) => {
document.body.querySelector('.container').addEventListener('scroll', throttle((e) => {
this.store.set({
scrollTop: e.target.scrollTop
}, {
leading: false,
trailing: true
})
}, DEBOUNCE_TIME))
}, THROTTLE_TIME))
},
ondestroy () {
},