fix bug in layout calculations

This commit is contained in:
Nolan Lawson 2018-01-27 09:53:14 -08:00
parent 7a510101d0
commit b98a0c6b85

View file

@ -24,20 +24,9 @@
import { virtualListStore } from './virtualListStore' import { virtualListStore } from './virtualListStore'
import { AsyncLayout } from '../../_utils/AsyncLayout' import { AsyncLayout } from '../../_utils/AsyncLayout'
const keyGetter = node => node.getAttribute('virtual-list-key')
const asyncLayout = new AsyncLayout(keyGetter)
export default { export default {
oncreate() { oncreate() {
let key = this.get('key') this.doRecalculateHeight()
asyncLayout.observe(key, this.refs.node, (rect) => {
// update all item heights in one microtask batch for better perf
this.store.batchUpdate('itemHeights', key, rect.height)
})
},
ondestroy() {
let key = this.get('key')
asyncLayout.unobserve(key, this.refs.node)
}, },
store: () => virtualListStore, store: () => virtualListStore,
computed: { computed: {
@ -45,10 +34,10 @@
}, },
methods: { methods: {
doRecalculateHeight() { doRecalculateHeight() {
let tempAsyncLayout = new AsyncLayout(keyGetter) let asyncLayout = new AsyncLayout(node => node.getAttribute('virtual-list-key'))
let key = this.get('key') let key = this.get('key')
tempAsyncLayout.observe(key, this.refs.node, (rect) => { asyncLayout.observe(key, this.refs.node, (rect) => {
tempAsyncLayout.disconnect() asyncLayout.disconnect()
// update all item heights in one microtask batch for better perf // update all item heights in one microtask batch for better perf
this.store.batchUpdate('itemHeights', key, rect.height) this.store.batchUpdate('itemHeights', key, rect.height)
}) })