Skip to content

Commit 5e5c655

Browse files
committed
refactor: change getter to method
1 parent c538181 commit 5e5c655

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

packages/shared/widget-plugin-grid/src/select-all/SelectAllController.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class SelectAllController implements ReactiveController {
1919
private readonly query: QueryController;
2020
private abortController?: AbortController;
2121
private locked = false;
22-
readonly pageSize: number = 100;
22+
readonly pageSize: number = 500;
2323
private readonly emitter = new EventTarget();
2424

2525
constructor(host: ReactiveControllerHost, spec: SelectAllControllerSpec) {
@@ -30,7 +30,6 @@ export class SelectAllController implements ReactiveController {
3030
type PrivateMembers = "setIsLocked" | "locked";
3131
makeObservable<this, PrivateMembers>(this, {
3232
setIsLocked: action,
33-
selection: computed,
3433
canExecute: computed,
3534
isExecuting: computed,
3635
locked: observable,
@@ -52,13 +51,18 @@ export class SelectAllController implements ReactiveController {
5251
this.emitter.removeEventListener(type, listener);
5352
}
5453

55-
get selection(): SelectionMultiValue | undefined {
54+
/**
55+
* @throws if selection is undefined or single
56+
*/
57+
selection(): SelectionMultiValue {
5658
const selection = this.gate.props.itemSelection;
57-
return selection?.type === "Multi" ? selection : undefined;
59+
if (selection === undefined) throw new Error("SelectAllController: selection is undefined.");
60+
if (selection.type === "Single") throw new Error("SelectAllController: single selection is not supported.");
61+
return selection;
5862
}
5963

6064
get canExecute(): boolean {
61-
return this.selection?.type === "Multi" && !this.locked;
65+
return this.gate.props.itemSelection?.type === "Multi" && !this.locked;
6266
}
6367

6468
get isExecuting(): boolean {
@@ -96,7 +100,7 @@ export class SelectAllController implements ReactiveController {
96100
this.setIsLocked(true);
97101

98102
const { offset: initOffset, limit: initLimit } = this.query;
99-
const initSelection = this.selection?.selection;
103+
const initSelection = this.selection().selection;
100104
const hasTotal = typeof this.query.totalCount === "number";
101105
const totalCount = this.query.totalCount ?? 0;
102106
let loaded = 0;
@@ -125,13 +129,13 @@ export class SelectAllController implements ReactiveController {
125129
loading = !signal.aborted && this.query.hasMoreItems;
126130
}
127131
// Set allItems on success
128-
this.selection?.setSelection(allItems);
132+
this.selection().setSelection(allItems);
129133
} catch (error) {
130134
if (!signal.aborted) {
131135
throw error;
132136
}
133137
// Restore selection on abort
134-
this.selection?.setSelection(initSelection ?? []);
138+
this.selection().setSelection(initSelection);
135139
} finally {
136140
this.query.setOffset(initOffset);
137141
this.query.setLimit(initLimit);
@@ -146,7 +150,7 @@ export class SelectAllController implements ReactiveController {
146150
console.debug("SelectAllController: can't clear selection while executing.");
147151
return;
148152
}
149-
this.selection?.setSelection([]);
153+
this.selection().setSelection([]);
150154
}
151155

152156
abort(): void {

0 commit comments

Comments
 (0)