diff --git a/src/lib/sorting/sort-by.pipe.ts b/src/lib/sorting/sort-by.pipe.ts index d198efd..5462d9a 100644 --- a/src/lib/sorting/sort-by.pipe.ts +++ b/src/lib/sorting/sort-by.pipe.ts @@ -4,10 +4,8 @@ import { SortingOrder } from './models/sorting-order.type'; import { KeysOf } from '../utils/types/utility-types'; @Pipe({ name: 'sortBy' }) -export class SortByPipe implements PipeTransform { - constructor(private readonly _sortingService: SortingService) {} - - transform(value: T[], order: SortingOrder, column: KeysOf): T[] { - return this._sortingService.sort(value, order, column); +export class SortByPipe implements PipeTransform { + transform(values: T[], order: SortingOrder, column: KeysOf): T[] { + return SortingService.sort(values, order, column); } } diff --git a/src/lib/sorting/sorting.service.ts b/src/lib/sorting/sorting.service.ts index 2ac25fb..3ca9cfe 100644 --- a/src/lib/sorting/sorting.service.ts +++ b/src/lib/sorting/sorting.service.ts @@ -5,9 +5,7 @@ import { SortingOption } from './models/sorting-option.model'; import { SortingOrder, SortingOrders } from './models/sorting-order.type'; import { KeysOf } from '../utils/types/utility-types'; -@Injectable({ - providedIn: 'root' -}) +@Injectable() export class SortingService { private readonly _sortingOption$ = new BehaviorSubject | undefined>(undefined); readonly sortingOption$ = this._sortingOption$.asObservable(); @@ -16,11 +14,7 @@ export class SortingService { return this._sortingOption$.getValue(); } - setSortingOption(value: SortingOption): void { - this._sortingOption$.next(value); - } - - sort(values: T[], order?: SortingOrder, column?: KeysOf): T[] { + static sort(values: T[], order?: SortingOrder, column?: KeysOf): T[] { if (!values || values.length <= 1 || !order) return values; if (!column) { @@ -32,8 +26,12 @@ export class SortingService { return orderBy(values, [column], [order]); } + setSortingOption(value: SortingOption): void { + this._sortingOption$.next(value); + } + defaultSort(values: T[]): T[] { - return this.sort(values, this.sortingOption?.order, this.sortingOption?.column); + return SortingService.sort(values, this.sortingOption?.order, this.sortingOption?.column); } toggleSort(column: KeysOf): void {