From 96ad0974342a06eaea46c64f5a2c078edba32bc4 Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Sat, 16 Dec 2023 11:26:33 +0500 Subject: [PATCH] core: add fn to get cache item --- packages/core/src/utils/virtualized-grouping.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/core/src/utils/virtualized-grouping.ts b/packages/core/src/utils/virtualized-grouping.ts index d81f1e6f0..f2176c0de 100644 --- a/packages/core/src/utils/virtualized-grouping.ts +++ b/packages/core/src/utils/virtualized-grouping.ts @@ -61,6 +61,19 @@ export class VirtualizedGrouping { ? "header-item" : "item"; } + cacheItem(index: number) { + const batchIndex = Math.floor(index / this.batchSize); + const batch = this.cache.get(batchIndex); + if (!batch) return; + const { items, groups, data } = batch; + const itemIndexInBatch = index - batchIndex * this.batchSize; + const group = groups?.get(itemIndexInBatch); + return { + item: items[itemIndexInBatch], + group: group && !group.hidden ? group.group : undefined, + data: data?.[itemIndexInBatch] + }; + } item(index: number): Promise<{ item: T; group?: GroupHeader }>; item(