make sorting method static, remove sorting service injector
This commit is contained in:
parent
be233975d6
commit
7bd24c4352
@ -4,10 +4,8 @@ import { SortingOrder } from './models/sorting-order.type';
|
||||
import { KeysOf } from '../utils/types/utility-types';
|
||||
|
||||
@Pipe({ name: 'sortBy' })
|
||||
export class SortByPipe<T extends object> implements PipeTransform {
|
||||
constructor(private readonly _sortingService: SortingService<T>) {}
|
||||
|
||||
transform(value: T[], order: SortingOrder, column: KeysOf<T>): T[] {
|
||||
return this._sortingService.sort(value, order, column);
|
||||
export class SortByPipe implements PipeTransform {
|
||||
transform<T extends object>(values: T[], order: SortingOrder, column: KeysOf<T>): T[] {
|
||||
return SortingService.sort(values, order, column);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<T extends object> {
|
||||
private readonly _sortingOption$ = new BehaviorSubject<SortingOption<T> | undefined>(undefined);
|
||||
readonly sortingOption$ = this._sortingOption$.asObservable();
|
||||
@ -16,11 +14,7 @@ export class SortingService<T extends object> {
|
||||
return this._sortingOption$.getValue();
|
||||
}
|
||||
|
||||
setSortingOption(value: SortingOption<T>): void {
|
||||
this._sortingOption$.next(value);
|
||||
}
|
||||
|
||||
sort(values: T[], order?: SortingOrder, column?: KeysOf<T>): T[] {
|
||||
static sort<T extends object>(values: T[], order?: SortingOrder, column?: KeysOf<T>): T[] {
|
||||
if (!values || values.length <= 1 || !order) return values;
|
||||
|
||||
if (!column) {
|
||||
@ -32,8 +26,12 @@ export class SortingService<T extends object> {
|
||||
return orderBy(values, [column], [order]);
|
||||
}
|
||||
|
||||
setSortingOption(value: SortingOption<T>): 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<T>): void {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user