From ffceed4ad9d46cb0f59e0fb4a6774c4d314f1f34 Mon Sep 17 00:00:00 2001 From: Petyo Ivanov Date: Wed, 29 Jun 2022 20:29:01 +0300 Subject: [PATCH] fix: fix excessive rerendering of grid Fixes #698 --- src/gridSystem.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/gridSystem.ts b/src/gridSystem.ts index c071d1851..5ede9bbaf 100644 --- a/src/gridSystem.ts +++ b/src/gridSystem.ts @@ -62,6 +62,10 @@ const { round, ceil, floor, min, max } = Math function buildItems(startIndex: number, endIndex: number) { return Array.from({ length: endIndex - startIndex + 1 }).map((_, i) => ({ index: i + startIndex } as GridItem)) } + +function gapComparator(prev: Gap, next: Gap) { + return prev && prev.column === next.column && prev.row === next.row +} export const gridSystem = u.system( ([ { overscan, visibleRange, listBoundary }, @@ -107,7 +111,7 @@ export const gridSystem = u.system( u.combineLatest( u.duc(totalCount), visibleRange, - u.duc(gap), + u.duc(gap, gapComparator), u.duc(itemDimensions, (prev, next) => prev && prev.width === next.width && prev.height === next.height) ), u.withLatestFrom(viewportDimensions),