simplify virtual list even more

This commit is contained in:
Nolan Lawson 2018-01-23 18:19:03 -08:00
parent 5f12322ac8
commit b15ad4b2f7
3 changed files with 7 additions and 12 deletions

View File

@ -2,7 +2,7 @@
<div class="timeline" role="feed" aria-label="{{label}}" on:initialized> <div class="timeline" role="feed" aria-label="{{label}}" on:initialized>
<VirtualList component="{{StatusListItem}}" <VirtualList component="{{StatusListItem}}"
:makeProps :makeProps
:items items="{{statusIds}}"
on:scrollToBottom="onScrollToBottom()" on:scrollToBottom="onScrollToBottom()"
shown="{{initialized}}" shown="{{initialized}}"
footerComponent="{{LoadingFooter}}" footerComponent="{{LoadingFooter}}"
@ -49,11 +49,6 @@
}), }),
computed: { computed: {
makeProps: ($currentInstance) => (statusId) => database.getStatus($currentInstance, statusId), makeProps: ($currentInstance) => (statusId) => database.getStatus($currentInstance, statusId),
items: (statusIds) => {
return statusIds.map(statusId => ({
key: statusId
}))
},
lastStatusId: (statusIds) => statusIds.length && statusIds[statusIds.length - 1], lastStatusId: (statusIds) => statusIds.length && statusIds[statusIds.length - 1],
label: (timeline, $currentInstance) => { label: (timeline, $currentInstance) => {
if (timelines[timeline]) { if (timelines[timeline]) {

View File

@ -1,11 +1,11 @@
<!-- TODO: setting height is hacky, just make this element the scroller --> <!-- TODO: setting height is hacky, just make this element the scroller -->
<div class="virtual-list {{shown ? '' : 'hidden'}}" style="height: {{$height}}px;"> <div class="virtual-list {{shown ? '' : 'hidden'}}" style="height: {{$height}}px;">
{{#each $visibleItems as item @key}} {{#each $visibleItems as visibleItem @key}}
<VirtualListLazyItem :component <VirtualListLazyItem :component
offset="{{item.offset}}" offset="{{visibleItem.offset}}"
makeProps="{{makeProps}}" makeProps="{{makeProps}}"
key="{{item.key}}" key="{{visibleItem.key}}"
index="{{item.index}}" index="{{visibleItem.index}}"
/> />
{{/each}} {{/each}}
{{#if $showFooter}} {{#if $showFooter}}

View File

@ -56,7 +56,7 @@ virtualListStore.compute('visibleItems',
let len = items.length let len = items.length
let i = -1 let i = -1
while (++i < len) { while (++i < len) {
let { key } = items[i] let key = items[i]
let height = itemHeights[key] || 0 let height = itemHeights[key] || 0
let currentOffset = totalOffset let currentOffset = totalOffset
totalOffset += height totalOffset += height
@ -87,7 +87,7 @@ virtualListStore.compute('heightWithoutFooter',
let i = -1 let i = -1
let len = items.length let len = items.length
while (++i < len) { while (++i < len) {
sum += itemHeights[items[i].key] || 0 sum += itemHeights[items[i]] || 0
} }
return sum return sum
}) })