src/model/list-selection.ts
Properties |
Methods |
isSelected | ||||||||
isSelected(item: any)
|
||||||||
Defined in src/model/list-selection.ts:12
|
||||||||
Parameters :
Returns :
boolean
|
select | ||||||||
select(item: any)
|
||||||||
Defined in src/model/list-selection.ts:6
|
||||||||
Parameters :
Returns :
void
|
selectAll |
selectAll()
|
Defined in src/model/list-selection.ts:8
|
Returns :
void
|
unselect | ||||||||
unselect(item: any)
|
||||||||
Defined in src/model/list-selection.ts:10
|
||||||||
Parameters :
Returns :
void
|
selectedItems |
selectedItems:
|
Type : any[]
|
Defined in src/model/list-selection.ts:2
|
totalItems |
totalItems:
|
Type : any[]
|
Defined in src/model/list-selection.ts:4
|
export interface ListSelection {
selectedItems: any[];
totalItems: any[];
select(item: any): void;
selectAll(): void;
unselect(item: any): void;
isSelected(item: any): boolean;
}
export class ListSelectionImpl implements ListSelection {
private _selectedItems: any[] = [];
constructor(public readonly totalItems: any[]) {}
select(item: any): void {
if (!this.isSelected(item)) {
this._selectedItems.push(item);
}
}
selectAll(): void {
this._selectedItems = this.totalItems;
}
unselect(item: any): void {
if (!this.isSelected(item)) {
throw new Error(`Cannot unselect an item that is not selected`);
}
this._selectedItems = this._selectedItems.filter(e => e !== item);
}
isSelected(item: any): boolean {
return !!this._selectedItems.find(e => e === item);
}
get selectedItems(): any[] {
return this._selectedItems;
}
}