kinda really sorta working
This commit is contained in:
parent
1528d51290
commit
b09e8c85ab
|
@ -190,13 +190,10 @@
|
||||||
components: {
|
components: {
|
||||||
Avatar
|
Avatar
|
||||||
},
|
},
|
||||||
data: () => ({
|
|
||||||
status: null,
|
|
||||||
}),
|
|
||||||
computed: {
|
computed: {
|
||||||
relativeDate: (status) => {
|
createdAtDate: (status) => status.created_at,
|
||||||
let date = new Date(status.created_at)
|
relativeDate: (createdAtDate) => {
|
||||||
return relativeFormat.format(date)
|
return relativeFormat.format(new Date(createdAtDate))
|
||||||
},
|
},
|
||||||
original: (status) => status.reblog ? status.reblog.account : status.account
|
original: (status) => status.reblog ? status.reblog.account : status.account
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
<:Window bind:scrollY='scrollY' bind:innerHeight='innerHeight' />
|
<:Window bind:scrollY='scrollY' bind:innerHeight='innerHeight'/>
|
||||||
<div class="virtual-list" ref:node style="height: {{$height}}px;">
|
<div class="virtual-list" ref:node style="height: {{$height}}px;">
|
||||||
<!-- <div class="virtual-list-viewport" ref:viewport></div> -->
|
<!-- <div class="virtual-list-viewport" ref:viewport></div> -->
|
||||||
{{#each $visibleItems as item, index @key}}
|
{{#each $visibleItems as item @key}}
|
||||||
<VirtualListItem :component
|
<VirtualListItem :component
|
||||||
offset="{{item.offset}}"
|
offset="{{item.offset}}"
|
||||||
props="{{item.props}}"
|
props="{{item.props}}"
|
||||||
key="{{item.key}}"
|
key="{{item.key}}"
|
||||||
index="{{item.index}}"
|
/>
|
||||||
/>
|
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
<style>
|
<style>
|
||||||
|
@ -20,14 +19,16 @@
|
||||||
import { virtualListStore } from '../_utils/virtualListStore'
|
import { virtualListStore } from '../_utils/virtualListStore'
|
||||||
import debounce from 'lodash/debounce'
|
import debounce from 'lodash/debounce'
|
||||||
|
|
||||||
|
const DEBOUNCE_TIME = 200
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
oncreate() {
|
oncreate () {
|
||||||
this.observe('innerHeight', innerHeight => {
|
this.observe('innerHeight', debounce(innerHeight => {
|
||||||
console.log('setting innerHeight', innerHeight)
|
console.log('setting innerHeight', innerHeight)
|
||||||
this.store.set({
|
this.store.set({
|
||||||
innerHeight: innerHeight
|
innerHeight: innerHeight
|
||||||
})
|
})
|
||||||
})
|
}, DEBOUNCE_TIME))
|
||||||
this.observe('items', (items) => {
|
this.observe('items', (items) => {
|
||||||
console.log('setting items')
|
console.log('setting items')
|
||||||
this.store.set({
|
this.store.set({
|
||||||
|
@ -39,7 +40,7 @@
|
||||||
this.store.set({
|
this.store.set({
|
||||||
scrollTop: scrollY
|
scrollTop: scrollY
|
||||||
})
|
})
|
||||||
}, 2000))
|
}, DEBOUNCE_TIME))
|
||||||
},
|
},
|
||||||
data: () => ({
|
data: () => ({
|
||||||
component: null
|
component: null
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
<div class="virtual-list-item"
|
<div class="virtual-list-item"
|
||||||
ref:node
|
ref:node
|
||||||
style="transform: translate3d(0, {{offset}}px, 0);"
|
style="transform: translate3d(0, {{offset}}px, 0);"
|
||||||
data-virtual-key="{{key}}"
|
|
||||||
data-virtual-index="{{index}}"
|
|
||||||
>
|
>
|
||||||
<:Component {component} virtualProps="{{props}}" />
|
<:Component {component} virtualProps="{{props}}" />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -15,35 +15,42 @@ virtualListStore.compute('visibleItems',
|
||||||
['items', 'scrollTop', 'height', 'itemHeights', 'innerHeight'],
|
['items', 'scrollTop', 'height', 'itemHeights', 'innerHeight'],
|
||||||
(items, scrollTop, height, itemHeights, innerHeight) => {
|
(items, scrollTop, height, itemHeights, innerHeight) => {
|
||||||
let visibleItems = []
|
let visibleItems = []
|
||||||
let currentOffset = 0
|
let totalOffset = 0
|
||||||
items.forEach((item, index) => {
|
let len = items.length
|
||||||
let { props, key } = item
|
let i = -1
|
||||||
|
while (++i < len) {
|
||||||
|
let { props, key } = items[i]
|
||||||
let height = itemHeights[key] || 0
|
let height = itemHeights[key] || 0
|
||||||
console.log(key, 'scrollTop', scrollTop, 'currentOffset', currentOffset, 'innerHeight', innerHeight)
|
let currentOffset = totalOffset
|
||||||
if (
|
totalOffset += height
|
||||||
((currentOffset < scrollTop) && (scrollTop - RENDER_BUFFER < currentOffset)) ||
|
//console.log(key, 'scrollTop', scrollTop, 'currentOffset', currentOffset, 'innerHeight', innerHeight)
|
||||||
((currentOffset >= scrollTop) && (currentOffset < (scrollTop + innerHeight + RENDER_BUFFER)))
|
let isBelowViewport = (currentOffset < scrollTop)
|
||||||
) {
|
if (isBelowViewport) {
|
||||||
console.log(' rendering', key)
|
if (scrollTop - RENDER_BUFFER > currentOffset) {
|
||||||
visibleItems.push({
|
continue // below the area we want to render
|
||||||
offset: currentOffset,
|
}
|
||||||
props: props,
|
|
||||||
key: key,
|
|
||||||
index: index
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
console.log('not rendering', key)
|
if (currentOffset > (scrollTop + innerHeight + RENDER_BUFFER)) {
|
||||||
|
break // above the area we want to render
|
||||||
|
}
|
||||||
}
|
}
|
||||||
currentOffset += height
|
visibleItems.push({
|
||||||
})
|
offset: currentOffset,
|
||||||
|
props: props,
|
||||||
|
key: key,
|
||||||
|
index: i
|
||||||
|
})
|
||||||
|
}
|
||||||
return visibleItems
|
return visibleItems
|
||||||
})
|
})
|
||||||
|
|
||||||
virtualListStore.compute('height', ['items', 'itemHeights'], (items, itemHeights) => {
|
virtualListStore.compute('height', ['items', 'itemHeights'], (items, itemHeights) => {
|
||||||
let sum = 0
|
let sum = 0
|
||||||
items.forEach(item => {
|
let i = -1
|
||||||
sum += itemHeights[item.key] || 0
|
let len = items.length
|
||||||
})
|
while (++i < len) {
|
||||||
|
sum += itemHeights[items[i].key] || 0
|
||||||
|
}
|
||||||
return sum
|
return sum
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue