2018-01-16 03:29:28 +01:00
|
|
|
<:Window bind:innerHeight='innerHeight'/>
|
|
|
|
<div class="virtual-list" style="height: {{$height}}px;">
|
2018-01-15 21:23:28 +01:00
|
|
|
<!-- <div class="virtual-list-viewport" ref:viewport></div> -->
|
2018-01-16 02:25:32 +01:00
|
|
|
{{#each $visibleItems as item @key}}
|
|
|
|
<VirtualListItem :component
|
|
|
|
offset="{{item.offset}}"
|
|
|
|
props="{{item.props}}"
|
|
|
|
key="{{item.key}}"
|
|
|
|
/>
|
2018-01-15 19:54:02 +01:00
|
|
|
{{/each}}
|
|
|
|
</div>
|
|
|
|
<style>
|
|
|
|
.virtual-list {
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<script>
|
|
|
|
import VirtualListItem from './VirtualListItem'
|
2018-01-15 21:23:28 +01:00
|
|
|
import { virtualListStore } from '../_utils/virtualListStore'
|
2018-01-16 01:35:08 +01:00
|
|
|
import debounce from 'lodash/debounce'
|
2018-01-15 19:54:02 +01:00
|
|
|
|
2018-01-16 03:29:28 +01:00
|
|
|
const DEBOUNCE_TIME = 500
|
2018-01-16 02:25:32 +01:00
|
|
|
|
2018-01-15 19:54:02 +01:00
|
|
|
export default {
|
2018-01-16 02:25:32 +01:00
|
|
|
oncreate () {
|
|
|
|
this.observe('innerHeight', debounce(innerHeight => {
|
2018-01-16 16:09:16 +01:00
|
|
|
//console.log('setting innerHeight', innerHeight)
|
2018-01-16 01:12:07 +01:00
|
|
|
this.store.set({
|
|
|
|
innerHeight: innerHeight
|
|
|
|
})
|
2018-01-16 02:25:32 +01:00
|
|
|
}, DEBOUNCE_TIME))
|
2018-01-15 21:23:28 +01:00
|
|
|
this.observe('items', (items) => {
|
2018-01-16 16:09:16 +01:00
|
|
|
//console.log('setting items')
|
2018-01-16 01:12:07 +01:00
|
|
|
this.store.set({
|
|
|
|
'items': items
|
|
|
|
})
|
2018-01-15 19:54:02 +01:00
|
|
|
})
|
2018-01-16 03:29:28 +01:00
|
|
|
document.body.querySelector('.container').addEventListener('scroll', debounce((e) => {
|
2018-01-16 01:12:07 +01:00
|
|
|
this.store.set({
|
2018-01-16 03:29:28 +01:00
|
|
|
scrollTop: e.target.scrollTop
|
2018-01-16 01:12:07 +01:00
|
|
|
})
|
2018-01-16 03:29:28 +01:00
|
|
|
}, DEBOUNCE_TIME, {
|
|
|
|
leading: true,
|
|
|
|
trailing: true
|
|
|
|
}))
|
|
|
|
},
|
|
|
|
ondestroy () {
|
2018-01-15 19:54:02 +01:00
|
|
|
},
|
|
|
|
data: () => ({
|
2018-01-15 21:23:28 +01:00
|
|
|
component: null
|
2018-01-15 19:54:02 +01:00
|
|
|
}),
|
2018-01-15 21:23:28 +01:00
|
|
|
store: () => virtualListStore,
|
2018-01-15 19:54:02 +01:00
|
|
|
components: {
|
|
|
|
VirtualListItem
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|