Skip to content

Commit 7bb21f8

Browse files
committed
Batch updates and reduce array creation
1 parent 48dae30 commit 7bb21f8

12 files changed

Lines changed: 116 additions & 120 deletions

e2e/VList.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ test.describe("smoke", () => {
9999
// check if last is displayed
100100
const last = component.getByText("999", { exact: true });
101101
await expect(last).toBeVisible();
102-
expect(await relativeBottom(component, last)).toEqual(0);
102+
expectInRange(await relativeBottom(component, last), { min: 0, max: 0.5 });
103103
// check if start is not displayed
104104
expect(await page.evaluate(() => (window as any)._displayed)).toBe(false);
105105
});

src/core/resizer.ts

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ export const createResizer = (
5252
const mountedIndexes = new WeakMap<Element, number>();
5353

5454
const resizeObserver = createResizeObserver((entries) => {
55-
const resizes: ItemResize[] = [];
5655
for (const { target, contentRect } of entries) {
5756
// Skip zero-sized rects that may be observed under `display: none` style
5857
if (!(target as HTMLElement).offsetParent) continue;
@@ -62,14 +61,10 @@ export const createResizer = (
6261
} else {
6362
const index = mountedIndexes.get(target);
6463
if (index != NULL) {
65-
resizes.push([index, contentRect[sizeKey]]);
64+
store.$update(ACTION_ITEM_RESIZE, [index, contentRect[sizeKey]]);
6665
}
6766
}
6867
}
69-
70-
if (resizes.length) {
71-
store.$update(ACTION_ITEM_RESIZE, resizes);
72-
}
7368
});
7469

7570
return {
@@ -106,20 +101,15 @@ export const createWindowResizer = (
106101
const mountedIndexes = new WeakMap<Element, number>();
107102

108103
const resizeObserver = createResizeObserver((entries) => {
109-
const resizes: ItemResize[] = [];
110104
for (const { target, contentRect } of entries) {
111105
// Skip zero-sized rects that may be observed under `display: none` style
112106
if (!(target as HTMLElement).offsetParent) continue;
113107

114108
const index = mountedIndexes.get(target);
115109
if (index != NULL) {
116-
resizes.push([index, contentRect[sizeKey]]);
110+
store.$update(ACTION_ITEM_RESIZE, [index, contentRect[sizeKey]]);
117111
}
118112
}
119-
120-
if (resizes.length) {
121-
store.$update(ACTION_ITEM_RESIZE, resizes);
122-
}
123113
});
124114

125115
let cleanupOnWindowResize: (() => void) | undefined;
@@ -220,7 +210,6 @@ export const createGridResizer = (
220210
}
221211

222212
if (resizedRows.size) {
223-
const heightResizes: ItemResize[] = [];
224213
resizedRows.forEach((rowIndex) => {
225214
let maxHeight = 0;
226215
maybeCachedColIndexes.forEach((colIndex) => {
@@ -230,13 +219,11 @@ export const createGridResizer = (
230219
}
231220
});
232221
if (maxHeight) {
233-
heightResizes.push([rowIndex, maxHeight]);
222+
rowStore.$update(ACTION_ITEM_RESIZE, [rowIndex, maxHeight]);
234223
}
235224
});
236-
rowStore.$update(ACTION_ITEM_RESIZE, heightResizes);
237225
}
238226
if (resizedCols.size) {
239-
const widthResizes: ItemResize[] = [];
240227
resizedCols.forEach((colIndex) => {
241228
let maxWidth = 0;
242229
maybeCachedRowIndexes.forEach((rowIndex) => {
@@ -246,10 +233,9 @@ export const createGridResizer = (
246233
}
247234
});
248235
if (maxWidth) {
249-
widthResizes.push([colIndex, maxWidth]);
236+
colStore.$update(ACTION_ITEM_RESIZE, [colIndex, maxWidth]);
250237
}
251238
});
252-
colStore.$update(ACTION_ITEM_RESIZE, widthResizes);
253239
}
254240
});
255241

@@ -268,20 +254,20 @@ export const createGridResizer = (
268254
};
269255
},
270256
$resizeCols(cols: ItemResize[]) {
271-
for (const [c] of cols) {
257+
for (const col of cols) {
272258
for (let r = 0; r < rowStore.$getItemsLength(); r++) {
273-
sizeCache.delete(getKey(r, c));
259+
sizeCache.delete(getKey(r, col[0]));
274260
}
261+
colStore.$update(ACTION_ITEM_RESIZE, col);
275262
}
276-
colStore.$update(ACTION_ITEM_RESIZE, cols);
277263
},
278264
$resizeRows(rows: ItemResize[]) {
279-
for (const [r] of rows) {
265+
for (const row of rows) {
280266
for (let c = 0; c < colStore.$getItemsLength(); c++) {
281-
sizeCache.delete(getKey(r, c));
267+
sizeCache.delete(getKey(row[0], c));
282268
}
269+
rowStore.$update(ACTION_ITEM_RESIZE, row);
283270
}
284-
rowStore.$update(ACTION_ITEM_RESIZE, rows);
285271
},
286272
$dispose: resizeObserver._dispose,
287273
};

0 commit comments

Comments
 (0)