angular-persistence
Version:
A library to handle persistence for Angular 2 applications.
90 lines • 2.11 kB
JavaScript
/**
* A storage type which stored values in memory. They are assumed to be mutable, but
* any object will work in this storage type.
*
* @export
* \@class MemoryStorage
*
* @author Scott O'Bryan
* \@since 1.0
*/
export var MemoryStorage = (function () {
function MemoryStorage() {
this._data = {};
}
/**
* Always returns true
*
* @return {?}
*/
MemoryStorage.prototype.available = function () {
return true;
};
/**
* Sets a value in this object for the specified key
*
* @param {?} key
* @param {?} value
* @return {?}
*/
MemoryStorage.prototype.set = function (key, value) {
if (value === undefined) {
delete this._data[key];
}
else {
this._data[key] = value;
}
return true;
};
/**
* Returns the value of the specified key
*
* @param {?} key
* @return {?}
*/
MemoryStorage.prototype.get = function (key) {
return this._data[key];
};
/**
* Returns false if the value for the key is undefined.
*
* @param {?} key
* @return {?}
*/
MemoryStorage.prototype.exists = function (key) {
return this._data[key] !== undefined;
};
/**
* Removes a value from this object
*
* @param {?} key
* @return {?}
*/
MemoryStorage.prototype.remove = function (key) {
delete this._data[key];
};
/**
* Removes all values in this storage type.
*
* @return {?}
*/
MemoryStorage.prototype.removeAll = function () {
var /** @type {?} */ keys = Object.keys(this._data);
this._data = {};
return keys;
};
/**
* Returns a list of all keys that are stored
*
* @return {?}
*/
MemoryStorage.prototype.keys = function () {
return Object.keys(this._data);
};
return MemoryStorage;
}());
function MemoryStorage_tsickle_Closure_declarations() {
/** @type {?} */
MemoryStorage.prototype._data;
}
//# sourceMappingURL=storage.memory.js.map