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

PaginatedResourceWrapper

this class was deprecated.

Used for wrapping PaginatedResourceListing to make it spa friendly

TODO:

  • Allow for manual cache updates, ex: a resource has been modified, deleted, created

Constructor Summary

Public Constructor
public

constructor(listing: PaginatedResourceListing, api: Maps4News, shareCache: Boolean)

Member Summary

Public Members
public get

Get api instance

public get

Get the active cache instance

public get

Returns the page number that is currently being used as a reference point

public set

Set the current page number

public

Available data assembled from the cache

public get

If there is a next page

public get

If there is a previous page

public get

List of page numbers that are still mid-flight

public get

Get the number of pages available

public get

Get the route of the resource

public set

route(value: String)

Override the resource route

public get

rows: Number: *

Row count

public get

Get if the shared cache should be used

public set

Sets if the shared cache should be used

public get

Returns if there are still requests mid-flight

Method Summary

Public Methods
public

get(pageId: Number | Array<Number>)

Manually fetch a page.

public

next()

Grab the next page

public

off(type: string, handler: function(event: any): void)

Function to call in response to the given event

public

on(type: string, handler: function(eventType: string, event: any): void | function(event: any): void)

Register an event handler for the given type.

public

Grab the previous page

public

Set the request params and submit

public

Manually rebuild the data

public

refresh(flush: Boolean)

Updates the cached pages.

Public Constructors

public constructor(listing: PaginatedResourceListing, api: Maps4News, shareCache: Boolean) source

Params:

NameTypeAttributeDescription
listing PaginatedResourceListing

Listing result

api Maps4News

Instance of the api

shareCache Boolean

Share cache across instances

Public Members

public get api: Maps4News: * source

Get api instance

Return:

Maps4News

Api instance

public get cache: ResourceCache: * source

Get the active cache instance

Return:

ResourceCache

Cache instance

public get currentPage: Number: * source

Returns the page number that is currently being used as a reference point

Return:

Number

The current page

See:

public set currentPage(value: Number) source

Set the current page number

public data: Array<ResourceBase> source

Available data assembled from the cache

public get hasNext: boolean: * source

If there is a next page

Return:

boolean

If there is a next page

public get hasPrevious: boolean: * source

If there is a previous page

Return:

boolean

If there is a previous page

public get inflight: Array: * source

List of page numbers that are still mid-flight

Return:

Array

Page numbers that are still mid-flight

public get pageCount: Number: * source

Get the number of pages available

Return:

Number

Page count

public get route: String: * source

Get the route of the resource

Return:

String

route

public set route(value: String) source

Override the resource route

public get rows: Number: * source

Row count

Return:

Number

Row count

public get shareCache: Boolean: * source

Get if the shared cache should be used

Return:

Boolean

Should the shared cache be used

public set shareCache(value: Boolean) source

Sets if the shared cache should be used

public get waiting: boolean: * source

Returns if there are still requests mid-flight

Return:

boolean

Returns if the wrapper is waiting for requests to finish

Public Methods

public get(pageId: Number | Array<Number>) source

Manually fetch a page. This will change the current page.

Params:

NameTypeAttributeDescription
pageId Number | Array<Number>

Page(s) to fetch

public next() source

Grab the next page

public off(type: string, handler: function(event: any): void) source

Function to call in response to the given event

Params:

NameTypeAttributeDescription
type string

Type of event to unregister handler from, or "*"

handler function(event: any): void

Handler function to remove.

public on(type: string, handler: function(eventType: string, event: any): void | function(event: any): void) source

Register an event handler for the given type.

Params:

NameTypeAttributeDescription
type string

Type of event to listen for, or "*" for all events.

handler function(eventType: string, event: any): void | function(event: any): void

Function to call in response to the given event.

public previous() source

Grab the previous page

public query(value: Object<String, *>): Object<String, String|Array<String>> source

Set the request params and submit

Params:

NameTypeAttributeDescription
value Object<String, *>
  • nullable: true

Query

Return:

Object<String, String|Array<String>>

query

Throw:

TypeError

See:

  • ResourceProxy#search

public rebuild() source

Manually rebuild the data

public refresh(flush: Boolean) source

Updates the cached pages.

Params:

NameTypeAttributeDescription
flush Boolean

Clear the cached route data

Example:

function onRefresh() {
  if(wrapper.waiting) {
    return; // not done yet
  }

  wrapper.off('post-rebuild', onRefresh);

  // Do stuff here
}

wrapper.on('post-rebuild', onRefresh);
wrapper.refresh();