improve virtual list update perf
This commit is contained in:
parent
8d91c3a08d
commit
94cab7aaf7
|
@ -13,14 +13,29 @@
|
|||
<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
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue