angular-persistence
Version:
A library to handle persistence for Angular 2 applications.
50 lines • 1.57 kB
JavaScript
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
import { MemoryStorage } from './storage.memory';
/**
* Storage type for immutable memory
*
* @export
* \@class ImmutableMemoryStorage
*
* @author Scott O'Bryan
* \@since 1.0
*/
export var ImmutableMemoryStorage = (function (_super) {
__extends(ImmutableMemoryStorage, _super);
function ImmutableMemoryStorage() {
_super.apply(this, arguments);
}
/**
* Sets a value in memory storage after stringifying the object. This
* add some overhead but ensures each copy of the object is immutable.
*
* @param {?} key
* @param {?} value
* @return {?}
*/
ImmutableMemoryStorage.prototype.set = function (key, value) {
if (value !== undefined) {
value = JSON.stringify(value);
}
return _super.prototype.set.call(this, key, value);
};
/**
* Returns an immutable value for the specified key.
*
* @param {?} key
* @return {?}
*/
ImmutableMemoryStorage.prototype.get = function (key) {
var /** @type {?} */ value = _super.prototype.get.call(this, key);
if (value !== undefined) {
return JSON.parse(value);
}
return undefined;
};
return ImmutableMemoryStorage;
}(MemoryStorage));
//# sourceMappingURL=storage.immutable_memory.js.map