From 40e9b44adc7775606309b24c3f48181b2d67dfa5 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sat, 29 Aug 2020 19:19:16 -0700 Subject: [PATCH] fix(VirtualList): fix some TODOs (#1851) * fix(VirtualList): fix some TODOs * fix: fix memory leak * fix: remove dead code --- src/routes/_components/virtualList/VirtualList.html | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/routes/_components/virtualList/VirtualList.html b/src/routes/_components/virtualList/VirtualList.html index 4faa9d36..7d63f729 100644 --- a/src/routes/_components/virtualList/VirtualList.html +++ b/src/routes/_components/virtualList/VirtualList.html @@ -64,6 +64,8 @@ this.store.setForRealm({ items: newItems }) 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.calculateListOffset() if (allVisibleItemsHaveHeight) { @@ -71,18 +73,12 @@ } }) - let observedOnce = false - 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 && distanceFromBottom <= DISTANCE_FROM_BOTTOM_TO_FIRE) { this.fireScrollToBottom() } - }) + }, { init: false }) this.observe('scrollTop', (scrollTop) => { this.fire('scrollTopChanged', scrollTop) @@ -107,7 +103,6 @@ return $scrollHeight - $scrollTop - $offsetHeight }, scrollTop: ({ $scrollTop }) => $scrollTop, - // TODO: bug in svelte store, shouldn't need to do this allVisibleItemsHaveHeight: ({ $allVisibleItemsHaveHeight }) => $allVisibleItemsHaveHeight, visibleItemKeys: ({ $visibleItems }) => ($visibleItems || []).map(_ => _.key) },