42 lines
		
	
	
		
			No EOL
		
	
	
		
			1.1 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			No EOL
		
	
	
		
			1.1 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<div class="virtual-list-item"
 | 
						|
     ref:node
 | 
						|
     style="transform: translate3d(0, {{offset}}px, 0);"
 | 
						|
>
 | 
						|
  <:Component {component} virtualProps="{{props}}" />
 | 
						|
</div>
 | 
						|
<style>
 | 
						|
  .virtual-list-item {
 | 
						|
    position: absolute;
 | 
						|
    top: 0;
 | 
						|
  }
 | 
						|
</style>
 | 
						|
<script>
 | 
						|
  import { virtualListStore } from '../_utils/virtualListStore'
 | 
						|
 | 
						|
  let updateItemHeights = {}
 | 
						|
  let promise = Promise.resolve()
 | 
						|
 | 
						|
  export default {
 | 
						|
    oncreate() {
 | 
						|
      let key = this.get('key')
 | 
						|
      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
 | 
						|
  }
 | 
						|
</script> |