2018-01-17 08:13:36 +00:00
|
|
|
<!-- TODO: setting height is hacky, just make this element the scroller -->
|
2018-01-17 08:06:24 +00:00
|
|
|
<div class="virtual-list" style="height: {{$height}}px;">
|
2018-01-16 01:25:32 +00:00
|
|
|
{{#each $visibleItems as item @key}}
|
|
|
|
<VirtualListItem :component
|
|
|
|
offset="{{item.offset}}"
|
|
|
|
props="{{item.props}}"
|
|
|
|
key="{{item.key}}"
|
2018-01-18 07:00:33 +00:00
|
|
|
index="{{item.index}}"
|
2018-01-16 01:25:32 +00:00
|
|
|
/>
|
2018-01-15 18:54:02 +00:00
|
|
|
{{/each}}
|
|
|
|
</div>
|
|
|
|
<style>
|
|
|
|
.virtual-list {
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<script>
|
|
|
|
import VirtualListItem from './VirtualListItem'
|
2018-01-15 20:23:28 +00:00
|
|
|
import { virtualListStore } from '../_utils/virtualListStore'
|
2018-01-17 08:59:15 +00:00
|
|
|
import { mark, stop } from '../_utils/marks'
|
2018-01-15 18:54:02 +00:00
|
|
|
|
2018-01-17 05:43:31 +00:00
|
|
|
const DISTANCE_FROM_BOTTOM_TO_FIRE = 400
|
2018-01-16 01:25:32 +00:00
|
|
|
|
2018-01-15 18:54:02 +00:00
|
|
|
export default {
|
2018-01-16 01:25:32 +00:00
|
|
|
oncreate () {
|
2018-01-15 20:23:28 +00:00
|
|
|
this.observe('items', (items) => {
|
2018-01-17 08:59:15 +00:00
|
|
|
mark('set items')
|
2018-01-16 00:12:07 +00:00
|
|
|
this.store.set({
|
2018-01-17 07:16:15 +00:00
|
|
|
items: items
|
2018-01-16 00:12:07 +00:00
|
|
|
})
|
2018-01-17 08:59:15 +00:00
|
|
|
stop('set items')
|
2018-01-15 18:54:02 +00:00
|
|
|
})
|
2018-01-17 07:16:15 +00:00
|
|
|
|
2018-01-17 08:06:24 +00:00
|
|
|
let observedOnce = false
|
|
|
|
|
2018-01-17 07:16:15 +00:00
|
|
|
this.observe('distanceFromBottom', (distanceFromBottom) => {
|
2018-01-17 08:06:24 +00:00
|
|
|
if (!observedOnce) {
|
|
|
|
observedOnce = true // TODO: the first time is always 0... need better way to handle this
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (distanceFromBottom >= 0 &&
|
2018-01-17 05:43:31 +00:00
|
|
|
distanceFromBottom <= DISTANCE_FROM_BOTTOM_TO_FIRE) {
|
|
|
|
this.fire('scrollToBottom')
|
|
|
|
}
|
|
|
|
})
|
2018-01-16 02:29:28 +00:00
|
|
|
},
|
2018-01-15 18:54:02 +00:00
|
|
|
data: () => ({
|
2018-01-15 20:23:28 +00:00
|
|
|
component: null
|
2018-01-15 18:54:02 +00:00
|
|
|
}),
|
2018-01-15 20:23:28 +00:00
|
|
|
store: () => virtualListStore,
|
2018-01-15 18:54:02 +00:00
|
|
|
components: {
|
|
|
|
VirtualListItem
|
2018-01-17 07:16:15 +00:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
distanceFromBottom: ($scrollHeight, $scrollTop, $offsetHeight) => {
|
|
|
|
return $scrollHeight - $scrollTop - $offsetHeight
|
|
|
|
}
|
2018-01-15 18:54:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|