Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit 6e61079

Browse files
committed
use inject
1 parent 2e620d6 commit 6e61079

File tree

14 files changed

+46
-41
lines changed

14 files changed

+46
-41
lines changed

.eslintrc.json

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
"eol-last": "off",
6565
"no-duplicate-string": "off",
6666
"arrow-body-style": "off",
67-
"id-blacklist": "error",
6867
"import/no-extraneous-dependencies": "off",
6968
"import/no-internal-modules": "off",
7069
"import/order": "off",

projects/ngx-easy-table/src/lib/effects/table.effects.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable } from '@angular/core';
1+
import { Injectable, inject } from '@angular/core';
22
import { Actions, createEffect, ofType } from '@ngrx/effects';
33
import { Store } from '@ngrx/store';
44
import { take, tap } from 'rxjs/operators';
@@ -9,6 +9,10 @@ import { EventService } from '../services/event.service';
99

1010
@Injectable()
1111
export class TableEffects {
12+
private actions$ = inject(Actions);
13+
private store = inject<Store<AppState>>(Store);
14+
private eventService = inject(EventService);
15+
1216
setFilters$ = createEffect(
1317
() =>
1418
this.actions$.pipe(
@@ -34,10 +38,4 @@ export class TableEffects {
3438
),
3539
{ dispatch: false }
3640
);
37-
38-
constructor(
39-
private actions$: Actions,
40-
private store: Store<AppState>,
41-
private eventService: EventService
42-
) {}
4341
}

projects/ngx-easy-table/src/lib/facade/table.facade.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as Actions from '../actions/table.actions';
22
import { Store } from '@ngrx/store';
3-
import { Injectable } from '@angular/core';
3+
import { Injectable, inject } from '@angular/core';
44
import { CellClass, CellStyle, RowClass, RowStyle } from '../model/api';
55
import { Columns } from '../model/columns';
66

77
@Injectable()
88
export class Facade {
9-
constructor(private store: Store) {}
9+
private store = inject(Store);
1010

1111
setPagination(page: number, itemsPerPage: number): void {
1212
this.store.dispatch(

projects/ngx-easy-table/src/lib/services/config-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Injectable } from '@angular/core';
22
import { Config, STYLE, THEME } from '../model/config';
33

4-
// eslint-disable-next-line, no-underscore-dangle, id-blacklist, id-match
4+
// eslint-disable-next-line
55
export const DefaultConfig: Config = {
66
searchEnabled: false,
77
headerEnabled: true,

src/app/app.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit, inject } from '@angular/core';
22
import { environment } from '../environments/environment';
33
import { NavigationEnd, Router } from '@angular/router';
44
import { Subject } from 'rxjs';
@@ -17,7 +17,7 @@ export interface Link {
1717
changeDetection: ChangeDetectionStrategy.OnPush,
1818
})
1919
export class AppComponent implements OnInit, OnDestroy {
20-
constructor(private router: Router) {}
20+
private router = inject(Router);
2121

2222
private ngUnsubscribe: Subject<void> = new Subject<void>();
2323
public readonly version = environment.VERSION;

src/app/demo/infinite-scroll-server-template/infinite-scroll-server-template.component.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Component,
55
OnDestroy,
66
OnInit,
7+
inject,
78
} from '@angular/core';
89
import { Columns, Config, DefaultConfig } from 'ngx-easy-table';
910
import { takeUntil } from 'rxjs/operators';
@@ -18,6 +19,9 @@ import { Subject } from 'rxjs';
1819
changeDetection: ChangeDetectionStrategy.OnPush,
1920
})
2021
export class InfiniteScrollServerTemplateComponent implements OnInit, OnDestroy {
22+
private cdr = inject(ChangeDetectorRef);
23+
private readonly companyService = inject(CompanyService);
24+
2125
public configuration: Config;
2226
public columns: Columns[];
2327
public data: Company[] = [];
@@ -26,8 +30,6 @@ export class InfiniteScrollServerTemplateComponent implements OnInit, OnDestroy
2630
private offset = 1;
2731
public selected: number | null = null;
2832

29-
constructor(private cdr: ChangeDetectorRef, private readonly companyService: CompanyService) {}
30-
3133
ngOnDestroy(): void {
3234
this.ngUnsubscribe.next();
3335
this.ngUnsubscribe.complete();

src/app/demo/infinite-scroll-server/infinite-scroll-server.component.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Component,
55
OnDestroy,
66
OnInit,
7+
inject,
78
} from '@angular/core';
89
import { Columns, Config, DefaultConfig } from 'ngx-easy-table';
910
import { takeUntil } from 'rxjs/operators';
@@ -18,15 +19,16 @@ import { Subject } from 'rxjs';
1819
changeDetection: ChangeDetectionStrategy.OnPush,
1920
})
2021
export class InfiniteScrollServerComponent implements OnInit, OnDestroy {
22+
private cdr = inject(ChangeDetectorRef);
23+
private readonly companyService = inject(CompanyService);
24+
2125
public configuration: Config;
2226
public columns: Columns[];
2327
public data: Company[] = [];
2428
public totalLength = 0;
2529
private ngUnsubscribe: Subject<void> = new Subject<void>();
2630
private offset = 1;
2731

28-
constructor(private cdr: ChangeDetectorRef, private readonly companyService: CompanyService) {}
29-
3032
ngOnDestroy(): void {
3133
this.ngUnsubscribe.next();
3234
this.ngUnsubscribe.complete();

src/app/demo/infinite-scroll/infinite-scroll.component.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core';
1+
import {
2+
ChangeDetectionStrategy,
3+
ChangeDetectorRef,
4+
Component,
5+
OnInit,
6+
inject,
7+
} from '@angular/core';
28
import { Company, data } from '../../../assets/data';
39
import { Columns, Config, DefaultConfig, Event } from 'ngx-easy-table';
410

@@ -9,12 +15,12 @@ import { Columns, Config, DefaultConfig, Event } from 'ngx-easy-table';
915
changeDetection: ChangeDetectionStrategy.OnPush,
1016
})
1117
export class InfiniteScrollComponent implements OnInit {
18+
private cdr = inject(ChangeDetectorRef);
19+
1220
public configuration: Config;
1321
public columns: Columns[];
1422
public data: Company[] = [];
1523

16-
constructor(private cdr: ChangeDetectorRef) {}
17-
1824
ngOnInit(): void {
1925
this.columns = [
2026
{ key: 'phone', title: 'Phone' },

src/app/demo/live-update/live-update.component.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Component,
55
OnDestroy,
66
OnInit,
7+
inject,
78
} from '@angular/core';
89
import { interval, Subject, tap } from 'rxjs';
910
import { takeUntil } from 'rxjs/operators';
@@ -24,6 +25,8 @@ interface Data {
2425
changeDetection: ChangeDetectionStrategy.OnPush,
2526
})
2627
export class LiveUpdateComponent implements OnInit, OnDestroy {
28+
private cdr = inject(ChangeDetectorRef);
29+
2730
data: Data[] = [
2831
{ status: 'ACTIVE', amount: 1, company: 'Foo', limit: 1000, balance: 2000 },
2932
{ status: 'INACTIVE', amount: 2, company: 'Bar', limit: 1000, balance: 900 },
@@ -47,8 +50,6 @@ export class LiveUpdateComponent implements OnInit, OnDestroy {
4750
return Math.floor(min + Math.random() * (max - min + 1));
4851
}
4952

50-
constructor(private cdr: ChangeDetectorRef) {}
51-
5253
ngOnInit(): void {
5354
this.configuration = { ...DefaultConfig };
5455
interval(600)

src/app/demo/persist-state-router/persist-state-router.component.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
OnDestroy,
66
OnInit,
77
ViewChild,
8+
inject,
89
} from '@angular/core';
910
import { Company, data } from '../../../assets/data';
1011
import { API, APIDefinition, Columns, Config, DefaultConfig } from 'ngx-easy-table';
@@ -19,6 +20,8 @@ import { Subject } from 'rxjs';
1920
styles: [],
2021
})
2122
export class PersistStateRouterComponent implements OnInit, OnDestroy, AfterViewInit {
23+
private route = inject(ActivatedRoute);
24+
2225
@ViewChild('table') table: APIDefinition;
2326
private unsubscribe = new Subject<void>();
2427
public columns: Columns[] = [
@@ -33,8 +36,6 @@ export class PersistStateRouterComponent implements OnInit, OnDestroy, AfterView
3336
public sortColumn: string;
3437
public sortOrder: 'asc' | 'desc';
3538

36-
constructor(private route: ActivatedRoute) {}
37-
3839
ngOnInit(): void {
3940
this.configuration = { ...DefaultConfig };
4041
this.data = data;

src/app/demo/server-pagination/server-pagination.component.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
OnDestroy,
66
OnInit,
77
ViewChild,
8+
inject,
89
} from '@angular/core';
910
import { CompanyService } from '../../services/company.service';
1011
import { APIDefinition, Columns, Config, DefaultConfig } from 'ngx-easy-table';
@@ -27,6 +28,9 @@ interface EventObject {
2728
changeDetection: ChangeDetectionStrategy.OnPush,
2829
})
2930
export class ServerPaginationComponent implements OnInit, OnDestroy {
31+
private readonly companyService = inject(CompanyService);
32+
private readonly cdr = inject(ChangeDetectorRef);
33+
3034
@ViewChild('table') table: APIDefinition;
3135
public columns: Columns[] = [
3236
{ key: 'phone', title: 'Phone' },
@@ -44,11 +48,6 @@ export class ServerPaginationComponent implements OnInit, OnDestroy {
4448
};
4549
private ngUnsubscribe: Subject<void> = new Subject<void>();
4650

47-
constructor(
48-
private readonly companyService: CompanyService,
49-
private readonly cdr: ChangeDetectorRef
50-
) {}
51-
5251
ngOnInit(): void {
5352
this.configuration = { ...DefaultConfig };
5453
this.getData('');

src/app/demo/server-sort/server-sort.component.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Component,
55
OnDestroy,
66
OnInit,
7+
inject,
78
} from '@angular/core';
89
import { CompanyService } from '../../services/company.service';
910
import { Columns, Config, DefaultConfig } from 'ngx-easy-table';
@@ -28,6 +29,9 @@ interface EventObject {
2829
changeDetection: ChangeDetectionStrategy.OnPush,
2930
})
3031
export class ServerSortComponent implements OnInit, OnDestroy {
32+
private readonly companyService = inject(CompanyService);
33+
private readonly cdr = inject(ChangeDetectorRef);
34+
3135
public columns: Columns[] = [
3236
{ key: 'phone', title: 'Phone' },
3337
{ key: 'age', title: 'Age' },
@@ -46,11 +50,6 @@ export class ServerSortComponent implements OnInit, OnDestroy {
4650
order: '',
4751
};
4852

49-
constructor(
50-
private readonly companyService: CompanyService,
51-
private readonly cdr: ChangeDetectorRef
52-
) {}
53-
5453
ngOnInit(): void {
5554
this.configuration = { ...DefaultConfig };
5655
this.configuration.serverPagination = true;

src/app/services/company.service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { HttpClient, HttpResponse } from '@angular/common/http';
2-
import { Injectable } from '@angular/core';
2+
import { Injectable, inject } from '@angular/core';
33
import { Observable } from 'rxjs';
44

55
@Injectable()
66
export class CompanyService {
7+
private http = inject(HttpClient);
8+
79
private readonly BACKEND_URL =
810
'https://my-json-server.typicode.com/ssuperczynski/ngx-easy-table/company?';
911

10-
constructor(private http: HttpClient) {}
11-
1212
getCompanies(params = '', observe = true): Observable<HttpResponse<Company[]>> {
1313
return this.http.get<Company[]>(`${this.BACKEND_URL}${params}`, {
1414
observe: observe ? 'response' : null,

src/assets/data.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { Columns } from 'ngx-easy-table';
2-
3-
/* eslint-disable max-lines, id-blacklist */
1+
/* eslint-disable max-lines */
42
export interface Company {
53
phone: string;
64
age: number;
@@ -13,7 +11,7 @@ export interface Company {
1311
imgUrl?: string;
1412
}
1513

16-
export const columns: Columns[] = [
14+
export const columns = [
1715
{ key: 'phone', title: 'Phone' },
1816
{ key: 'age', title: 'Age' },
1917
{ key: 'company', title: 'Company' },

0 commit comments

Comments
 (0)