import PaginatedResourceWrapper from '@mapcreator/maps4news/src/PaginatedResourceWrapper.js'
PaginatedResourceWrapper
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 |
cache: ResourceCache: * Get the active cache instance |
|
public get |
currentPage: Number: * Returns the page number that is currently being used as a reference point |
|
public set |
currentPage(value: Number) Set the current page number |
|
public |
Available data assembled from the cache |
|
public get |
If there is a next page |
|
public get |
hasPrevious: boolean: * 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 |
Override the resource route |
|
public get |
Row count |
|
public get |
shareCache: Boolean: * Get if the shared cache should be used |
|
public set |
shareCache(value: Boolean) Sets if the shared cache should be used |
|
public get |
Returns if there are still requests mid-flight |
Method Summary
Public Methods | ||
public |
Manually fetch a page. |
|
public |
next() Grab the next page |
|
public |
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 |
previous() Grab the previous page |
|
public |
Set the request params and submit |
|
public |
rebuild() Manually rebuild the data |
|
public |
Updates the cached pages. |
Public Constructors
public constructor(listing: PaginatedResourceListing, api: Maps4News, shareCache: Boolean) source
Params:
Name | Type | Attribute | Description |
listing | PaginatedResourceListing | Listing result |
|
api | Maps4News | Instance of the api |
|
shareCache | Boolean | Share cache across instances |
Public Members
public get currentPage: Number: * source
Returns the page number that is currently being used as a reference point
Public Methods
public get(pageId: Number | Array<Number>) source
Manually fetch a page. This will change the current page.
public off(type: string, handler: function(event: any): void) source
Function to call in response to the given event
public on(type: string, handler: function(eventType: string, event: any): void | function(event: any): void) source
Register an event handler for the given type.
public query(value: Object<String, *>): Object<String, String|Array<String>> source
Set the request params and submit
Throw:
See:
- ResourceProxy#search
public refresh(flush: Boolean) source
Updates the cached pages.
Params:
Name | Type | Attribute | Description |
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();