pinafore/routes/_components/VirtualList.html
2018-01-15 16:35:08 -08:00

52 lines
1.4 KiB
HTML

<:Window bind:scrollY='scrollY' bind:innerHeight='innerHeight' />
<div class="virtual-list" ref:node style="height: {{$height}}px;">
<!-- <div class="virtual-list-viewport" ref:viewport></div> -->
{{#each $visibleItems as item, index @key}}
<VirtualListItem :component
offset="{{item.offset}}"
props="{{item.props}}"
key="{{item.key}}"
index="{{item.index}}"
/>
{{/each}}
</div>
<style>
.virtual-list {
position: relative;
}
</style>
<script>
import VirtualListItem from './VirtualListItem'
import { virtualListStore } from '../_utils/virtualListStore'
import debounce from 'lodash/debounce'
export default {
oncreate() {
this.observe('innerHeight', innerHeight => {
console.log('setting innerHeight', innerHeight)
this.store.set({
innerHeight: innerHeight
})
})
this.observe('items', (items) => {
console.log('setting items')
this.store.set({
'items': items
})
})
this.observe('scrollY', debounce((scrollY) => {
console.log('setting scrollY', scrollY)
this.store.set({
scrollTop: scrollY
})
}, 2000))
},
data: () => ({
component: null
}),
store: () => virtualListStore,
components: {
VirtualListItem
}
}
</script>