Skip to content

Commit 69e3feb

Browse files
committed
revert id caching
1 parent 692a2e6 commit 69e3feb

File tree

1 file changed

+5
-18
lines changed
  • frontend/src/components/ui/data-grid/controllers

1 file changed

+5
-18
lines changed

frontend/src/components/ui/data-grid/controllers/rows.ts

+5-18
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import type { EmptyObject } from "type-fest";
55
import type { DataGrid } from "../data-grid";
66
import type { GridItem, GridRowId, GridRows } from "../types";
77

8+
import { cached } from "@/utils/weakCache";
9+
810
/**
911
* Enables removing and adding rows from a grid.
1012
*
@@ -23,8 +25,6 @@ export class DataGridRowsController implements ReactiveController {
2325
addRows?: DataGrid["addRows"];
2426
};
2527

26-
readonly #rowIds = new Map<GridItem, GridRowId>();
27-
2828
#prevItems?: GridItem[];
2929

3030
public rows: GridRows = new Map<GridRowId, GridItem>();
@@ -55,25 +55,12 @@ export class DataGridRowsController implements ReactiveController {
5555
item[rowKey as unknown as string] as GridRowId,
5656
item,
5757
])
58-
: items.map((item) => [this.getCachedId(item), item]),
58+
: items.map(
59+
cached((item) => [nanoid(), item], { cacheConstructor: Map }),
60+
),
5961
);
6062
}
6163

62-
/**
63-
* Use item reference to get a persistent generated ID.
64-
*/
65-
private getCachedId(item: GridItem): GridRowId {
66-
const id = this.#rowIds.get(item);
67-
68-
if (id) return id;
69-
70-
const newId = nanoid();
71-
72-
this.#rowIds.set(item, newId);
73-
74-
return newId;
75-
}
76-
7764
public setItems(items: GridItem[]) {
7865
if (!this.#prevItems || items !== this.#prevItems) {
7966
this.setRowsFromItems(items);

0 commit comments

Comments
 (0)