Skip to content

Commit

Permalink
0.2.1: Ensures destroyed views are uncached during item list changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
lVlyke committed Oct 14, 2022
1 parent ff162d9 commit 6508955
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@lithiumjs/ngx-virtual-scroll",
"description": "A fast and lightweight virtual scrolling solution for Angular that supports single column lists, grid lists and view caching.",
"repository": "https://github.com/lVlyke/lithium-ngx-virtual-scroll",
"version": "0.2.0",
"version": "0.2.1",
"main": "index.js",
"author": "Mychal Thompson <[email protected]>",
"license": "MIT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,13 @@ export class DefaultVirtualScrollStrategy<T> implements VirtualScrollStrategy<T>
// Iterate through the cache starting from the point furthest from the first rendered index
for (let i = startIndex; i != endIndex && this.cacheFull(scrollState); i += direction) {
const view = cachedViews[i];

// If the view was destroyed externally, remove it from the cache
if (view.viewRef.destroyed) {
this.destroyView(scrollState, view);
}
// If this view isn't about to be rendered, evict it from the cache and destroy it
if (view.itemIndex < minIndex || view.itemIndex >= minIndex + scrollState.renderedItems.length) {
else if (view.itemIndex < minIndex || view.itemIndex >= minIndex + scrollState.renderedItems.length) {
this.destroyView(scrollState, view);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/virtual-scroll/virtual-scroll.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ export class VirtualScroll<T> implements VirtualScrollState<T> {
private cleanViewCache(): void {
// Destroy all cached views that are no longer valid for current items
for (let [trackByKey, view] of this._cachedViews.entries()) {
if (!this.isViewForAnyItems(view)) {
if (!this.isViewForAnyItems(view) || view.viewRef.destroyed) {
this.scrollStrategy.destroyViewRef(this, view.viewRef);
this._cachedViews.delete(trackByKey);
}
Expand Down

0 comments on commit 6508955

Please sign in to comment.