improve virtual list update perf
This commit is contained in:
parent
8d91c3a08d
commit
94cab7aaf7
|
@ -13,14 +13,29 @@
|
||||||
<script>
|
<script>
|
||||||
import { virtualListStore } from '../_utils/virtualListStore'
|
import { virtualListStore } from '../_utils/virtualListStore'
|
||||||
|
|
||||||
|
let updateItemHeights = {}
|
||||||
|
let promise = Promise.resolve()
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
oncreate() {
|
oncreate() {
|
||||||
let itemHeights = this.store.get('itemHeights')
|
|
||||||
let key = this.get('key')
|
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({
|
this.store.set({
|
||||||
itemHeights: itemHeights
|
itemHeights: itemHeights
|
||||||
})
|
})
|
||||||
|
updateItemHeights = {}
|
||||||
|
})
|
||||||
},
|
},
|
||||||
store: () => virtualListStore
|
store: () => virtualListStore
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue