improve virtual list update perf

This commit is contained in:
Nolan Lawson 2018-01-16 18:08:37 -08:00
parent 8d91c3a08d
commit 94cab7aaf7
1 changed files with 19 additions and 4 deletions

View File

@ -13,13 +13,28 @@
<script>
import { virtualListStore } from '../_utils/virtualListStore'
let updateItemHeights = {}
let promise = Promise.resolve()
export default {
oncreate() {
let itemHeights = this.store.get('itemHeights')
let key = this.get('key')
itemHeights[key] = this.refs.node.offsetHeight
this.store.set({
itemHeights: itemHeights
updateItemHeights[key] = this.refs.node.offsetHeight
promise.then(() => {
// update all item heights in one microtask batch for better perf
let updatedKeys = Object.keys(updateItemHeights)
if (!updatedKeys.length) {
return
}
// batch all updates to itemHeights for better perf
let itemHeights = this.store.get('itemHeights')
for (key of updatedKeys) {
itemHeights[key] = updateItemHeights[key]
}
this.store.set({
itemHeights: itemHeights
})
updateItemHeights = {}
})
},
store: () => virtualListStore