Created
May 9, 2019 08:56
-
-
Save tzookb/ca4a7968953bee888f900ba4c1a93266 to your computer and use it in GitHub Desktop.
This file contains 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
interface SorterObj { | |
sorts: string[][], | |
addSort(by?: string, how?: string): SorterObj; | |
} | |
const getSorter = function(): SorterObj { | |
const modal: SorterObj = { | |
sorts: [], | |
addSort: function(this: SorterObj, by: string, how?: string): SorterObj { | |
if (by) { | |
if (how) { | |
this.sorts.push([ | |
by, | |
how === 'asc' ? 'ASC' : 'DESC' | |
]) | |
} else { | |
this.sorts.push([by, 'DESC']) | |
} | |
} | |
return this; | |
} | |
}; | |
return modal; | |
} | |
const sorter = getSorter() | |
.addSort('id') | |
.addSort('xx', 'asc') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment