more refactoring

This commit is contained in:
Nolan Lawson 2018-02-12 22:32:56 -08:00
parent acc1ce396d
commit 2db4236761
4 changed files with 18 additions and 30 deletions

View file

@ -43,7 +43,7 @@
this.store.setForRealm({intersectionStates: intersectionStates}) this.store.setForRealm({intersectionStates: intersectionStates})
this.set({intersectionObserver: new IntersectionObserver(this.onIntersection.bind(this), { this.set({intersectionObserver: new IntersectionObserver(this.onIntersection.bind(this), {
root: document.querySelector('.container'), root: document.querySelector(this.get('containerQuery')),
rootMargin: '300% 0px' rootMargin: '300% 0px'
})}) })})
this.observe('allItemsHaveHeight', allItemsHaveHeight => { this.observe('allItemsHaveHeight', allItemsHaveHeight => {
@ -80,7 +80,7 @@
} }
this.set({scrolledToPosition: true}) this.set({scrolledToPosition: true})
console.log('scrollToPosition', rect.top) console.log('scrollToPosition', rect.top)
let container = document.querySelector('.container') let container = document.querySelector(this.get('containerQuery'))
if (!container) { if (!container) {
return return
} }

View file

@ -7,46 +7,33 @@
{{#if !$initialized}} {{#if !$initialized}}
<LoadingPage /> <LoadingPage />
{{/if}} {{/if}}
{{#if timelineType === 'notifications'}} {{#if virtual}}
<VirtualList component="{{NotificationVirtualListItem}}" <VirtualList component="{{VirtualListComponent}}"
:makeProps
items="{{$timelineItemIds}}"
on:scrollToBottom="onScrollToBottom()"
on:scrollToTop="onScrollToTop()"
shown="{{$initialized}}"
footerComponent="{{LoadingFooter}}"
showFooter="{{$initialized && $runningUpdate}}"
showHeader="{{$showHeader}}"
headerComponent="{{MoreHeaderVirtualWrapper}}"
:headerProps
realm="{{$currentInstance + '/' + timeline}}" realm="{{$currentInstance + '/' + timeline}}"
on:initializedVisibleItems="initialize()" containerQuery=".container"
/>
{{elseif virtual}}
<VirtualList component="{{StatusVirtualListItem}}"
:makeProps :makeProps
items="{{$timelineItemIds}}" items="{{$timelineItemIds}}"
on:scrollToBottom="onScrollToBottom()"
on:scrollToTop="onScrollToTop()"
shown="{{$initialized}}" shown="{{$initialized}}"
showFooter="{{$initialized && $runningUpdate}}"
footerComponent="{{LoadingFooter}}" footerComponent="{{LoadingFooter}}"
showHeader="{{$showHeader}}" showHeader="{{$showHeader}}"
headerComponent="{{MoreHeaderVirtualWrapper}}" headerComponent="{{MoreHeaderVirtualWrapper}}"
:headerProps :headerProps
showFooter="{{$initialized && $runningUpdate}}" on:scrollToBottom="onScrollToBottom()"
realm="{{$currentInstance + '/' + timeline}}" on:scrollToTop="onScrollToTop()"
on:initializedVisibleItems="initialize()" on:initializedVisibleItems="initialize()"
/> />
{{else}} {{else}}
<!-- if this is a status thread, it's easier to just render the <!-- if this is a status thread, it's easier to just render the
whole thing rather than use a virtual list --> whole thing rather than use a virtual list -->
<PseudoVirtualList component="{{StatusVirtualListItem}}" <PseudoVirtualList component="{{VirtualListComponent}}"
realm="{{$currentInstance + '/' + timeline}}"
containerQuery=".container"
:makeProps :makeProps
items="{{$timelineItemIds}}" items="{{$timelineItemIds}}"
shown="{{$initialized}}" shown="{{$initialized}}"
on:initializedVisibleItems="initialize()"
scrollToItem="{{scrollToItem}}" scrollToItem="{{scrollToItem}}"
realm="{{$currentInstance + '/' + timeline}}" on:initializedVisibleItems="initialize()"
/> />
{{/if}} {{/if}}
</div> </div>
@ -90,13 +77,14 @@
this.teardownFocus() this.teardownFocus()
}, },
data: () => ({ data: () => ({
StatusVirtualListItem,
NotificationVirtualListItem,
LoadingFooter, LoadingFooter,
MoreHeaderVirtualWrapper, MoreHeaderVirtualWrapper,
Status Status
}), }),
computed: { computed: {
VirtualListComponent: (timelineType) => {
return timelineType === 'notifications' ? NotificationVirtualListItem : StatusVirtualListItem
},
makeProps: ($currentInstance, timelineType, timelineValue) => async (itemId) => { makeProps: ($currentInstance, timelineType, timelineValue) => async (itemId) => {
let res = { timelineType, timelineValue } let res = { timelineType, timelineValue }
if (timelineType === 'notifications') { if (timelineType === 'notifications') {

View file

@ -1,4 +1,4 @@
<VirtualListContainer :realm > <VirtualListContainer :realm :containerQuery >
<div class="virtual-list {{shown ? '' : 'hidden'}}" style="height: {{$height}}px;"> <div class="virtual-list {{shown ? '' : 'hidden'}}" style="height: {{$height}}px;">
<VirtualListHeader component="{{headerComponent}}" virtualProps="{{headerProps}}" shown="{{$showHeader}}"/> <VirtualListHeader component="{{headerComponent}}" virtualProps="{{headerProps}}" shown="{{$showHeader}}"/>
{{#if $visibleItems}} {{#if $visibleItems}}

View file

@ -10,7 +10,7 @@
export default { export default {
oncreate() { oncreate() {
mark('onCreate VirtualListContainer') mark('onCreate VirtualListContainer')
let node = document.querySelector('.container') let node = document.querySelector(this.get('containerQuery'))
this.setupScroll(node) this.setupScroll(node)
this.setupFullscreen() this.setupFullscreen()
this.store.setCurrentRealm(this.get('realm')) this.store.setCurrentRealm(this.get('realm'))
@ -58,7 +58,7 @@
node.addEventListener('scroll', this.scrollListener) node.addEventListener('scroll', this.scrollListener)
}, },
teardownScroll() { teardownScroll() {
let node = document.querySelector('.container') let node = document.querySelector(this.get('containerQuery'))
if (node) { if (node) {
node.removeEventListener('scroll', this.scrollListener) node.removeEventListener('scroll', this.scrollListener)
} }