Last active
January 12, 2018 19:06
-
-
Save sanusart/87500709f91ed020ed15d83c1b5cf66a to your computer and use it in GitHub Desktop.
Angular sortBy pipe #tag #angular #angular4 #lodash #fp #pipe #tag1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Pipe, PipeTransform } from '@angular/core'; | |
import { sortBy, reverse, flow, identity } from 'lodash/fp'; | |
@Pipe({ name: 'sortBy' }) | |
export class SortByPipe implements PipeTransform { | |
transform(list, field, direction = 'DESC') { | |
return flow([ | |
sortBy([field]), | |
direction === 'DESC' ? reverse : identity | |
])(list); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment