From 2dbf9e3d263f592b80214c66df9b113ecde38f15 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Thu, 19 May 2022 13:48:15 -0500 Subject: [PATCH] Support list as a function --- helpers/api/pagination.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 { } +