Skip to content

Commit f0da72f

Browse files
authored
🐚 Stop updating Grid recursively when collision=compress (#83)
1 parent 65110dd commit f0da72f

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/lib/Grid.svelte

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@
185185
items = items;
186186
187187
if (autoCompress && collision === 'compress') {
188-
controller.compress();
188+
_controller._internalCompress();
189189
}
190190
}
191191
@@ -260,8 +260,10 @@
260260
collision
261261
}));
262262
263-
export const controller = new GridController($gridSettings) as GridControllerType;
264-
$: controller.gridParams = $gridSettings;
263+
const _controller = new GridController($gridSettings);
264+
$: _controller.gridParams = $gridSettings;
265+
266+
export const controller = _controller as GridControllerType;
265267
266268
setContext(GRID_CONTEXT_NAME, gridSettings);
267269
</script>

src/lib/GridController.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ export class GridController implements GridControllerType {
3333
this._compress(this.gridParams.items);
3434
}
3535

36-
private _compress(items: Record<string, LayoutItem>): void {
36+
_internalCompress(): void {
37+
this._compress(this.gridParams.items, true);
38+
}
39+
40+
private _compress(items: Record<string, LayoutItem>, skipUpdate = false): void {
3741
const gridItems = Object.values(items);
3842
const sortedItems = [...gridItems].sort((a, b) => a.y - b.y);
3943

@@ -53,6 +57,8 @@ export class GridController implements GridControllerType {
5357
return accItem;
5458
}, [] as LayoutItem[]);
5559

56-
this.gridParams.updateGrid();
60+
if (!skipUpdate) {
61+
this.gridParams.updateGrid();
62+
}
5763
}
5864
}

0 commit comments

Comments
 (0)