Skip to content

Commit

Permalink
Add to allow fixing vaadin/flow-components#6648
Browse files Browse the repository at this point in the history
  • Loading branch information
pepijnve committed Sep 17, 2024
1 parent 9c84e5c commit 9e52cad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ export class Cache<TItem> {
*/
setPage(page: number, items: unknown[]): void;

/**
* Clears the entries for the given page from the `items` array.
*/
clearPage(page: number): void;

/**
* Retrieves the sub-cache associated with the item at the given index
* in the `items` array.
Expand Down
14 changes: 14 additions & 0 deletions packages/component-base/src/data-provider-controller/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,20 @@ export class Cache {
});
}

/**
* Clears the entries for the given page from the `items` array.
*
* @param {number} page
*/
clearPage(page) {
const startIndex = page * this.pageSize;
let endIndex = startIndex + this.pageSize;
if (this.size !== undefined && endIndex >= this.size) {
endIndex = this.size;
}
this.items.fill(undefined, startIndex, endIndex);
}

/**
* Retrieves the sub-cache associated with the item at the given index
* in the `items` array.
Expand Down

0 comments on commit 9e52cad

Please sign in to comment.