mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Catch non-arrays
This commit is contained in:
parent
49581738bb
commit
ad2892772d
1 changed files with 11 additions and 0 deletions
|
|
@ -3,6 +3,12 @@ export const defaultPerPage = 20
|
||||||
|
|
||||||
export class PaginatedList {
|
export class PaginatedList {
|
||||||
constructor({ list, perPage = defaultPerPage }) {
|
constructor({ list, perPage = defaultPerPage }) {
|
||||||
|
|
||||||
|
// Catch errors if the list is not an array or a function
|
||||||
|
if ( !Array.isArray( list ) && typeof list !== 'function' ) {
|
||||||
|
throw new Error(`List must be an array or a function but is ${typeof list}`)
|
||||||
|
}
|
||||||
|
|
||||||
this.listArg = list
|
this.listArg = list
|
||||||
this.perPage = perPage
|
this.perPage = perPage
|
||||||
}
|
}
|
||||||
|
|
@ -17,6 +23,11 @@ export class PaginatedList {
|
||||||
}
|
}
|
||||||
|
|
||||||
get total () {
|
get total () {
|
||||||
|
// Catch errors if the list is not an array or a function
|
||||||
|
if ( !Array.isArray( this.list ) ) {
|
||||||
|
throw new Error(`List must be an array or a function but is ${typeof list}`)
|
||||||
|
}
|
||||||
|
|
||||||
return this.list.length
|
return this.list.length
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue