diff --git a/helpers/api/pagination.js b/helpers/api/pagination.js index e870e78..05e1d36 100644 --- a/helpers/api/pagination.js +++ b/helpers/api/pagination.js @@ -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 { } +