Removed the use of any and enabled the rule in eslint.
Now according to me the conversion is final. Testing is required.
This commit is contained in:
@ -5,19 +5,27 @@ import { MatSort, Sort } from '@angular/material/sort';
|
||||
import { merge, Observable, of as observableOf } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { BalanceSheetItem } from './balance-sheet-item';
|
||||
|
||||
/** Simple sort comparator for example ID/Name columns (for client-side sorting). */
|
||||
function compare(a: string | number, b: string | number, isAsc: boolean) {
|
||||
return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
|
||||
}
|
||||
export class BalanceSheetDataSource extends DataSource<any> {
|
||||
constructor(public data: any[], private paginator?: MatPaginator, private sort?: MatSort) {
|
||||
export class BalanceSheetDataSource extends DataSource<BalanceSheetItem> {
|
||||
constructor(
|
||||
public data: BalanceSheetItem[],
|
||||
private paginator?: MatPaginator,
|
||||
private sort?: MatSort,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<any[]> {
|
||||
const dataMutations: (Observable<any[]> | EventEmitter<PageEvent> | EventEmitter<Sort>)[] = [
|
||||
observableOf(this.data),
|
||||
];
|
||||
connect(): Observable<BalanceSheetItem[]> {
|
||||
const dataMutations: (
|
||||
| Observable<BalanceSheetItem[]>
|
||||
| EventEmitter<PageEvent>
|
||||
| EventEmitter<Sort>
|
||||
)[] = [observableOf(this.data)];
|
||||
if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page);
|
||||
if (this.sort) dataMutations.push((this.sort as MatSort).sortChange);
|
||||
|
||||
@ -31,13 +39,13 @@ export class BalanceSheetDataSource extends DataSource<any> {
|
||||
|
||||
disconnect() {}
|
||||
|
||||
private getPagedData(data: any[]) {
|
||||
private getPagedData(data: BalanceSheetItem[]) {
|
||||
if (this.paginator === undefined) return data;
|
||||
const startIndex = this.paginator.pageIndex * this.paginator.pageSize;
|
||||
return data.splice(startIndex, this.paginator.pageSize);
|
||||
}
|
||||
|
||||
private getSortedData(data: any[]) {
|
||||
private getSortedData(data: BalanceSheetItem[]) {
|
||||
if (this.sort === undefined) return data;
|
||||
if (!this.sort.active || this.sort.direction === '') {
|
||||
return data;
|
||||
@ -48,9 +56,8 @@ export class BalanceSheetDataSource extends DataSource<any> {
|
||||
const isAsc = sort.direction === 'asc';
|
||||
switch (sort.active) {
|
||||
case 'name':
|
||||
if (a.name === undefined || b.name === undefined) return 0;
|
||||
return compare(a.name, b.name, isAsc);
|
||||
case 'id':
|
||||
return compare(+a.id, +b.id, isAsc);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -8,12 +8,14 @@ describe('BalanceSheetComponent', () => {
|
||||
let component: BalanceSheetComponent;
|
||||
let fixture: ComponentFixture<BalanceSheetComponent>;
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [ReactiveFormsModule, RouterTestingModule],
|
||||
declarations: [BalanceSheetComponent],
|
||||
}).compileComponents();
|
||||
}));
|
||||
beforeEach(
|
||||
waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [ReactiveFormsModule, RouterTestingModule],
|
||||
declarations: [BalanceSheetComponent],
|
||||
}).compileComponents();
|
||||
}),
|
||||
);
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(BalanceSheetComponent);
|
||||
|
||||
Reference in New Issue
Block a user