ngx-store
Version:
Angular decorators to automagically keep variables in HTML5 LocalStorage, SessionStorage, cookies; injectable services for managing and listening to data changes and a bit more.
94 lines (93 loc) • 2.45 kB
TypeScript
import { WebStorageService } from './webstorage.service';
export declare class Resource<T> {
protected service: WebStorageService;
protected readonly key: string;
constructor(service: WebStorageService, key: string);
protected _defaultValue: any;
/**
* Returns default value
* @returns {T}
*/
get defaultValue(): T;
protected _path: Array<string>;
/**
* Returns current path as a string
* @returns {string}
*/
get path(): string;
protected _prefix: string;
/**
* Returns currently set prefix
* @returns {string}
*/
get prefix(): string;
/**
* Returns value taking path into account
* @returns {T}
*/
get value(): T;
protected get fullValue(): T;
protected get pathString(): string;
/**
* Sets path of object property
* @param {string} path
* @returns {this}
*/
setPath(path: string): this;
/**
* Appends current path
* e.g. if path('key') and appendPath('nested'), the path will be "key.nested"
* @param {string} path
* @returns {this}
*/
appendPath(path: string): this;
/**
* Removes last item of path
* e.g. if path('key.nested') and truncatePath(), the path will be "key"
* @returns {this}
*/
truncatePath(): this;
/**
* Resets set path
* @returns {this}
*/
resetPath(): this;
/**
* Sets prefix
* @param {string} prefix
* @returns {this}
*/
setPrefix(prefix: string): this;
/**
* Moves storage item to new key using given prefix
* @param {string} prefix
* @returns {this}
*/
changePrefix(prefix: string): this;
/**
* Sets default value for both reading and saving operations
* @param defaultValue
* @returns {this}
*/
setDefaultValue(defaultValue: T): this;
/**
* Creates or overrides value as a new entry or existing object property depending on path
* @param value
* @returns {this}
*/
save(value: T): this;
/**
* Updates existing object property using current path
* @param {T} value
* @returns {this}
*/
update(value: T): this;
/**
* Removes item stored under current key
* @returns {this}
*/
remove(): this;
protected considerDefault<S>(value: S): S;
protected isNullOrUndefined(value: any): boolean;
protected readValue(): T;
}