Skip to content

Instantly share code, notes, and snippets.

@tzookb
Created May 9, 2019 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tzookb/ca4a7968953bee888f900ba4c1a93266 to your computer and use it in GitHub Desktop.
Save tzookb/ca4a7968953bee888f900ba4c1a93266 to your computer and use it in GitHub Desktop.
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