1
0
mirror of https://github.com/nolanlawson/pinafore synced 2024-12-12 02:07:26 +01:00

improve virtual list update perf

This commit is contained in:
Nolan Lawson 2018-01-16 18:08:37 -08:00
parent 8d91c3a08d
commit 94cab7aaf7

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