Support list as a function

This commit is contained in:
Sam Carlton 2022-05-19 13:48:15 -05:00
parent 6e51ff67d8
commit 2dbf9e3d26

View file

@ -1,11 +1,21 @@
export const defaultPerPage = 20
export class PaginatedList {
constructor({ list, perPage = defaultPerPage }) {
this.list = list
this.listArg = list
this.perPage = perPage
}
get list () {
// if our list is a function, call it
if ( typeof this.listArg === 'function' ) {
return this.listArg()
}
return this.listArg
}
get total () {
return this.list.length
}
@ -46,3 +56,4 @@ export class PaginatedList {
}