Home Manual Reference Source
import ResourceLister from '@mapcreator/maps4news/src/ResourceLister.js'
public class | source

ResourceLister

Extends:

events~EventEmitter → ResourceLister

Paginated resource lister

Constructor Summary

Public Constructor
public

constructor(api: Maps4News, route: string, Resource: constructor<ResourceBase>, parameters: RequestParameters, maxRows: number, key: string)

ResourceLister constructor

Member Summary

Public Members
public get

Resource constructor accessor, used for building the resource instance

public get

Get the api instance

public set

Set if ResourceLister#update should be called when ResourceLister#parameters is updated

public get

Get if ResourceLister#update should be called when ResourceLister#parameters is updated

public get

Get the number of rows the server has available

public get

Get the data

public get

Get if there are more resources to fetch.

public get

Get the maximum amount of rows allowed

public set

maxRows(value: number)

Set the maximum amount of rows allowed

public get

Get the request parameters

public set

Set the request parameters

public get

Get the route (url)

public get

Get the row count

public get

Get if the instance is waiting for data

Method Summary

Public Methods
public

[Symbol.iterator](): Iterator

Returns the iterable

public

loadMore(rows: number)

Same as this.maxRows += this.parameters.perPage

public

push(row: Resource, autoMaxRows: boolean)

Push a row to the data collection

public

async update()

Update the server data

Public Constructors

public constructor(api: Maps4News, route: string, Resource: constructor<ResourceBase>, parameters: RequestParameters, maxRows: number, key: string) source

ResourceLister constructor

Params:

NameTypeAttributeDescription
api Maps4News

Api instance

route string

Resource url route

Resource constructor<ResourceBase>

Resource constructor

parameters RequestParameters
  • nullable: true

Request parameters

maxRows number
  • optional
  • default: 50

Initial max rows

key string
  • optional
  • default: id

Key

Public Members

public get Resource: constructor<ResourceBase>: * source

Resource constructor accessor, used for building the resource instance

Return:

constructor<ResourceBase>

resource constructor

public get api: Maps4News: * source

Get the api instance

Return:

Maps4News

api instance

public set autoUpdate(value: boolean) source

Set if ResourceLister#update should be called when ResourceLister#parameters is updated

Throw:

update

parameters

public get autoUpdate: * source

Get if ResourceLister#update should be called when ResourceLister#parameters is updated

Throw:

update

parameters

public get availableRows: number: * source

Get the number of rows the server has available

Return:

number

number of rows

public get data: Array<Resource>: * source

Get the data

Return:

Array<Resource>

data

public get hasMore: boolean: * source

Get if there are more resources to fetch. It indicates if the maxRows can be increased.

Return:

boolean

if more rows are available

public get maxRows: number: * source

Get the maximum amount of rows allowed

Return:

number

max rows

public set maxRows(value: number) source

Set the maximum amount of rows allowed

public get parameters: RequestParameters: * source

Get the request parameters

Return:

RequestParameters

parameters

public set parameters(object: RequestParameters) source

Set the request parameters

If you set ResourceLister#autoUpdate to true then ResourceLister#update will automatically be called when the parameters are updated.

Throw:

autoUpdate

public get route: string: * source

Get the route (url)

Return:

string

route

public get rowCount: number: * source

Get the row count

Return:

number

row count

See:

public get waiting: boolean: * source

Get if the instance is waiting for data

Return:

boolean

waiting for data

Public Methods

public [Symbol.iterator](): Iterator source

Returns the iterable

Return:

Iterator

iterator

public loadMore(rows: number) source

Same as this.maxRows += this.parameters.perPage

Params:

NameTypeAttributeDescription
rows number
  • optional
  • default: parameters.perPage

Amount to increment maxRows with

public push(row: Resource, autoMaxRows: boolean) source

Push a row to the data collection

This will append the row or update an existing row based on the key. If autoMaxRows is set to true and maxRows only needs to be increased by one for the new resource to show up it will

Params:

NameTypeAttributeDescription
row Resource

resource

autoMaxRows boolean

Increase maxRows if needed

public async update() source

Update the server data