fix(VirtualList): fix some TODOs (#1851)
* fix(VirtualList): fix some TODOs * fix: fix memory leak * fix: remove dead code
This commit is contained in:
parent
4d1a72bb98
commit
40e9b44adc
|
@ -64,6 +64,8 @@
|
||||||
this.store.setForRealm({ items: newItems })
|
this.store.setForRealm({ items: newItems })
|
||||||
stop('set items')
|
stop('set items')
|
||||||
})
|
})
|
||||||
|
// We observe on the component rather than the store to avoid a leak in store listeners
|
||||||
|
// (Svelte automatically removes component listeners, but not store listeners)
|
||||||
this.observe('allVisibleItemsHaveHeight', allVisibleItemsHaveHeight => {
|
this.observe('allVisibleItemsHaveHeight', allVisibleItemsHaveHeight => {
|
||||||
this.calculateListOffset()
|
this.calculateListOffset()
|
||||||
if (allVisibleItemsHaveHeight) {
|
if (allVisibleItemsHaveHeight) {
|
||||||
|
@ -71,18 +73,12 @@
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
let observedOnce = false
|
|
||||||
|
|
||||||
this.observe('distanceFromBottom', (distanceFromBottom) => {
|
this.observe('distanceFromBottom', (distanceFromBottom) => {
|
||||||
if (!observedOnce) {
|
|
||||||
observedOnce = true // TODO: the first time is always 0... need better way to handle this
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (distanceFromBottom >= 0 &&
|
if (distanceFromBottom >= 0 &&
|
||||||
distanceFromBottom <= DISTANCE_FROM_BOTTOM_TO_FIRE) {
|
distanceFromBottom <= DISTANCE_FROM_BOTTOM_TO_FIRE) {
|
||||||
this.fireScrollToBottom()
|
this.fireScrollToBottom()
|
||||||
}
|
}
|
||||||
})
|
}, { init: false })
|
||||||
|
|
||||||
this.observe('scrollTop', (scrollTop) => {
|
this.observe('scrollTop', (scrollTop) => {
|
||||||
this.fire('scrollTopChanged', scrollTop)
|
this.fire('scrollTopChanged', scrollTop)
|
||||||
|
@ -107,7 +103,6 @@
|
||||||
return $scrollHeight - $scrollTop - $offsetHeight
|
return $scrollHeight - $scrollTop - $offsetHeight
|
||||||
},
|
},
|
||||||
scrollTop: ({ $scrollTop }) => $scrollTop,
|
scrollTop: ({ $scrollTop }) => $scrollTop,
|
||||||
// TODO: bug in svelte store, shouldn't need to do this
|
|
||||||
allVisibleItemsHaveHeight: ({ $allVisibleItemsHaveHeight }) => $allVisibleItemsHaveHeight,
|
allVisibleItemsHaveHeight: ({ $allVisibleItemsHaveHeight }) => $allVisibleItemsHaveHeight,
|
||||||
visibleItemKeys: ({ $visibleItems }) => ($visibleItems || []).map(_ => _.key)
|
visibleItemKeys: ({ $visibleItems }) => ($visibleItems || []).map(_ => _.key)
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue