vue-service-model
Version:
Vue.js library for handling REST service requests with caching, aggregation and model definitions
65 lines (64 loc) • 2.02 kB
TypeScript
import Dictionary from '../types/Dictionary';
import { ServiceStoreStateData, ServiceStoreOptions } from '../types/store/ServiceStore';
export declare class ServiceStore {
/**
* Dictionary of cached data structure by options.key
*/
protected _data: Dictionary<ServiceStoreStateData>;
/**
* Dictionary of started requests by options.key
*/
protected _requests: Dictionary<Promise<any>>;
/**
* Default cache duration in seconds.
* 0: no cache
* null: Cache does not expire
*/
protected cacheDuration: number | null;
constructor(cacheDuration: number | null);
/**
* Get data of options.key either from cache or by calling options.sendRequest
* @param options
*/
getData(options: ServiceStoreOptions): Promise<any>;
/**
* Loads data by calling options.sendRequest. If request of same key has already started return attach to this request
* @param options
*/
loadData(options: ServiceStoreOptions): Promise<any>;
/**
* Save data in cache if required
* @param key
* @param data
*/
protected _setData(key: string, data: Dictionary<any>): void;
/**
* Save started request promise
* @param key
* @param request
*/
protected _setRequest(key: string, request: Promise<any>): void;
/**
* Check whether data should be retrieved from cache or not
* @param options
*/
protected useCache(options: ServiceStoreOptions): boolean;
/**
* Check whether request is already in queue and return request promise if so
* @param options
*/
protected getRequestAggregation(options: ServiceStoreOptions): Promise<any> | null;
/**
* Remove request promise
* @param key
*/
removeRequest(key: string): void;
/**
* Clean up data and remove expired cache
*/
clean(): void;
/**
* clear complete cache
*/
clear(): void;
}