Skip to content

Commit df7029f

Browse files
committed
refactor: reduce used memory for checks
1 parent 0a8ac40 commit df7029f

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

packages/pluggableWidgets/datagrid-web/src/helpers/state/SelectAllBarViewModel.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,12 @@ export class SelectAllBarViewModel implements ReactiveController {
8585
return str.replace("%d", `${this.#count.selectedCount}`);
8686
}
8787

88-
private get selectedSet(): Set<string> {
89-
const selection = this.#gate.props.itemSelection;
90-
if (!selection) return new Set();
91-
if (selection.type === "Single") return new Set();
92-
return new Set([...selection.selection.map(it => it.id)]);
93-
}
94-
9588
private get isCurrentPageSelected(): boolean {
96-
const items = this.#gate.props.datasource.items ?? [];
97-
if (items.length === 0) return false;
98-
return items.every(items => this.selectedSet.has(items.id));
89+
const selection = this.#gate.props.itemSelection;
90+
if (!selection || selection.type === "Single") return false;
91+
const pageIds = new Set(this.#gate.props.datasource.items?.map(item => item.id) ?? []);
92+
const selectionSubArray = selection.selection.filter(item => pageIds.has(item.id));
93+
return selectionSubArray.length === pageIds.size && pageIds.size > 0;
9994
}
10095

10196
private get isAllItemsSelected(): boolean {

0 commit comments

Comments
 (0)